Gekko求解器没有提供解决方案

问题描述

我正在尝试使用优化来解决天线匹配问题,在该问题中,我想最小化最终匹配阻抗的相位(通过pi匹配网络),例如Q> 100,阻抗= 50。

奇怪的是,仅当我对三个变量的初始猜测为50时,才给出解决方案。此外,当不等式约束为> 10而不是> 1 ...时,它会找到解决方案。我不明白这一点,因为如果> 10,则大于1。...

如果更改上限和下限,这也会影响求解器。在lb = -1000和ub = 1000的情况下,我得到x2 = 1000,x3 = -125.57,x4 = 22.53。但是,如果我将下限更改为-200(仍应允许-125.57解决方案),则求解器将找不到解决方案。

也许我设置不正确的优化问题?这是我的问题陈述: 目标函数:最小化Zin的虚部(用于共振) 不等式约束:服从Q>一些数 等式约束:且Zin的实部= 50

这是我编写的简单python脚本:

from gekko import GEKKO
m = GEKKO()
x2,x3,x4,= m.Array(m.Var,3,lb=-1000,ub=1000)  # upper and lower bounds for unkNowns
x2.value = 50; x3.value =50; x4.value =50; # initial guess

#equations
m.Equation((-9.84*x2**2*x4)/(96.786*(x2+x3)*(x2+x3+4)+(120.11*x3+x2*(120.11+x3))*(120.11*(x3+x4)+x2*(120.11+x3+x4)))  > 10) # inequality constraint
m.Equation((9.84*(x2**2)*(x4**2))/((9.84*(x2+x3+x4))**2+(120.11*(x2+x3+x4)+x2*(x3+x4))**2) ==50) #  equality constraint

#objective
m.Obj((x4*(96.79*(x2+x3)*(x2+x3+x4)+(120.109*x3+ x2*(120.11+x3))*(120.11*(x3+x4)+x2*(120.11+x3+x4))))/(96.9*(x2+x3+x4)**2+(120.11*(x3+x4)+x2*(120.11+x3+x4))**2))

#m.options.IMODE=3
m.options.soLVER=3

#Solve
#m.solve(disp=False)
m.solve()
print('x2 =',x2.value,'x3 =',x3.value,'x4 =',x4.value)

这是分析电路的原理图(jX1 == 0),

matching network

以及得出的方程式:

ReZinpi=(R1 X2^2 X4^2)/(R1^2 (X2 + X3 + X4)^2 + ((X3 + X4) XL + X2 (X3 + X4 + XL))^2) 

   ImZinpi = (X4 (R1^2 (X2 + X3) (X2 + X3 + X4) + 
              (X3 XL + X2 (X3 + XL)) ((X3 + X4) XL + X2 (X3 + X4 + XL))))
             /(R1^2 (X2 + X3 + X4)^2 + ((X3 + X4) XL + X2 (X3 + X4 + XL))^2) 

   Qpi= -((R1 X2^2 X4)/(R1^2 (X2 + X3) (X2 + X3 + X4) + 
          (X3 XL +  X2 (X3 + XL)) ((X3 + X4) XL + X2 (X3 + X4 + XL))))

这种方法是否可以优化pi匹配网络中的分量值,从而在达到高Q值的同时最大化匹配(最小化相位)?

解决方法

我无法验证您的方程式,但可以使您对问题的特征有所了解。看来您的问题是非常非线性的。 interior point algorithm可能会因边界不同而采取不同的路线。这是您的解决方案的等高线图,其中x2 = 1000可以将其缩小为变量x3和x4。

contour plot

有一个目标函数,不等式约束(> 10)为黑线,等式约束(= 50)为蓝线。分母中的变量可能会变小(接近零)。有时,这有助于将分母项与等式的另一边相乘,例如x/y==50x=y*50

from gekko import GEKKO
m = GEKKO(remote=False)
# upper and lower bounds for unknowns
x2,x3,x4 = m.Array(m.Var,3,lb=-1000,ub=1000)
x2.value = 50; x3.value =50; x4.value =50; # initial guess

#equations
m.Equation((-9.84*x2**2*x4)/(96.786*(x2+x3)*(x2+x3+4)+\
            (120.11*x3+x2*(120.11+x3))*(120.11*(x3+x4)+\
            x2*(120.11+x3+x4)))  > 10) # inequality constraint
m.Equation((9.84*(x2**2)*(x4**2))/((9.84*(x2+x3+x4))**2+\
            (120.11*(x2+x3+x4)+x2*(x3+x4))**2) ==50) #  equality constraint

#objective
m.Minimize((x4*(96.79*(x2+x3)*(x2+x3+x4)+(120.109*x3+ \
            x2*(120.11+x3))*(120.11*(x3+x4)+x2*\
            (120.11+x3+x4))))/(96.9*(x2+x3+x4)**2+\
            (120.11*(x3+x4)+x2*(120.11+x3+x4))**2))

#m.options.IMODE=3
m.options.SOLVER=3

#Solve
#m.solve(disp=False)
m.solve()
print('x2 =',x2.value,'x3 =',x3.value,'x4 =',x4.value)

# solution
x2_opt = 1000.0
x3_opt = -125.57474673
x4_opt = 22.537916773

## Generate a contour plot
import matplotlib
import numpy as np
import matplotlib.pyplot as plt

# Design variables at mesh points
x2 = x2_opt
x3 = np.arange(-150.0,-100.0,0.2)
x4 = np.arange(10,30,0.1)
x3,x4 = np.meshgrid(x3,x4)

# Equations and Constraints
eq1 = (-9.84*x2**2*x4)/(96.786*(x2+x3)*(x2+x3+4)+\
        (120.11*x3+x2*(120.11+x3))*(120.11*(x3+x4)+x2*(120.11+x3+x4)))
eq2 = (9.84*(x2**2)*(x4**2))/((9.84*(x2+x3+x4))**2+\
        (120.11*(x2+x3+x4)+x2*(x3+x4))**2)
obj = (x4*(96.79*(x2+x3)*(x2+x3+x4)+(120.109*x3+ x2*(120.11+x3))*\
        (120.11*(x3+x4)+x2*(120.11+x3+x4))))/(96.9*(x2+x3+x4)**2+\
        (120.11*(x3+x4)+x2*(120.11+x3+x4))**2)

# Create a contour plot
# Visit https://matplotlib.org/examples/pylab_examples/contour_demo.html
#   for more examples and options for contour plots
plt.figure()
# Objective contours
CS = plt.contour(x3,x4,obj)
plt.clabel(CS,inline=1,fontsize=10)
# eq1>10
CS = plt.contour(x3,eq1,[10.0,15.0,20.0],colors='k',linewidths=[2.0,0.5,0.5])
plt.clabel(CS,fontsize=10)
# eq2=50
CS = plt.contour(x3,eq2,[50],colors='b',linewidths=[4.0])
plt.clabel(CS,fontsize=10)

plt.plot(x3_opt,x4_opt,'.',color='orange',markersize=15)
# Add some labels
plt.xlabel('x3')
plt.ylabel('x4')
# Save the figure as a PNG
plt.savefig('contour_plot.png')

# Show the plots
plt.show()