如何从gekko中检索'infeasibilities.txt'
How to retrieve the 'infeasibilities.txt' from the gekko
我收到来自 GEKKO 模拟的不可行错误消息。我想检索 'infeasibilities.txt' 文件以调试算法。
请告诉我在哪里可以找到该文件。
R1 = m.Intermediate(3/r0/W*((A3*(A2+B2+B3+F)+(A2+B2)*(B3+F))*(cg0[0]-ceq1) \
-(A3*(B2+B3+F)+B2*(B3+F))*(cg0[0]-ceq2) \
-A2*(B3+F)*(cg0[0]-ceq3)))
R2 = m.Intermediate(3/r0/W*(-(B2*(A3+B3+F)+A3*(B3+F))*(cg0[0]-ceq1) \
+((A1+B1+B2)*(A3+B3+F)+A3*(B3+F))*(cg0[0]-ceq2) \
-(A1+B1)*(B3+F)*(cg0[0]-ceq3)))
R3 = m.Intermediate(3/r0/W*(-A2*(B3+F)*(cg0[0]-ceq1) \
-(A1+B1)*(B3+F)*(cg0[0]-ceq2) \
+((A1+B1)*(A2+B2+B3+F)+A2*(B2+B1+F))*(cg0[0]-ceq3)))
m.Equation(cH.dt() == nus[0].dot([R1, R2, R3]))
m.Equation(cM.dt() == nus[1].dot([R1, R2, R3]))
m.Equation(cW.dt() == nus[2].dot([R1, R2, R3]))
m.Equation(cF.dt() == nus[3].dot([R1, R2, R3]))
m.options.IMODE = 4
m.options.SOLVER = 3
m.options.nodes = 2
正在创建文件:infeasibilities.txt
使用命令 apm_get(server,app,'infeasibilities.txt') 检索文件
错误:找不到解决方案
有两种方法可以访问该文件。第一种方法是切换到 remote=False
在本地解决并在您的计算机上生成 infeasibilities.txt 文件。第二种方法是从远程目录中检索文件。第一种方法在编码方面是最简单的解决方案(只需更改一个选项并打开 运行 文件夹)。第二种方法最方便,因为它使文件在您的 运行 目录中可用。我在下面包含的示例故意与方程 x+y=1
和 x+y=0
.
不可行
方法 1 - 在 remote=False
时打开 运行 文件夹
from gekko import GEKKO
m = GEKKO(remote=False) # remote=False to produce local folder with results
x = m.Var()
y = m.Var()
m.Equations([x+y==1, x+y==0]) # no solution
m.open_folder() # open folder if remote=False to see infeasibilities.txt
m.solve(disp=True) # solve
方法 2 - 在 remote=True
时检索 infeasibilities.txt 文件
from gekko import GEKKO
m = GEKKO(remote=True)
x = m.Var()
y = m.Var()
m.Equations([x+y==1, x+y==0]) # no solution
try:
m.solve(disp=True) # solve
except:
print('Not successful')
from gekko.apm import get_file
print(m._server)
print(m._model_name)
f = get_file(m._server,m._model_name,'infeasibilities.txt')
f = f.decode().replace('\r','')
with open('infeasibilities.txt', 'w') as fl:
fl.write(str(f))
infeasibilities.txt 文件有些难以阅读,但它确实尝试识别导致求解失败的方程式。这是这个问题的例子。
************************************************
***** POSSIBLE INFEASBILE EQUATIONS ************
************************************************
____________________________________________________________________________
EQ Number Lower Residual Upper Infeas. Name
1 0.0000E+00 -9.4140E-01 0.0000E+00 9.4140E-01 ss.Eqn(1): 0 = (v1+v2)-(1)
Variable Lower Value Upper $Value Name
1 -1.2346E+20 2.9300E-02 1.2346E+20 0.0000E+00 ss.v1
2 -1.2346E+20 2.9300E-02 1.2346E+20 0.0000E+00 ss.v2
____________________________________________________________________________
EQ Number Lower Residual Upper Infeas. Name
2 0.0000E+00 5.8600E-02 0.0000E+00 -5.8600E-02 ss.Eqn(2): 0 = (v1+v2)-(0)
Variable Lower Value Upper $Value Name
1 -1.2346E+20 2.9300E-02 1.2346E+20 0.0000E+00 ss.v1
2 -1.2346E+20 2.9300E-02 1.2346E+20 0.0000E+00 ss.v2
************************************************
****** ACTIVE OBJECTIVE EQUATIONS **************
************************************************
Number ID Node Horizon Unscaled Res Scaled Res Scaling Name
************************************************
************* ACTIVE EQUATIONS *****************
************************************************
Number ID Node Horizon Unscaled Res Scaled Res Scaling Name
1 1 1 1 -9.4140E-01 -9.4140E-01 1.0000E+00 ss.Eqn(1): 0 = (v1+v2)-(1)
2 2 1 1 5.8600E-02 5.8600E-02 1.0000E+00 ss.Eqn(2): 0 = (v1+v2)-(0)
************************************************
************ INACTIVE EQUATIONS ****************
************************************************
Number Unscaled Res Scaled Res Scaling Name
如果您使用 x = m.Var(name='x')
命名您的变量,那么该文件将变得更具描述性。这两个方程都被确定为可能不可行。
我收到来自 GEKKO 模拟的不可行错误消息。我想检索 'infeasibilities.txt' 文件以调试算法。
请告诉我在哪里可以找到该文件。
R1 = m.Intermediate(3/r0/W*((A3*(A2+B2+B3+F)+(A2+B2)*(B3+F))*(cg0[0]-ceq1) \
-(A3*(B2+B3+F)+B2*(B3+F))*(cg0[0]-ceq2) \
-A2*(B3+F)*(cg0[0]-ceq3)))
R2 = m.Intermediate(3/r0/W*(-(B2*(A3+B3+F)+A3*(B3+F))*(cg0[0]-ceq1) \
+((A1+B1+B2)*(A3+B3+F)+A3*(B3+F))*(cg0[0]-ceq2) \
-(A1+B1)*(B3+F)*(cg0[0]-ceq3)))
R3 = m.Intermediate(3/r0/W*(-A2*(B3+F)*(cg0[0]-ceq1) \
-(A1+B1)*(B3+F)*(cg0[0]-ceq2) \
+((A1+B1)*(A2+B2+B3+F)+A2*(B2+B1+F))*(cg0[0]-ceq3)))
m.Equation(cH.dt() == nus[0].dot([R1, R2, R3]))
m.Equation(cM.dt() == nus[1].dot([R1, R2, R3]))
m.Equation(cW.dt() == nus[2].dot([R1, R2, R3]))
m.Equation(cF.dt() == nus[3].dot([R1, R2, R3]))
m.options.IMODE = 4
m.options.SOLVER = 3
m.options.nodes = 2
正在创建文件:infeasibilities.txt
使用命令 apm_get(server,app,'infeasibilities.txt') 检索文件
错误:找不到解决方案
有两种方法可以访问该文件。第一种方法是切换到 remote=False
在本地解决并在您的计算机上生成 infeasibilities.txt 文件。第二种方法是从远程目录中检索文件。第一种方法在编码方面是最简单的解决方案(只需更改一个选项并打开 运行 文件夹)。第二种方法最方便,因为它使文件在您的 运行 目录中可用。我在下面包含的示例故意与方程 x+y=1
和 x+y=0
.
方法 1 - 在 remote=False
时打开 运行 文件夹from gekko import GEKKO
m = GEKKO(remote=False) # remote=False to produce local folder with results
x = m.Var()
y = m.Var()
m.Equations([x+y==1, x+y==0]) # no solution
m.open_folder() # open folder if remote=False to see infeasibilities.txt
m.solve(disp=True) # solve
方法 2 - 在 remote=True
时检索 infeasibilities.txt 文件from gekko import GEKKO
m = GEKKO(remote=True)
x = m.Var()
y = m.Var()
m.Equations([x+y==1, x+y==0]) # no solution
try:
m.solve(disp=True) # solve
except:
print('Not successful')
from gekko.apm import get_file
print(m._server)
print(m._model_name)
f = get_file(m._server,m._model_name,'infeasibilities.txt')
f = f.decode().replace('\r','')
with open('infeasibilities.txt', 'w') as fl:
fl.write(str(f))
infeasibilities.txt 文件有些难以阅读,但它确实尝试识别导致求解失败的方程式。这是这个问题的例子。
************************************************
***** POSSIBLE INFEASBILE EQUATIONS ************
************************************************
____________________________________________________________________________
EQ Number Lower Residual Upper Infeas. Name
1 0.0000E+00 -9.4140E-01 0.0000E+00 9.4140E-01 ss.Eqn(1): 0 = (v1+v2)-(1)
Variable Lower Value Upper $Value Name
1 -1.2346E+20 2.9300E-02 1.2346E+20 0.0000E+00 ss.v1
2 -1.2346E+20 2.9300E-02 1.2346E+20 0.0000E+00 ss.v2
____________________________________________________________________________
EQ Number Lower Residual Upper Infeas. Name
2 0.0000E+00 5.8600E-02 0.0000E+00 -5.8600E-02 ss.Eqn(2): 0 = (v1+v2)-(0)
Variable Lower Value Upper $Value Name
1 -1.2346E+20 2.9300E-02 1.2346E+20 0.0000E+00 ss.v1
2 -1.2346E+20 2.9300E-02 1.2346E+20 0.0000E+00 ss.v2
************************************************
****** ACTIVE OBJECTIVE EQUATIONS **************
************************************************
Number ID Node Horizon Unscaled Res Scaled Res Scaling Name
************************************************
************* ACTIVE EQUATIONS *****************
************************************************
Number ID Node Horizon Unscaled Res Scaled Res Scaling Name
1 1 1 1 -9.4140E-01 -9.4140E-01 1.0000E+00 ss.Eqn(1): 0 = (v1+v2)-(1)
2 2 1 1 5.8600E-02 5.8600E-02 1.0000E+00 ss.Eqn(2): 0 = (v1+v2)-(0)
************************************************
************ INACTIVE EQUATIONS ****************
************************************************
Number Unscaled Res Scaled Res Scaling Name
如果您使用 x = m.Var(name='x')
命名您的变量,那么该文件将变得更具描述性。这两个方程都被确定为可能不可行。