Gekko infeasible solution with costraint that should be satisfied

痞子三分冷 提交于 2021-01-27 13:35:25

问题


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.


回答1:


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()


来源:https://stackoverflow.com/questions/61408010/gekko-infeasible-solution-with-costraint-that-should-be-satisfied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!