How to fix @Error: Equation Definition GEKKO
How to fix @Error: Equation Definition GEKKO
我正在研究成本最小化问题。我尝试了很多次,但仍然出现此错误:
Exception: @error: Equation Definition
Equation without an equality (=) or inequality (>,<)
1((((5.84-v34)+((6)*(int_v2))))*(31.7))
STOPPING...
这是我的代码:
import pandas as pd
import numpy as np
from gekko import GEKKO
m = GEKKO() # Initialize gekko
Sadd=pd.read_csv("Sadd.csv")
X2= m.Array(m.Var,len(Sadd),value=0,lb=-1,ub=1,integer=True)
SOC2= m.Array(m.Var,len(Sadd),value=100,lb=0,ub=100)
m.Equation(SOC2[0]==100)
for i in range(1,3):
m.Equation(SOC2[i]-SOC2[i-1] == 5*X2[i-1])
for i in range(3,11):
m.Equation(X2[i]==0)
m.Equation(SOC2[i]==0)
for i in range(12,16):
m.Equation(SOC2[i]-SOC2[i-1] == 5*X2[i-1])
m.Equation(SOC2[11]==SOC2[2]-55)
TOU=Sadd['TOU']
PV=m.Array(m.Var,len(Sadd),value=5)
for i in range(0,len(Sadd)):
m.Equation(PV[i]>= 0)
m.Equation(PV[i]<= Sadd['PV'].iloc[i])
m.Equation(Sadd['Load'].iloc[i]-PV[i]+6*X2[i]>=0)
m.Obj((Sadd['Load']-PV+6*X2)*TOU)
m.options.SOLVER=1
m.solve()
我该如何解决?谢谢
这是我的Sadd.csv,如果你想查看的话。非常感谢。
Date/Time C2 SC2 SOC2PV Load TOU
0 11/25/2020 6:00 0 0 0 0 5.82 31.7
1 11/25/2020 6:15 0 0 0 0 5.84 31.7
2 11/25/2020 6:30 0 55 0 0 7 31.7
3 11/25/2020 6:45 1 0 0 0 7.16 31.7
4 11/25/2020 7:00 1 0 0 0 8.41 31.7
5 11/25/2020 7:15 1 0 0 0 10.95 31.7
6 11/25/2020 7:30 1 0 0 1 11.79 31.7
7 11/25/2020 7:45 1 0 0 2.75 14.77 31.7
8 11/25/2020 8:00 1 0 0 4.35 12.24 31.7
9 11/25/2020 8:15 1 0 0 5.975 17.58 31.7
10 11/25/2020 8:30 1 0 0 7.65 16.79 31.7
11 11/25/2020 8:45 0 0 0 8.625 19.04 31.7
12 11/25/2020 9:00 0 0 0 8.8 20.66 31.7
13 11/25/2020 9:15 0 0 0 9.575 18.57 11
14 11/25/2020 9:30 0 0 0 10.5 19.66 11
15 11/25/2020 9:45 0 0 0 10.625 19.76 11
尝试索引 objective 中的值。
for i in range(len(Sadd)):
m.Minimize((Sadd['Load'].iloc[i]-PV[i]+6*X2[i])*TOU[i])
将多个 objective 函数相加以创建最终组合 objective。
import pandas as pd
import numpy as np
from gekko import GEKKO
m = GEKKO(remote=False) # Initialize gekko
Sadd=pd.read_csv("Sadd.csv")
X2= m.Array(m.Var,len(Sadd),value=0,lb=-1,ub=1,integer=True)
SOC2= m.Array(m.Var,len(Sadd),value=100,lb=0,ub=100)
m.Equation(SOC2[0]==100)
for i in range(1,3):
m.Equation(SOC2[i]-SOC2[i-1] == 5*X2[i-1])
for i in range(3,11):
m.Equation(X2[i]==0)
m.Equation(SOC2[i]==0)
for i in range(12,16):
m.Equation(SOC2[i]-SOC2[i-1] == 5*X2[i-1])
m.Equation(SOC2[11]==SOC2[2]-55)
TOU=Sadd['TOU'].values
PV=m.Array(m.Var,len(Sadd),value=5)
for i in range(0,len(Sadd)):
m.Equation(PV[i]>= 0)
m.Equation(PV[i]<= Sadd['PV'].iloc[i])
m.Equation(Sadd['Load'].iloc[i]-PV[i]+6*X2[i]>=0)
for i in range(len(Sadd)):
m.Minimize((Sadd['Load'].iloc[i]-PV[i]+6*X2[i])*TOU[i])
m.options.SOLVER=1
m.solve()
现在给出了一个成功的解决方案:
----------------------------------------------
Steady State Optimization with APOPT Solver
----------------------------------------------
Iter: 1 I: 0 Tm: -0.00 NLPi: 2 Dpth: 0 Lvs: 3 Obj: 2.93E+03 Gap: NaN
Iter: 2 I: -1 Tm: -0.00 NLPi: 1 Dpth: 1 Lvs: 2 Obj: 2.93E+03 Gap: NaN
Iter: 3 I: 0 Tm: -0.00 NLPi: 2 Dpth: 1 Lvs: 3 Obj: 3.12E+03 Gap: NaN
Iter: 4 I: -1 Tm: -0.00 NLPi: 2 Dpth: 1 Lvs: 2 Obj: 2.93E+03 Gap: NaN
--Integer Solution: 3.30E+03 Lowest Leaf: 3.12E+03 Gap: 5.77E-02
Iter: 5 I: 0 Tm: -0.00 NLPi: 2 Dpth: 2 Lvs: 1 Obj: 3.30E+03 Gap: 5.77E-02
Iter: 6 I: -1 Tm: 0.02 NLPi: 2 Dpth: 2 Lvs: 0 Obj: 3.12E+03 Gap: 5.77E-02
No additional trial points, returning the best integer solution
Successful solution
---------------------------------------------------
Solver : APOPT (v1.0)
Solution time : 0.031299999999999994 sec
Objective : 3300.72
Successful solution
---------------------------------------------------
这是我从 DataFrame 转换而来的 CSV 文件,以防其他人想要 运行 脚本并需要数据。
Date/Time,C2,SC2,SOC2,PV,Load,TOU
11/25/2020 6:00,0,0,0,0,5.82,31.7
11/25/2020 6:15,0,0,0,0,5.84,31.7
11/25/2020 6:30,0,55,0,0,7,31.7
11/25/2020 6:45,1,0,0,0,7.16,31.7
11/25/2020 7:00,1,0,0,0,8.41,31.7
11/25/2020 7:15,1,0,0,0,10.95,31.7
11/25/2020 7:30,1,0,0,1,11.79,31.7
11/25/2020 7:45,1,0,0,2.75,14.77,31.7
11/25/2020 8:00,1,0,0,4.35,12.24,31.7
11/25/2020 8:15,1,0,0,5.975,17.58,31.7
11/25/2020 8:30,1,0,0,7.65,16.79,31.7
11/25/2020 8:45,0,0,0,8.625,19.04,31.7
11/25/2020 9:00,0,0,0,8.8,20.66,31.7
11/25/2020 9:15,0,0,0,9.575,18.57,11
11/25/2020 9:30,0,0,0,10.5,19.66,11
11/25/2020 9:45,0,0,0,10.625,19.76,11
我正在研究成本最小化问题。我尝试了很多次,但仍然出现此错误:
Exception: @error: Equation Definition
Equation without an equality (=) or inequality (>,<)
1((((5.84-v34)+((6)*(int_v2))))*(31.7))
STOPPING...
这是我的代码:
import pandas as pd
import numpy as np
from gekko import GEKKO
m = GEKKO() # Initialize gekko
Sadd=pd.read_csv("Sadd.csv")
X2= m.Array(m.Var,len(Sadd),value=0,lb=-1,ub=1,integer=True)
SOC2= m.Array(m.Var,len(Sadd),value=100,lb=0,ub=100)
m.Equation(SOC2[0]==100)
for i in range(1,3):
m.Equation(SOC2[i]-SOC2[i-1] == 5*X2[i-1])
for i in range(3,11):
m.Equation(X2[i]==0)
m.Equation(SOC2[i]==0)
for i in range(12,16):
m.Equation(SOC2[i]-SOC2[i-1] == 5*X2[i-1])
m.Equation(SOC2[11]==SOC2[2]-55)
TOU=Sadd['TOU']
PV=m.Array(m.Var,len(Sadd),value=5)
for i in range(0,len(Sadd)):
m.Equation(PV[i]>= 0)
m.Equation(PV[i]<= Sadd['PV'].iloc[i])
m.Equation(Sadd['Load'].iloc[i]-PV[i]+6*X2[i]>=0)
m.Obj((Sadd['Load']-PV+6*X2)*TOU)
m.options.SOLVER=1
m.solve()
我该如何解决?谢谢
这是我的Sadd.csv,如果你想查看的话。非常感谢。
Date/Time C2 SC2 SOC2PV Load TOU
0 11/25/2020 6:00 0 0 0 0 5.82 31.7
1 11/25/2020 6:15 0 0 0 0 5.84 31.7
2 11/25/2020 6:30 0 55 0 0 7 31.7
3 11/25/2020 6:45 1 0 0 0 7.16 31.7
4 11/25/2020 7:00 1 0 0 0 8.41 31.7
5 11/25/2020 7:15 1 0 0 0 10.95 31.7
6 11/25/2020 7:30 1 0 0 1 11.79 31.7
7 11/25/2020 7:45 1 0 0 2.75 14.77 31.7
8 11/25/2020 8:00 1 0 0 4.35 12.24 31.7
9 11/25/2020 8:15 1 0 0 5.975 17.58 31.7
10 11/25/2020 8:30 1 0 0 7.65 16.79 31.7
11 11/25/2020 8:45 0 0 0 8.625 19.04 31.7
12 11/25/2020 9:00 0 0 0 8.8 20.66 31.7
13 11/25/2020 9:15 0 0 0 9.575 18.57 11
14 11/25/2020 9:30 0 0 0 10.5 19.66 11
15 11/25/2020 9:45 0 0 0 10.625 19.76 11
尝试索引 objective 中的值。
for i in range(len(Sadd)):
m.Minimize((Sadd['Load'].iloc[i]-PV[i]+6*X2[i])*TOU[i])
将多个 objective 函数相加以创建最终组合 objective。
import pandas as pd
import numpy as np
from gekko import GEKKO
m = GEKKO(remote=False) # Initialize gekko
Sadd=pd.read_csv("Sadd.csv")
X2= m.Array(m.Var,len(Sadd),value=0,lb=-1,ub=1,integer=True)
SOC2= m.Array(m.Var,len(Sadd),value=100,lb=0,ub=100)
m.Equation(SOC2[0]==100)
for i in range(1,3):
m.Equation(SOC2[i]-SOC2[i-1] == 5*X2[i-1])
for i in range(3,11):
m.Equation(X2[i]==0)
m.Equation(SOC2[i]==0)
for i in range(12,16):
m.Equation(SOC2[i]-SOC2[i-1] == 5*X2[i-1])
m.Equation(SOC2[11]==SOC2[2]-55)
TOU=Sadd['TOU'].values
PV=m.Array(m.Var,len(Sadd),value=5)
for i in range(0,len(Sadd)):
m.Equation(PV[i]>= 0)
m.Equation(PV[i]<= Sadd['PV'].iloc[i])
m.Equation(Sadd['Load'].iloc[i]-PV[i]+6*X2[i]>=0)
for i in range(len(Sadd)):
m.Minimize((Sadd['Load'].iloc[i]-PV[i]+6*X2[i])*TOU[i])
m.options.SOLVER=1
m.solve()
现在给出了一个成功的解决方案:
----------------------------------------------
Steady State Optimization with APOPT Solver
----------------------------------------------
Iter: 1 I: 0 Tm: -0.00 NLPi: 2 Dpth: 0 Lvs: 3 Obj: 2.93E+03 Gap: NaN
Iter: 2 I: -1 Tm: -0.00 NLPi: 1 Dpth: 1 Lvs: 2 Obj: 2.93E+03 Gap: NaN
Iter: 3 I: 0 Tm: -0.00 NLPi: 2 Dpth: 1 Lvs: 3 Obj: 3.12E+03 Gap: NaN
Iter: 4 I: -1 Tm: -0.00 NLPi: 2 Dpth: 1 Lvs: 2 Obj: 2.93E+03 Gap: NaN
--Integer Solution: 3.30E+03 Lowest Leaf: 3.12E+03 Gap: 5.77E-02
Iter: 5 I: 0 Tm: -0.00 NLPi: 2 Dpth: 2 Lvs: 1 Obj: 3.30E+03 Gap: 5.77E-02
Iter: 6 I: -1 Tm: 0.02 NLPi: 2 Dpth: 2 Lvs: 0 Obj: 3.12E+03 Gap: 5.77E-02
No additional trial points, returning the best integer solution
Successful solution
---------------------------------------------------
Solver : APOPT (v1.0)
Solution time : 0.031299999999999994 sec
Objective : 3300.72
Successful solution
---------------------------------------------------
这是我从 DataFrame 转换而来的 CSV 文件,以防其他人想要 运行 脚本并需要数据。
Date/Time,C2,SC2,SOC2,PV,Load,TOU
11/25/2020 6:00,0,0,0,0,5.82,31.7
11/25/2020 6:15,0,0,0,0,5.84,31.7
11/25/2020 6:30,0,55,0,0,7,31.7
11/25/2020 6:45,1,0,0,0,7.16,31.7
11/25/2020 7:00,1,0,0,0,8.41,31.7
11/25/2020 7:15,1,0,0,0,10.95,31.7
11/25/2020 7:30,1,0,0,1,11.79,31.7
11/25/2020 7:45,1,0,0,2.75,14.77,31.7
11/25/2020 8:00,1,0,0,4.35,12.24,31.7
11/25/2020 8:15,1,0,0,5.975,17.58,31.7
11/25/2020 8:30,1,0,0,7.65,16.79,31.7
11/25/2020 8:45,0,0,0,8.625,19.04,31.7
11/25/2020 9:00,0,0,0,8.8,20.66,31.7
11/25/2020 9:15,0,0,0,9.575,18.57,11
11/25/2020 9:30,0,0,0,10.5,19.66,11
11/25/2020 9:45,0,0,0,10.625,19.76,11