BYU-PRISM / GEKKO

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

Setting integer=True does not seem to work #134

Open jxmorris12 opened 2 years ago

jxmorris12 commented 2 years ago

I'm trying a simple example to test out GEKKO. I'm providing the keyword argument integer=True to initialize an array of variables, yet the solution found doesn't ensure that they're integers. What am I doing wrong?

from gekko import GEKKO
m = GEKKO()

x = m.Array(m.Var, 7, value=0, lb=0, ub=1, integer=True)
m.Equation(sum(x) <= 2)

print(f'Maximizing sum({x})')
m.Maximize(sum(x))

m.solve(disp=False, debug=True)
print(x)
> Maximizing sum([0 0 0 0 0 0 0])
> [[0.28571426403] [0.28571426403] [0.28571426403] [0.28571426403]
 [0.28571426403] [0.28571426403] [0.28571426403]]
jxmorris12 commented 2 years ago

Figured out how to enable mixed-integer optimization by changing the solver- just added the following line:

m.options.SOLVER=1

this wasn't very intuitive. Maybe you could throw an error if someone specifies integer=True but tries to use a solver that doesn't support mixed integer.

APMonitor commented 2 years ago

Great suggestion! I've added it as an upcoming feature request.