i want to solve this MINLP problem.I have check carefully but it says
@error: Equation Definition
Equation without an equality (=) or inequality (>,<)
true
STOPPING...
Traceback (most recent call last):
File "D:\code\3_1.py", line 61, in <module>
m.solve(disp=True)
File "C:\{path}\Python311\Lib\site-packages\gekko\gekko.py", line 2140, in solve
raise Exception(apm_error)
Exception: @error: Equation Definition
Equation without an equality (=) or inequality (>,<)
true
STOPPING...
Please help me!
from gekko import GEKKO
import numpy as np
m = GEKKO(remote=False)
#Data
X1i = [8, 4, 8, 8]
Q1i_POT = [14365.35, 7182.17, 14364.35, 14364.35]
Q1i = [14365.35, 7182.17, 14364.35, 14364.35]
Q11= 14365.35
qi = [0.94, 0.92, 0.96, 0.98]
k1i = [5000, 1500, 4500, 3500]
v1i=[18, 15, 24, 30]
ci=[30000, 25000, 36000,28000]
hs=[5, 20, 50, 95, 145]
es=[5, 15, 30, 45, 50]
ks=[0,200, 150, 100, 50]
m_val=30
e1=5
alpha = 4*10**8
delta = 2
qa=0.95
#Decison variables
# Assuming Ji is a list of 4 continuous decision variables
Ji = [m.Var(value=0.0, lb=0.0) for _ in range(4)]
# Assuming X1i is a list of 4 continuous decision variables
X1i = [m.Var(value=0.0, lb=0.0, integer=True) for _ in range(4)]
# X2, X3, X4, X5
Xs = [m.Var(value=0.0, lb=0.0, integer=True) for _ in range(2, 6)]
# Assuming P is a continuous decision variable with a lower bound greater than 0
P = m.Var(value=0.0, lb=1e-5)
Q1 = m.Intermediate(Ji[1] * Q11)
# Constraint 1
m.Equation(Q1 == m.sum([Ji[i] * Q1i[i] for i in range(4)]))
# Constraint 2
for i in range(4):
m.Equation(alpha * P**(-delta) * Ji[i] * Q1i[i] <= Q1 * ci[i])
# Constraint 3
m.Equation(m.sum([Ji[i] * Q1i[i] * qi[i] for i in range(4)]) <= Q1 * qa)
# Constraint 8
m.Equation(m.sum([Ji[i] for i in range(4)]) <= m_val)
# Constraint 10
for i in range(4):
m.Equation(Q1i[i] >= 0)
# Constraint: 12
m.Equation(P > 0)
# Objective function
m.Maximize(alpha * P**(1-delta) - (1/Q1) \
* (alpha * P**(-delta) \
* m.sum([Ji[i] * k1i[i] for i in range(4)]) + \
e1/2 * m.sum([Ji[i] * (Q1i[i])**2 for i in range(4)]) + \
alpha * P**(-delta) * m.sum([Ji[i] * Q1i[i] * v1i[i] \
for i in range(4)])))
m.solve(disp=True)
I’ve tried pretty much everything. I’ve retyped the equations and doubled checked all the syntax with chatgpt. I’ve had the same error for 7 days and I am very stuck
The problem is with Constraint 10:
Q1i = [14365.35, 7182.17, 14364.35, 14364.35]
# Constraint 10
for i in range(4):
m.Equation(Q1i[i] >= 0)
This evaluates to True
four times because the elements of Q1i
are Python float
types instead of Gekko variables and all are greater than zero.
For troubleshooting, open the run directory with m.open_folder()
and the model file gk_model0.apm
. The model file shows the problem with the equations that are listed as True
.
Equations
v14=((v1)*(14365.35))
v15=((v2)*(7182.17))
v16=((v3)*(14364.35))
v17=((v4)*(14364.35))
i0=v18
((((((400000000)*(((v13)^(-2)))))*(v1)))*(14365.35))<=((i0)*(30000))
((((((400000000)*(((v13)^(-2)))))*(v2)))*(7182.17))<=((i0)*(25000))
((((((400000000)*(((v13)^(-2)))))*(v3)))*(14364.35))<=((i0)*(36000))
((((((400000000)*(((v13)^(-2)))))*(v4)))*(14364.35))<=((i0)*(28000))
v19=((((v1)*(14365.35)))*(0.94))
v20=((((v2)*(7182.17)))*(0.92))
v21=((((v3)*(14364.35)))*(0.96))
v22=((((v4)*(14364.35)))*(0.98))
v23<=((i0)*(0.95))
v24<=30
True
True
True
True
v13>0
v25=((v1)*(5000))
v26=((v2)*(1500))
v27=((v3)*(4500))
v28=((v4)*(3500))
For MINLP problems, you’ll also need to switch to the APOPT solver with m.options.SOLVER=1
.