如何从gekko检索'infeasibilities.txt' [英] How to retrieve the 'infeasibilities.txt' from the gekko

查看:73
本文介绍了如何从gekko检索'infeasibilities.txt'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了来自GEKKO模拟的不可行错误消息.我想检索"infeasibilities.txt"文件以调试算法.

I've got an infeasibility error message from GEKKO simulation. I want to retrieve the 'infeasibilities.txt' file for debugging the algorithm.

请让我知道在哪里可以找到该文件.

Please let me know where I can find the file.

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

创建文件:infeasiasibilities.txt

Creating file: infeasibilities.txt

使用命令apm_get(server,app,'infeasibilities.txt')检索文件

Use command apm_get(server,app,'infeasibilities.txt') to retrieve file

错误:找不到解决方案

推荐答案

有两种访问文件的方法.第一种方法是切换到 remote = False 在本地求解并在您的计算机上生成infeasibilities.txt文件.第二种方法是从远程目录中检索文件.第一种方法是最简单的编码解决方案(只需更改一个选项并打开运行文件夹).第二种方法最方便,因为它使文件在运行目录中可用.我下面包含的示例故意不适合方程式 x + y = 1 x + y = 0 .

There are two ways to access the file. The first method is to switch to remote=False to solve locally and produce the infeasibilities.txt file on your computer. The second method is to retrieve the file from the remote directory. The first method is the most simple solution in terms of coding (just change an option and open the run folder). The second method is most convenient because it makes the file available in your run directory. The example that I include below is purposefully infeasible with equations x+y=1 and 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文件在某种程度上很难读取,但是它确实试图识别导致解决方案失败的方程式.这是此问题的示例.

The infeasibilities.txt file is somewhat hard to read but it does try to identify equations that are causing the solution to fail. Here is the example from this problem.

************************************************
***** 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')命名变量,则文件将变得更具描述性.这两个方程都被认为是不可行的.

If you use x = m.Var(name='x') to name your variables then the file will become more descriptive. Both equations were identified as potentially infeasible.

这篇关于如何从gekko检索'infeasibilities.txt'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆