Python TypeError:必须是实数,而不是GK_运算符
我对python了解不多,但我需要帮助来理解为什么会出现我的优化方程 TypeError:必须是实数,而不是GK_运算符 我做错了什么?此问题可在apmonitor.com(hs87)上找到Python TypeError:必须是实数,而不是GK_运算符,python,optimization,gekko,Python,Optimization,Gekko,我对python了解不多,但我需要帮助来理解为什么会出现我的优化方程 TypeError:必须是实数,而不是GK_运算符 我做错了什么?此问题可在apmonitor.com(hs87)上找到 from gekko import GEKKO import math m = GEKKO () #Parameters a = 131.078 b = 1.48477 #Hock & Schittkowski say 1.48577 c = 0.90798 d0 = 1.47588 e0 =
from gekko import GEKKO
import math
m = GEKKO ()
#Parameters
a = 131.078
b = 1.48477 #Hock & Schittkowski say 1.48577
c = 0.90798
d0 = 1.47588
e0 = 1.47588
d = math.cos(d0)
e = math.sin(e0)
lim1 = 300
lim2 = 100
lim3 = 200
rate1 = 30
rate2 = 31
rate3 = 28
rate4 = 29
rate5 = 30
#var x1 >= 0, <= 400;
#var x2 >= 0, <= 1000;
#var x3 >= 340, <= 420;
#var x4 >= 340, <= 420;
#var x5 >= -1000, <= 1000; # Hock & Schittkowski say <= 10000
#var x6 >= 0, <= 0.5236;
add[1:3] > 0
slk[1:3]
x1 = m.Var(value = 390)
x2 = m.Var(value = 1000)
x3 = m.Var(value = 419.5)
x4 = m.Var(value = 340.5)
x5 = m.Var(value = 198.175)
x6 = m.Var(value = 0.5)
add1 = x1 - lim1 + slk1
add2 = x2 - lim2 + slk2
add3 = x2 - lim3 + slk3
m.Equations(300 - x3*x4*math.cos(b - x6)/a + c*x3^2*d/a)
m.Equations(-x3*x4*math.cos(b + x6)/a + c*x4^2*d/a)
m.Equations(-x3*x4*math.sin(b + x6)/a + c*x4^2*e/a)
m.Equations(200 - x3*x4*math.sin(b - x6)/a + c*x3^2*e/a == 0)
m.obj(rate1*x1 + (rate2-rate1)*add1)
m.obj(rate3*x2 + (rate4-rate3)*add2 + (rate5-rate4)*add3)
m.solve(disp=False)
print(x1.value)
print(x2.value)
print(x3.value)
print(x4.value)
print(x5.value)
print(x6.value)
从gekko导入gekko
输入数学
m=壁虎()
#参数
a=131.078
b=1.48477 35;霍克和希特科夫斯基说是1.48577
c=0.90798
d0=1.47588
e0=1.47588
d=数学cos(d0)
e=数学sin(e0)
lim1=300
lim2=100
lim3=200
比率1=30
比率2=31
比率3=28
比率4=29
比率5=30
#var x1>=0,=0,=340,=340,=-1000,一些提示:
- 使用Python power运算符
**
而不是^
- 每个等式必须有一个等式
=
或不等式
,=
,0
slk[1:3]
x[1]=390,>=0,=0,=340,=340,=-1000,
EXIT: Converged to a point of local infeasibility. Problem may be infeasible.
An error occured.
The error code is 2
---------------------------------------------------
Solver : IPOPT (v3.12)
Solution time : 4.060000000026776E-002 sec
Objective : 5159.30673181783
Unsuccessful with error code 0
---------------------------------------------------
Creating file: infeasibilities.txt
Use command apm_get(server,app,'infeasibilities.txt') to retrieve file
@error: Solution Not Found
! Nonlinear electrical network
! The problem is corrected to conform to the problem as stated in
! D. M. Himmelblau, Applied Nonlinear Programming,
! McGraw-Hill, 1972, pp. 413-414
! except that jump-discontinuities in the objective function are
! omitted by stating it as the sum of two piecewise-linear terms
Model hs87
Parameters
a = 131.078
b = 1.48477 ! Hock & Schittkowski say 1.48577
c = 0.90798
d0 = 1.47588
e0 = 1.47588
d = cos(d0)
e = sin(e0)
lim[1] = 300
lim[2] = 100
lim[3] = 200
rate[1] = 30
rate[2] = 31
rate[3] = 28
rate[4] = 29
rate[5] = 30
End Parameters
Variables
add[1:3] > 0
slk[1:3]
x[1] = 390, >= 0, <= 400
x[2] = 1000, >= 0, <= 1000
x[3] = 419.5, >= 340, <= 420
x[4] = 340.5, >= 340, <= 420
x[5] = 198.175, >= -1000, <= 1000 ! Hock & Schittkowski say <= 10000
x[6] = 0.5, >= 0, <= 0.5236
obj[1:2]
End Variables
Equations
! piecewise linear
add[1] = x[1] - lim[1] + slk[1]
add[2] = x[2] - lim[2] + slk[2]
add[3] = x[2] - lim[3] + slk[3]
x[1] = 300 - x[3]*x[4]*cos(b - x[6])/a + c*x[3]^2*d/a
x[2] = -x[3]*x[4]*cos(b + x[6])/a + c*x[4]^2*d/a
x[5] = -x[3]*x[4]*sin(b + x[6])/a + c*x[4]^2*e/a
200 - x[3]*x[4]*sin(b - x[6])/a + c*x[3]^2*e/a = 0
! best known objective = 8827.5977
obj[1] = rate[1]*x[1] + (rate[2]-rate[1])*add[1]
obj[2] = rate[3]*x[2] + (rate[4]-rate[3])*add[2] + (rate[5]-rate[4])*add[3]
End Equations
End Model