从这里得到代码:用非线性模型预测控制在GEKKO上实现横向contoller
我似乎不能运行它。我得到的错误是:
解决者开始..。
错误: dyld:库未加载: /usr/local/opt/gcc/lib/gcc/9/libquadmath.0.dylib 参考来源: /anaconda3/envs/wsb/lib/python3.6/site-packages/gekko/bin/apm_mac 原因:找不到图像 错误:“results.json”未找到。请检查上面的其他错误详细信息。 回溯(最近一次调用):m.solve(disp=True)文件第2216行,在solve self.load_JSON() File "/anaconda3/envs/wsb/lib/python3.6/site-packages/gekko/gk_post_solve.py",第13行中,在load_JSON f= open(os.path.join(self._path ),( 'options.json')) FileNotFoundError: Errno 2没有这样的文件或目录:FileNotFoundError
我也尝试过调试: Python找不到"options.json“文件
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO()
m.time = np.linspace(0,20,41)
# Parameters
mass = 500
b = m.Param(value=50)
K = m.Param(value=0.8)
# Manipulated variable
p = m.MV(value=0, lb=0, ub=100)
p.STATUS = 1 # allow optimizer to change
p.DCOST = 0.1 # smooth out gas pedal movement
p.DMAX = 20 # slow down change of gas pedal
# Controlled Variable
v = m.CV(value=0)
v.STATUS = 1 # add the SP to the objective
m.options.CV_TYPE = 2 # squared error
v.SP = 40 # set point
v.TR_INIT = 1 # set point trajectory
v.TAU = 5 # time constant of trajectory
# Process model
m.Equation(mass*v.dt() == -v*b + K*b*p)
m.options.IMODE = 6 # control
m.solve(disp=False)
# get additional solution information
import json
with open(m.path+'//results.json') as f:
results = json.load(f)
plt.figure()
plt.subplot(2,1,1)
plt.plot(m.time,p.value,'b-',label='MV Optimized')
plt.legend()
plt.ylabel('Input')
plt.subplot(2,1,2)
plt.plot(m.time,results['v1.tr'],'k-',label='Reference Trajectory')
plt.plot(m.time,v.value,'r--',label='CV Response')
plt.ylabel('Output')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()发布于 2021-04-27 03:17:51
脚本在您的问题语句中编写时成功运行。您所收到的错误是因为您正在使用MacOS并切换到m=GEKKO(remote=False)。这个GitHub问题描述了错误和解决方案。如果使用远程服务器,则不会出现错误。

https://stackoverflow.com/questions/67274898
复制相似问题