当我 运行 python 中的 APMonitor nlc 示例时出现 HTTP 错误
HTTP error when I run the APMonitor nlc example in python
我一直对学习 MPC 控制很感兴趣,我想尝试 nlc python 示例在这里找到:
http://apmonitor.com/wiki/index.php/Main/PythonApp
当我 运行 初始演示示例时,出现 HTTP 错误。通过在 apm.py 文件中将 "http" 的实例更改为 "https",我能够 运行 演示示例,类似于此处发现的问题:
https://github.com/olivierhagolle/LANDSAT-Download/issues/33
我现在一直在尝试 运行 nlc 示例,但我遇到了同样的错误(如下所示)。但是,将 "http" 的实例更改为 "https" 似乎不再有帮助。
*Traceback(最后一次调用):
文件 "C:\Users\veli95839\Documents\Python\Scripts\example_nlc\nlc.py",第 88 行,位于
响应 = apm_meas(服务器、应用程序、x、值)
文件 "C:\Users\veli95839\Documents\Python\Scripts\example_nlc\apm.py",第 607 行,在 load_meas 中
f = urllib.request.urlopen(url_base,params_en)
文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 222 行,在 url 打开
return opener.open(url, 数据, 超时)
文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 531 行,打开
响应 = meth(请求,响应)
文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 640 行,在 http_response 中
响应 = self.parent.error(
文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 569 行,错误
return self._call_chain(*参数)
文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 502 行,在 _call_chain 中
结果 = func(args)
文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 649 行,在 http_error_default 中
提高 HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError:HTTP 错误 503:服务不可用
如果有人遇到过类似问题,请告诉我!
谢谢,
克莱尔
如果您的计算机未连接到 Internet 或服务器在您 运行 测试时不可用,您可能会收到该错误。你可以安装一个local APM server (for Windows or Linux) to avoid any disruptions. Another option is to switch to Python gekko that uses the same underlying APM engine but can run locally with remote=False
. Here is the same MPC example in Python gekko.
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO(remote=False)
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,GUI=True)
# 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()
如果您想获得有关非线性或线性模型预测控制的 APM Python 或 gekko 的更多信息,series of tutorials with the Temperature Control Lab (TCLab).
具有解决方案的高级控制实验室
- 数字孪生模型开发
- 实验 A - 单加热器建模
- 实验 B - 双加热器建模
- 具有参数和状态估计的机器学习
- 实验 C - 参数估计
- 实验 D - 经验模型估计
- 实验 E - 混合模型估计
- 模型预测控制
- Lab F - 线性模型预测控制
- 实验 G - 非线性模型预测控制
- Lab H - 移动 Horizon 使用 MPC 进行估计
这些练习教授如何进行第一性原理或经验建模、状态估计和预测控制。下面是来自实验室 H 的组合移动 Horizon 估计和模型预测控制的示例。
我一直对学习 MPC 控制很感兴趣,我想尝试 nlc python 示例在这里找到:
http://apmonitor.com/wiki/index.php/Main/PythonApp
当我 运行 初始演示示例时,出现 HTTP 错误。通过在 apm.py 文件中将 "http" 的实例更改为 "https",我能够 运行 演示示例,类似于此处发现的问题:
https://github.com/olivierhagolle/LANDSAT-Download/issues/33
我现在一直在尝试 运行 nlc 示例,但我遇到了同样的错误(如下所示)。但是,将 "http" 的实例更改为 "https" 似乎不再有帮助。
*Traceback(最后一次调用): 文件 "C:\Users\veli95839\Documents\Python\Scripts\example_nlc\nlc.py",第 88 行,位于 响应 = apm_meas(服务器、应用程序、x、值) 文件 "C:\Users\veli95839\Documents\Python\Scripts\example_nlc\apm.py",第 607 行,在 load_meas 中 f = urllib.request.urlopen(url_base,params_en) 文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 222 行,在 url 打开 return opener.open(url, 数据, 超时) 文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 531 行,打开 响应 = meth(请求,响应) 文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 640 行,在 http_response 中 响应 = self.parent.error( 文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 569 行,错误 return self._call_chain(*参数) 文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 502 行,在 _call_chain 中 结果 = func(args) 文件 "C:\Users\veli95839\Documents\Python\lib\urllib\request.py",第 649 行,在 http_error_default 中 提高 HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError:HTTP 错误 503:服务不可用
如果有人遇到过类似问题,请告诉我!
谢谢,
克莱尔
如果您的计算机未连接到 Internet 或服务器在您 运行 测试时不可用,您可能会收到该错误。你可以安装一个local APM server (for Windows or Linux) to avoid any disruptions. Another option is to switch to Python gekko that uses the same underlying APM engine but can run locally with remote=False
. Here is the same MPC example in Python gekko.
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO(remote=False)
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,GUI=True)
# 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()
如果您想获得有关非线性或线性模型预测控制的 APM Python 或 gekko 的更多信息,series of tutorials with the Temperature Control Lab (TCLab).
具有解决方案的高级控制实验室
- 数字孪生模型开发
- 实验 A - 单加热器建模
- 实验 B - 双加热器建模
- 具有参数和状态估计的机器学习
- 实验 C - 参数估计
- 实验 D - 经验模型估计
- 实验 E - 混合模型估计
- 模型预测控制
- Lab F - 线性模型预测控制
- 实验 G - 非线性模型预测控制
- Lab H - 移动 Horizon 使用 MPC 进行估计
这些练习教授如何进行第一性原理或经验建模、状态估计和预测控制。下面是来自实验室 H 的组合移动 Horizon 估计和模型预测控制的示例。