BYU-PRISM / GEKKO

GEKKO Python for Machine Learning and Dynamic Optimization

Home Page:https://machinelearning.byu.edu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MINL yielding solution that does not obey strict inequalities

edumapurunga opened this issue · comments

Problem

I am trying to solve a integer programming problem with nonlinear constraints, more specifically polynomial on the variables.
When I set the model with strict inequalities, the solver yields a solution that does not obey the constraint, i.e. it is not a feasible solution.
I have tested only with integer variables, and strict inequalities.
I first thought that the solver was replacing the strict inequalities for simple inequalities, so I used a tolerance value, but this didn't work either.

Code

from gekko import GEKKO

# Set model
m = GEKKO()
# Set optimizer
m.options.SOLVER=1  # APOPT is an MINLP solver
# Set optimizer options
# optional solver settings with APOPT
m.solver_options = ['minlp_maximum_iterations 500', \
                    # minlp iterations with integer solution
                    'minlp_max_iter_with_int_sol 10', \
                    # treat minlp as nlp
                    'minlp_as_nlp 0', \
                    # nlp sub-problem max iterations
                    'nlp_maximum_iterations 50', \
                    # 1 = depth first, 2 = breadth first
                    'minlp_branch_method 1', \
                    # maximum deviation from whole number
                    'minlp_integer_tol 0.05', \
                    # covergence tolerance
                    'minlp_gap_tol 0.01']

# Set variables
x1 = m.Var(value=1, lb=0, ub=1, integer=True, name='x1')
x2 = m.Var(value=1, lb=0, ub=1, integer=True, name='x2')
# Set a tolerance val for zero
tol = 1e-3
# Constraints
Eq1 = x1 > tol
Eq2 = x2 > tol
# Add constraints to the model
m.Equations([Eq1, Eq2])
# Criterion
Crit = x1 + x2
# Add criterion to the model
m.Obj(Crit)
# Solve
m.solve()
print('Results')
print('x1: ' + str(x1.value))
print('x2: ' + str(x2.value))
print('Objective: ' + str(m.options.objfcnval))

Results

apm 191.177.185.87_gk_model34 <br><pre> ----------------------------------------------------------------
 APMonitor, Version 1.0.1
 APMonitor Optimization Suite
 ----------------------------------------------------------------
 
 
 --------- APM Model Size ------------
 Each time step contains
   Objects      :            0
   Constants    :            0
   Variables    :            4
   Intermediates:            0
   Connections  :            0
   Equations    :            3
   Residuals    :            3
 
 Number of state variables:              4
 Number of total equations: -            2
 Number of slack variables: -            2
 ---------------------------------------
 Degrees of freedom       :              0
 
 ----------------------------------------------
 Steady State Optimization with APOPT Solver
 ----------------------------------------------
Iter:     1 I:  0 Tm:      0.00 NLPi:    2 Dpth:    0 Lvs:    0 Obj:  2.00E-03 Gap:  0.00E+00
 Successful solution
 
 ---------------------------------------------------
 Solver         :  APOPT (v1.0)
 Solution time  :   4.639999999199063E-002 sec
 Objective      :   0.000000000000000E+000
 Successful solution
 ---------------------------------------------------
 
Results
x1: [0.0]
x2: [0.0]
Objective: 0.0

Expected Results

The only solution that would satisfy the bounds and the strict inequalities would be x1 = x2 = 1.

Versions

gekko 1.0.6

Great question! Please ask future questions on Stack Overflow. We typically use GitHub for bug reporting and those issues for feature tracking.

If you need a strict inequality with an integer constraint then use:

Eq1 = x1 >= 1
Eq2 = x2 >= 1

Gekko is a numerical solver so inequality constraints > and >= are equivalent. Also, the APOPT solver has an integer tolerance. This can be changed with:

m.solver_options = ['minlp_integer_tol 1.0e-4']

The default is 1.0e-2 so tol=1.0e-3 is within that limit and 0 or 1e-3 is an acceptable integer solution.

@APMonitor Thanks for the reply!