GEKKO中的非线性输入(操纵变量)

时间:2019-10-01 22:58:41

标签: python gekko

我有一个具有二次输入(操纵变量[MV])的非线性系统。为了使用GEKKO对这个系统进行MPC仿真,我定义了以下函数来处理二次输入:

def NTVin(T, u):
    n = T.shape[0]
    Tntv = zeros(n)
    u2 = zeros_like(u, dtype = float64)
    for i in range(len(u2)):
        u2[i] = copy(u[i].VALUE)
    for i in range(n):
        Tntv[i] = dot(dot(u2, T[i,:,:]), u2)

    return Tntv

然后我将系统方程式定义如下:

from pylab import*
dt = .02 # sec = 20ms
m = GEKKO(remote = True)
ntg = int(tf/dt) + 1
m.time = linspace(0., tf, ntg)
m.options.CV_TYPE = 2 # 2 = squared error
x = m.Array(m.SV, Nnew, value = 0.)
y = m.Array(m.CV, Mm, value = 0.)
unb = m.Array(m.MV, B.shape[1], lb = 5.e5, ub = 2.25e6)
untv = m.Array(m.MV, Bntv.shape[1], value = 0.)
tau_sp = 3.e-2
for i in range(Bntv.shape[1]):
    untv[i].value = ic[i]
    untv[i].STATUS = 1
for i in range(B.shape[1]):
    unb[i].value = 0.
    unb[i].STATUS = 1
    unb[i].DCOST = 0.
    unb[i].COST = 0.
for i in range(N):
    x[i].value = ans0[i]
for i in range(Nnew):
    m.Equation(x[i].dt() == dot(A[i,:], x) + Bint[i] + dot(B[i,:], unb) - dot(Mnew[i,:], NTVin(Bntv, untv)))
for i in range(Mm):
    m.Equation(y[i] == dot(Phim[i,:], x))
    y[i].value = dot(Phim[i,:], ans0)
    y[i].STATUS = 1
    y[i].TR_INIT = 1
    y[i].SP = omegaR0[i]
    y[i].TAU = tau_sp
m.options.IMODE = 6
m.options.NODES = 2
m.solve(disp = True, GUI = False)

模拟运行,但是GEKKO从未更改MV untv(无论为untv[i].value设置什么,在模拟中都保持该值),而线性MV unb在模拟,并且时间会有所不同。我怀疑应该责怪我的职能NTVin(特别是在行u2[i] = copy(u[i].VALUE中)。我的问题是,GEKKO是否可以处理非线性MV,如果可以,在声明系统方程式时是否有办法处理这种二次输入?

1 个答案:

答案 0 :(得分:3)

是的,Gekko和求解器(APOPT,BPOPT,IPOPT)可以求解非线性表达式。复制u2[i]值时,它是在创建数字值而不是Gekko变量。二次目标术语的一种想法是尝试使用本文档Model Building Functions中所述的预构建qobj函数。您也可以尝试State Space object并将m.options.CV_TYPE=2设置为二次目标。有连续或离散状态空间的选项。