BYU-PRISM / GEKKO

GEKKO Python for Machine Learning and Dynamic Optimization
https://machinelearning.byu.edu
Other
595 stars 104 forks source link

New variable bounds not registered #36

Closed loganbeal closed 6 years ago

loganbeal commented 6 years ago

If variable bounds are set/changed after the initial solve, they new bound is not registered. Here's an example with the HS71 problem where the lower bound on x1 is changed from 0.1 to 1:

from gekko import GEKKO
# Initialize Model
m = GEKKO(remote=False)
#initialize variables
x1,x2,x3,x4 = [m.Var() for i in range(4)]
#initial values
x1.value = 1
x2.value = 5
x3.value = 5
x4.value = 1
#lower bounds
x1.lower = .1
x2.lower = 1
x3.lower = 1
x4.lower = 1
#upper bounds
x1.upper = 5
x2.upper = 5
x3.upper = 5
x4.upper = 5
#Equations
m.Equation(x1*x2*x3*x4>=25)
m.Equation(x1**2+x2**2+x3**2+x4**2==40)
#Objective
m.Obj(x1*x4*(x1+x2+x3)+x3)
#Set global options
m.options.IMODE = 3 #steady state optimization
#Solve simulation
m.solve(disp=False) # solve on public server
print(m._variables)

#%% adjust problem and resolve
x1.LOWER = 1
m.solve(disp=False)
print(m._variables)

The output shows that the lower bound of 1 on x1 is not used:

[[0.7545087], [4.639369], [3.788569], [1.885132]]
[[0.7545087], [4.639369], [3.788569], [1.885132]]