I am creating a non-linear program in Python using the Gekko package. The program includes a constraint of the form:
m.Equation(i <= M*q)
where i
is a decision variable, M
is a large constant (larger than the max possible value of 'i'), and q
is a binary decision variable that must be forced to 1 if i
is greater than 0.
The issue is that this constraint doesn't always hold depending on the values of i
and M
. For example, if i
is 100 and M
is set to 10,000, then q
becomes 1.
However, if i
is 100 and M
is set to 100,000, then q
remains 0, therefore violating the constraint.
This is problematic because i
can take on values between 0 and 1,000,000, and I need this constraint to always hold, regardless of the value of i
.
I've tried using 'm.if3()' but that just led to no answer being found.
Adjust the integer tolerance minlp_integer_tol
to fix the problem. The APOPT
solver considers 0.01
an integer value unless the tolerance is changed to a more stringent value such as 1.0e-6
.
m = GEKKO(remote=True,server='https://byu.apmonitor.com')
# multiple options as one list
m.solver_options = ['minlp_gap_tol 1.0e-3',\
'minlp_integer_tol 1.0e-6']
m.options.solver = 1
Also check that the APOPT
solver is selected with m.options.SOLVER=1
. The default is to use the IPOPT
solver that does not enforce integer variables.