我试图修改pythongekko中的示例代码,使Model Predictive Control with the TCLab使用二进制(On/Off),而不是0到100%之间的连续加热器值。{1{1}的解仍被转换为连续变量,而不是将其转换为连续变量。在
# Manipulated variables
Q1b = m.MV(value=0,lb=0,ub=1,name='q1',integer=True)
Q1b.STATUS = 1 # manipulated
Q1b.FSTATUS = 0 # not measured
Q1b.DMAX = 1.0
Q1b.DCOST = 0.1
Q1 = m.Intermediate(Q1b*100)
Q2 = m.MV(value=0,name='q2')
Q2.STATUS = 1 # manipulated
Q2.FSTATUS = 0 # not measured
Q2.DMAX = 30.0
Q2.DCOST = 0.1
Q2.UPPER = 100.0
Q2.LOWER = 0.0
当决策变量(操纵变量)必须是二进制或整数解时,如何使用Gekko进行最优控制?在
您引用的示例问题使用默认的
IPOPT
解算器。要获得二进制或整数解,请切换到APOPT
解算器。在还有一件事需要做,因为您将
^{pr2}$Q1
从m.MV()
更改为m.Intermediate
类型。在访问Q1
值的循环中,进行以下修改:Q2
仍然是0到100%之间的连续值,您仍然可以使用Q2.NEWVAL
参数访问移动计划的第一步。对于Q1
,您需要使用Q1.value[1]
来访问第一步,因为它是m.Intermediate()
类型,并且没有NEWVAL
属性。如果安装了make_mp4=True
,脚本将生成一个带有make_mp4=True
的视频动画。动画显示Q1
现在是ON/OFF
(0或1),而{具有二元变量的模型预测控制
相关问题 更多 >
编程相关推荐