4

I'm new to gekko and APM, I'm trying to solve a problem but the solution seems to get infeasible with a new equation in a binary variable that should be viable. Here's the simplified APM model:

Model
Variables
    int_v1 = 0, >= 0
    int_v2 = 0, <= 1, >= 0
    v3 = 0
    v4 = 0
    v5 = 0
    v6 = 0
End Variables
Equations
    (0+int_v1)>=100
    v3=((3.15)*(int_v1))
    v4>=((int_v2)*(300))
    v5=(0+((int_v1)*(3.15)))
    minimize v6
End Equations
Connections
    v3 = sum_1.x[1]
    v4 = sum_1.y
    v5 = sum_2.x[1]
    v6 = sum_2.y
End Connections
Objects
    sum_1 = sum(1)
    sum_2 = sum(1)
End Objects
End Model

Solving this problem in http://apmonitor.com/online/view_pass.php will give a solution in which int_v2 = 1. But if I add the following equation after v4 to the problem, it says solution not found:

(((1-int_v2))*(v4))=0

I looked into the infeasibilities file but cloud not grasp the problem. Since the above solution gives int_v2 = 1 then this equation should be always true with 0 = 0. Appreciate any guidance.

peter_b
  • 21
  • 8

1 Answers1

2

The additional equation adds a stationarity point (e.g. x*y=0) that can be challenging to solve. For your optimization problem, solvers APOPT and IPOPT both incorrectly report that the problem is infeasible. However, the BPOPT solver is able to solve the NLP problem but not necessarily with an integer solution. You posted the APM file from your Gekko problem. Here is your problem in Gekko (without the additional equation):

from gekko import GEKKO

m = GEKKO(remote=False)
v1 = m.Var(0,lb=0,integer=True)
v2 = m.Var(0,lb=0,ub=1,integer=True)
v3 = m.Var(0); v5 = m.Var(0)
v4 = m.sum([v3]); v6 = m.sum([v5])

m.Equation(v1>=100)
m.Equation(v3==3.15*v1)
m.Equation(v4>=v2*300)
m.Equation(v5==v1*3.15)
m.Minimize(v6)

Here are two approaches: 1. Initialize with BPOPT and then switch to APOPT for the integer solution and 2. Solve without the additional equation and then add it and solve again.

  1. Use BPOPT to initialize with NLP, solve MINLP with APOPT
from gekko import GEKKO

m = GEKKO(remote=False)
v1 = m.Var(0,lb=0,integer=True)
v2 = m.Var(0,lb=0,ub=1,integer=True)
v3 = m.Var(0); v5 = m.Var(0)
v4 = m.sum([v3]); v6 = m.sum([v5])

m.Equation(v1>=100)
m.Equation(v3==3.15*v1)
m.Equation(v4>=v2*300)
m.Equation(v5==v1*3.15)
m.Minimize(v6)

m.Equation((1-v2)*v4==0)

m.options.SOLVER=2 # solve with BPOPT
m.solve()

m.options.SOLVER=1 # solve with APOPT
m.solve()
  1. Initialize without equation
from gekko import GEKKO

m = GEKKO(remote=False)
v1 = m.Var(0,lb=0,integer=True)
v2 = m.Var(0,lb=0,ub=1,integer=True)
v3 = m.Var(0); v5 = m.Var(0)
v4 = m.sum([v3]); v6 = m.sum([v5])

m.Equation(v1>=100)
m.Equation(v3==3.15*v1)
m.Equation(v4>=v2*300)
m.Equation(v5==v1*3.15)
m.Minimize(v6)

# solve without equation
m.options.SOLVER=1
m.solve()

# add infeasible equation and solve
m.Equation((1-v2)*v4==0)
m.solve()

You can open the run folder to see that the APM file is similar to the one from your question.

# open folder to view apm file
#   or optionally the infeasibilities.txt file
m.open_folder()
John Hedengren
  • 12,068
  • 1
  • 21
  • 25
  • This is great, thank you for your time to give this complete answer. I'm new to this field would you mind pointing some literature to better undenstand the concepts and this library as well? Thank you very much – peter_b Apr 24 '20 at 14:44
  • 1
    Yes, here is the documentation https://gekko.readthedocs.io/en/latest/ and tutorials https://apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization and a short course https://apmonitor.com/do/index.php/Main/ShortCourse – John Hedengren Apr 24 '20 at 16:45
  • 1
    There are literature sources here: https://apmonitor.com/wiki/index.php/Main/APMonitorReferences – John Hedengren Apr 24 '20 at 16:45