控制范围和预测范围 [英] The control horizon and prediction horizon

查看:206
本文介绍了控制范围和预测范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经审查了用于模型预测控制的书目和Gekko编程结构。虽然我了解它的编程方式及其目的。我想了解例如Gekko如何根据Seborg中的相关信息管理控制范围和预测范围之间的差异。我看不到代码的差异。以下是用于说明的MPC应用程序示例。


 从gekko导入GEKKO 
导入numpy as np
导入matplotlib.pyplot as plt

m = GEKKO()

#时间范围[0,1,2,...,39,40]
m.time = np.linspace(0,40,41)

#MV =操纵变量
u = m.MV(值= 0,lb = 0,ub = 100)
u.STATUS = 1; u.DCOST = 0.1; u.DMAX = 20

#CV =控制变量
x = m.CV(value = 0,name =‘x’)
x.STATUS = 1; x.SP = 45

#定义模型
K = m.Param(value = 0.8); tau = 15.0
m.Equation(tau * x.dt()== -x + K * u)

#选项并求解
m.options.CV_TYPE = 2
m.options.MV_TYPE = 0
m.options.NODES = 3
m.options.IMODE = 6

#定义控制和预测范围
m.options.CTRL_HOR = 10
m.options.CTRL_TIME = 1
m.options.PRED_HOR = 40
m.options.PRED_TIME = 2

m .solve(disp = False)

#绘图结果
plt.figure()
plt.subplot(2,1,1)
plt.step(m .time,u.value,'b-',label ='MV Move Plan')
plt.legend()
plt.ylabel('MV')
plt.subplot(2 ,1,2)
plt.plot([0,40],[45,45],'k-',label ='Target Setpoint')
plt.plot(m.time,x .value,'r-',label ='CV Response')
plt.ylabel('CV')
plt.xlabel('Time')
plt.legend(loc = 最佳)
plt.show()

对于您对我应该如何考虑<代码中使用的code> np.linspace()指令。


谢谢。


SandraRodríguez

解决方案

控制范围是允许MV移动的时间范围的一部分。预测范围超出控制范围以预测最终的CV结果,但没有MV移动。这是工业模型预测性控制器的一个遗留概念,它需要计算短期移动计划,但还需要预测控制器的MV和CV最终将在哪里解决。


选项1:使用Gekko选项定义时间范围(不推荐)


参数 CTRL_HOR CTRL_TIME PRED_HOR PRED_TIME 是APMonitor的选项,但不会更改Gekko解决方案,除非您设置


选项2:使用 m.time()定义时间范围


使用 m.time 是定义MPC时间范围的首选方法。

  m.time = [0, 1,2,3,4,6,8,10,15,25,35,50,80] 

< a href = https://i.stack.imgur.com/ZwMuZ.png rel = nofollow noreferrer>


减少预测范围的自由度


目的预测范围的最大值是要计算到稳态,并保持控制范围的最后允许的MV移动不变。如果需要在某个点之后禁止MV移动,则 m.Connection()可以将MV值链接在一起,以在某个时间范围内禁止移动。

 #为范围(9,len(m.time))中的i创建预测范围

m .Connection(u,u,8,i)#连接端点节点
m.Connection(u,u,8,i,1,2)#连接内部节点


以下是此示例问题的完整代码。

 从gekko进口GEKKO 
进口numpy为np
进口matplotlib.pyplot为plt

m = GEKKO()

#时间范围
m.time = [0,1,2,3,4,6,8,10,15,25,35, 50,80]

#MV =操纵变量
u = m.MV(value = 0,lb = 0,ub = 100)
u.STATUS = 1; u.DCOST = 0.1; u.DMAX = 20

#CV =控制变量
x = m.CV(value = 0,name =‘x’)
x.STATUS = 1; x.SP = 45

#定义模型
K = m.Param(value = 0.8); tau = 15.0
m.Equation(tau * x.dt()== -x + K * u)

#选项并求解
m.options.CV_TYPE = 2
m.options.MV_TYPE = 0
m.options.NODES = 3
m.options.IMODE = 6

#为以下项目创建预测范围
i in range(9,len(m.time)):
m.Connection(u,u,8,i)#连接端点节点
m.Connection(u,u,8,i ,1,2)#连接内部节点

m.solve(disp = True)

#绘制结果
plt.figure()
plt .subplot(2,1,1)
plt.step(m.time,u.value,'b-',label ='MV Move Plan')
plt.plot(m.time [ 0:8],u.value [0:8],'o',color ='orange',label ='Control Horizo​​n')
plt.plot(m.time [8:],u.value [8:],'x',color ='purple',label ='Prediction Horizo​​n')
plt.legend()
plt.ylabel('MV')
plt.subplot (2,1,2)
plt.plot([0,80],[45,45],'k-',label ='Target Setpoint')
plt.plot(m.time ,x.value,'r .-',label ='CV Response')
plt.ylabel('CV')
plt.xlabel('Time')
plt.legend( loc ='best')
plt.show()


I have reviewed the bibliography and the Gekko programming structure for model predictive control.  Although I understood the way it is programmed and their purpose. I would like to understand how Gekko manages the differences between the control horizon and prediction horizon according to related in Seborg, for example.  I can´t see a differentiation on the code. Below is an example MPC application for illustration.

from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt  

m = GEKKO()

# Time Horizon [0,1,2,...,39,40]
m.time = np.linspace(0,40,41)

# MV = Manipulated Variable
u = m.MV(value=0, lb=0, ub=100)
u.STATUS=1; u.DCOST=0.1; u.DMAX=20

# CV = Controlled Variable
x = m.CV(value=0,name='x')
x.STATUS=1; x.SP=45

# Define model
K = m.Param(value=0.8); tau = 15.0
m.Equation(tau*x.dt() == -x + K*u)

# Options and solve
m.options.CV_TYPE = 2
m.options.MV_TYPE = 0
m.options.NODES   = 3
m.options.IMODE   = 6

# Define Control and Prediction Horizon
m.options.CTRL_HOR = 10
m.options.CTRL_TIME = 1
m.options.PRED_HOR = 40
m.options.PRED_TIME = 2

m.solve(disp=False)

# Plot results
plt.figure()
plt.subplot(2,1,1)
plt.step(m.time,u.value,'b-',label='MV Move Plan')
plt.legend()
plt.ylabel('MV')
plt.subplot(2,1,2)
plt.plot([0,40],[45,45],'k-',label='Target Setpoint')
plt.plot(m.time,x.value,'r--',label='CV Response')
plt.ylabel('CV')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()

I would appreciate your feedback about how I should consider the np.linspace() instruction used in the code.

Thank you.

Sandra Rodríguez

解决方案

The control horizon is the section of the time horizon where MV moves are allowed. The prediction horizon extends past the control horizon to predict the final CV outcomes but without MV movement. It is a legacy concept from industrial model predictive controllers that need to calculate a short-term move plan but also need to predict where the controller MVs and CVs will eventually settle out.

Option 1: Use Gekko Options to Define Time Horizon (not recommended)

The parameters CTRL_HOR, CTRL_TIME, PRED_HOR, and PRED_TIME are options from APMonitor but don't change the Gekko solution unless you set m.options.CSV_READ=0. Turning off the CSV file reading is not recommended because Gekko uses the CSV data file to communicate changes.

m.options.CSV_READ = 0

# Define Control and Prediction Horizon
m.options.CTRL_HOR = 10
m.options.CTRL_TIME = 1
m.options.PRED_HOR = 40
m.options.PRED_TIME = 1

Option 2: Use m.time() to Define Time Horizon

Using m.time is the preferred method for defining your MPC time horizon. It can be non-uniform with more than just a control and prediction interval.

m.time = [0,1,2,3,4,6,8,10,15,25,35,50,80]

Reduce Prediction Horizon Degrees of Freedom

The purpose of the prediction horizon is to calculate to steady state, holding the last allowable MV move from the control horizon constant. If you need to disallow MV movement after a certain point then m.Connection() can link MV values together to disallow movement after a certain time horizon location.

# Create prediction horizon
for i in range(9,len(m.time)):
    m.Connection(u,u,8,i)     # connect end point node
    m.Connection(u,u,8,i,1,2) # connect internal node

Here is the full code for this example problem.

from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt  

m = GEKKO()

# Time Horizon
m.time = [0,1,2,3,4,6,8,10,15,25,35,50,80]

# MV = Manipulated Variable
u = m.MV(value=0, lb=0, ub=100)
u.STATUS=1; u.DCOST=0.1; u.DMAX=20

# CV = Controlled Variable
x = m.CV(value=0,name='x')
x.STATUS=1; x.SP=45

# Define model
K = m.Param(value=0.8); tau = 15.0
m.Equation(tau*x.dt() == -x + K*u)

# Options and solve
m.options.CV_TYPE = 2
m.options.MV_TYPE = 0
m.options.NODES   = 3
m.options.IMODE   = 6

# Create prediction horizon
for i in range(9,len(m.time)):
    m.Connection(u,u,8,i)     # connect end point node
    m.Connection(u,u,8,i,1,2) # connect internal node

m.solve(disp=True)

# Plot results
plt.figure()
plt.subplot(2,1,1)
plt.step(m.time,u.value,'b-',label='MV Move Plan')
plt.plot(m.time[0:8],u.value[0:8],'o',color='orange',label='Control Horizon')
plt.plot(m.time[8:],u.value[8:],'x',color='purple',label='Prediction Horizon')
plt.legend()
plt.ylabel('MV')
plt.subplot(2,1,2)
plt.plot([0,80],[45,45],'k-',label='Target Setpoint')
plt.plot(m.time,x.value,'r.-',label='CV Response')
plt.ylabel('CV')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()

这篇关于控制范围和预测范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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