与MPC在Gekko的自由度警告

发布于 2025-01-30 18:03:04 字数 2913 浏览 2 评论 0原文

我正在尝试使用Gekko和MPC预测控制器的行为。我是控制系统的新手,以前从未与MPC或Gekko合作过。

我想最大程度地减少通风系统中风扇的功率,同时将温度保持在所需的范围内,特别是在图像中显示的范围内:

“上临时范围(蓝色)和下(绿色)和下(绿色)

我已经获得了一个使用Pysindy的方程式描述了通风系统的风扇功率与房间温度之间的关系。它以:

DX/DT = 0.205+0.029Y-0.003XY-0.001X^2,

其中X是室温,Y是风扇功率。

我的代码如下:

# Initialize GEKKO model
m = GEKKO() 
m.time = np.linspace(0,144,144)

# Manipulated variable
y = m.MV(value=0,lb=0,ub=100) # *** This is the fan power y *** 
y.STATUS = 1 
y.DCOST = 0.1
y.DMAX = 20

# Controlled variable
x = m.CV(value=18) #Initial value of control variable. *** This is temperature x ***
x.STATUS = 1

m.option.CV_TYPE = 1 #L1 norm
x.RT_INIT = 1
x.TAU = 20

# Add contraints
temp_u = np.concatenate((19*np.ones(32),22.5*np.ones(80),19*np.ones(32))) # Upper temperature limit 
temp_l = np.concatenate((17.5*np.ones(38),21.0*np.ones(68),17.5*np.ones(38))) # Lower temperature limit

T_low = m.Param(value=temp_l)
T_high = m.Param(value=temp_u)

m.Equations([x>=T_low, x<=T_high])

# Equation
m.Equation(x.dt() == 0.205+0.029*y-0.003*x*y-0.001*(x**2))

#MPC Mode
m.options.IMODE = 6 

#Solve
m.solve()

我得到以下输出:

apm 77.241.105.43_gk_model4 <br><pre> ----------------------------------------------------------------
 APMonitor, Version 1.0.1
 APMonitor Optimization Suite
 ----------------------------------------------------------------
 
 
 --------- APM Model Size ------------
 Each time step contains
   Objects      :            0
   Constants    :            0
   Variables    :            6
   Intermediates:            0
   Connections  :            0
   Equations    :            3
   Residuals    :            3
 
 Number of state variables:           2860
 Number of total equations: -         2717
 Number of slack variables: -          286
 ---------------------------------------
 Degrees of freedom       :           -143
 
 * Warning: DOF <= 0
 **********************************************
 Dynamic Control with Interior Point Solver
...
 
 Creating file: infeasibilities.txt
 Use command apm_get(server,app,'infeasibilities.txt') to retrieve file
 @error: Solution Not Found
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
~\mpc.ipynb Cell 11' in <cell line: 1>()
----> 1 m.solve()

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\gekko\gekko.py:2185, in GEKKO.solve(self, disp, debug, GUI, **kwargs)
   2183 #print APM error message and die
   2184 if (debug >= 1) and ('@error' in response):
-> 2185     raise Exception(response)
   2187 #load results
   2188 def byte2str(byte):

Exception:  @error: Solution Not Found

I am trying to predict how a controller behaves given a temperature range using GEKKO and MPC. I am new to control systems and have never worked with either MPC or GEKKO before.

I want to minimize the power of a fan in a ventilation system while keeping the temperature within a desired range, specifically within the range shown in the image:

Upper temp range (blue) and lower (green)

I have obtained an equation using PySINDy that described the relationship between fan power of a ventilation system and the temperature in the room. It is given as:

dx/dt = 0.205+0.029y-0.003xy-0.001x^2

where x is the room temperature and y is the fan power.

My code is as follows:

# Initialize GEKKO model
m = GEKKO() 
m.time = np.linspace(0,144,144)

# Manipulated variable
y = m.MV(value=0,lb=0,ub=100) # *** This is the fan power y *** 
y.STATUS = 1 
y.DCOST = 0.1
y.DMAX = 20

# Controlled variable
x = m.CV(value=18) #Initial value of control variable. *** This is temperature x ***
x.STATUS = 1

m.option.CV_TYPE = 1 #L1 norm
x.RT_INIT = 1
x.TAU = 20

# Add contraints
temp_u = np.concatenate((19*np.ones(32),22.5*np.ones(80),19*np.ones(32))) # Upper temperature limit 
temp_l = np.concatenate((17.5*np.ones(38),21.0*np.ones(68),17.5*np.ones(38))) # Lower temperature limit

T_low = m.Param(value=temp_l)
T_high = m.Param(value=temp_u)

m.Equations([x>=T_low, x<=T_high])

# Equation
m.Equation(x.dt() == 0.205+0.029*y-0.003*x*y-0.001*(x**2))

#MPC Mode
m.options.IMODE = 6 

#Solve
m.solve()

I get the following output :

apm 77.241.105.43_gk_model4 <br><pre> ----------------------------------------------------------------
 APMonitor, Version 1.0.1
 APMonitor Optimization Suite
 ----------------------------------------------------------------
 
 
 --------- APM Model Size ------------
 Each time step contains
   Objects      :            0
   Constants    :            0
   Variables    :            6
   Intermediates:            0
   Connections  :            0
   Equations    :            3
   Residuals    :            3
 
 Number of state variables:           2860
 Number of total equations: -         2717
 Number of slack variables: -          286
 ---------------------------------------
 Degrees of freedom       :           -143
 
 * Warning: DOF <= 0
 **********************************************
 Dynamic Control with Interior Point Solver
...
 
 Creating file: infeasibilities.txt
 Use command apm_get(server,app,'infeasibilities.txt') to retrieve file
 @error: Solution Not Found
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
~\mpc.ipynb Cell 11' in <cell line: 1>()
----> 1 m.solve()

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\gekko\gekko.py:2185, in GEKKO.solve(self, disp, debug, GUI, **kwargs)
   2183 #print APM error message and die
   2184 if (debug >= 1) and ('@error' in response):
-> 2185     raise Exception(response)
   2187 #load results
   2188 def byte2str(byte):

Exception:  @error: Solution Not Found

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错爱 2025-02-06 18:03:04

对于那些处于类似位置的人,解决了我自己的问题:

m = GEKKO()
m.time = np.linspace(0,144,145)
# Upper temperature limit 
temp_u = np.concatenate((18*np.ones(32),22*np.ones(81),18*np.ones(32)))
# Lower temperature limit 
temp_l = np.concatenate((17.0*np.ones(42),21.0*np.ones(61),17.0*np.ones(42)))
T_low = m.Param(value=temp_l)
T_high = m.Param(value=temp_u)

#Manipulated variable
u = m.MV(value=0,lb=0,ub=100)
u.STATUS = 1

#Controlled variable
T = m.SV(value=18)

#Soft constraints
eH = m.CV(value=0)
eL = m.CV(value=0)

eH.SPHI=0; eH.WSPHI=10; eH.WSPLO=0  ; eH.STATUS = 1
eL.SPLO=0; eL.WSPHI=0  ; eL.WSPLO=10; eL.STATUS = 1

m.Equations([eH==T-T_high,eL==T-T_low])
#m.Equations([eH==T-T_high])
m.Equation(T.dt() == 02.05+0.029*u-0.003*T*u-0.001*(T**2))
m.Minimize(u)


m.options.IMODE = 6
m.solve(disp=True,debug=True)

For those in a similar position, solved my own problem with this code:

m = GEKKO()
m.time = np.linspace(0,144,145)
# Upper temperature limit 
temp_u = np.concatenate((18*np.ones(32),22*np.ones(81),18*np.ones(32)))
# Lower temperature limit 
temp_l = np.concatenate((17.0*np.ones(42),21.0*np.ones(61),17.0*np.ones(42)))
T_low = m.Param(value=temp_l)
T_high = m.Param(value=temp_u)

#Manipulated variable
u = m.MV(value=0,lb=0,ub=100)
u.STATUS = 1

#Controlled variable
T = m.SV(value=18)

#Soft constraints
eH = m.CV(value=0)
eL = m.CV(value=0)

eH.SPHI=0; eH.WSPHI=10; eH.WSPLO=0  ; eH.STATUS = 1
eL.SPLO=0; eL.WSPHI=0  ; eL.WSPLO=10; eL.STATUS = 1

m.Equations([eH==T-T_high,eL==T-T_low])
#m.Equations([eH==T-T_high])
m.Equation(T.dt() == 02.05+0.029*u-0.003*T*u-0.001*(T**2))
m.Minimize(u)


m.options.IMODE = 6
m.solve(disp=True,debug=True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文