微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么代码会以“找不到解决方案”错误和“退出:收敛到局部不可行的点问题可能不可行”而终止?

如何解决为什么代码会以“找不到解决方案”错误和“退出:收敛到局部不可行的点问题可能不可行”而终止?

我似乎无法弄清楚为什么 IPOPT 找不到解决方案。最初,我认为这个问题是完全不可行的,但是当我将 col_total 的值减少到 161000 以下的任何数字或注释掉最后一个约束方程包含 col_total,它使用 Optimal Solution Found and a final objective value function of -161775.256826753 求解和退出。我已经使用 Artificial Bee ColonyParticle Swamp Optimization 技术解决了相同的最大化问题,它们分别解决并返回了至少 225000226000 的最优目标值函数.可能需要另一个求解器吗?我还尝试了 APOPTBPOPTIPOPT修改了容差值,但目前还没有任何组合似乎有效。代码贴在下面。任何指导将不胜感激。

from gekko import GEKKO  
import numpy as np  

distances = np.array([[[0,0],[0,0]],\
                      [[155,\
                      [[310,[155,\
                      [[465,[310,\
                      [[620,[465,0]]])

        
alpha = 0.5 / np.log(30/0.075)  
diam = 31  
free = 7  
rho = 1.2253  
area = np.pi * (diam / 2)**2  
min_v = 5.5  
axi_max = 0.32485226746  
col_total = 176542.96546512868    
rat = 14  
nn = 5
u_hub_lowerbound = 5.777777777777778
c_pow = 0.59230249
p_max = 0.5 * rho * area * c_pow * free**3 

# Initialize Model  
m = GEKKO(remote=True)  
#initialize variables,Set lower and upper bounds  
x = [m.Var(value = 0.03902278,lb = 0,ub = axi_max) \
     for i in range(nn)]  

# i = 0  
b = 1  
c = 0  
v_s = list()  
for i in range(nn-1):       # Loop runs for nn-1 times  
        # print(i)
        # print(i,b,c)
        squared_defs = list()  
        while i < b:  

                d = distances[b][c][0]  
                r = distances[b][c][1]  
                ss = (2 * (alpha * d) / diam)  
                tt = r / ((diam/2) + (alpha * d))
                squared_defs.append((2 * x[i] / (1 + ss**2)) * np.exp(-(tt**2)) ** 2)  

                i+=1  
                c+=1  

        #Equations  
        m.Equation((free * (1 - (sum(squared_defs))**0.5)) - rat <= 0)
        m.Equation((free * (1 - (sum(squared_defs))**0.5)) - u_hub_lowerbound >= 0)  
        v_s.append(free * (1 - (sum(squared_defs))**0.5))  
        squared_defs.clear()  
        b+=1   
        c=0  


# Inserts free as the first item on the v_s list to 
# increase len(v_s) to nn,so that 'v_s' and 'x' 
# are of same length  
v_s.insert(0,free)                 
 
gamma = list()  
for i in range(len(x)):  

        bet = (4*x[i]*((1-x[i])**2) * rho * area) / 2 
        gam = bet * v_s[i]**3
        gamma.append(gam)
        #Equations
        m.Equation(x[i] - axi_max <= 0)  
        m.Equation((((4*x[i]*((1-x[i])**2) * rho * area) / 2) \
                    * v_s[i]**3) - p_max <= 0)  
        m.Equation((((4*x[i]*((1-x[i])**2) * rho * area) / 2) * \
                      v_s[i]**3) > 0)
          

#Equation  
m.Equation(col_total - sum(gamma) <= 0)  

#Objective  
y = sum(gamma)  
m.Maximize(y)  # Maximize  

#Set global options  
m.options.IMODE = 3 #steady state optimization  
#Solve simulation  
m.options.soLVER = 3
m.solver_options = ['linear_solver ma27','mu_strategy adaptive','max_iter 2500','tol 1.0e-5' ]  
m.solve()      

解决方法

在表达式中构建没有 .value 的方程。 x[i].value 仅在解完成后查看解或初始化x[i] 的值时才需要。表达式 m.Maximize(y)m.Obj(-y) 更易读,尽管它们是等价的。

from gekko import GEKKO  
import numpy as np  

distances = np.array([[[0,0],[0,0]],\
                      [[155,\
                      [[310,[155,\
                      [[465,[310,\
                      [[620,[465,0]]])  
        
alpha = 0.5 / np.log(30/0.075)  
diam = 31  
free = 7  
rho = 1.2253  
area = np.pi * (diam / 2)**2  
min_v = 5.5  
axi_max = 0.069262150781  
col_total = 20000  
p_max = 4000  
rat = 14  
nn = 5  

# Initialize Model  
m = GEKKO(remote=True)  
#initialize variables,Set lower and upper bounds  
x = [m.Var(value = 0.03902278,lb = 0,ub = axi_max) \
     for i in range(nn)]  

i = 0  
b = 1  
c = 0  
v_s = list()  
for turbs in range(nn-1):       # Loop runs for nn-1 times  
    squared_defs = list()  
    while i < b:  
        d = distances[b][c][0]  
        r = distances[b][c][1]  
        ss = (2 * (alpha * d) / diam)  
        tt = r / ((diam/2) + (alpha * d))  
        squared_defs.append((2 * x[i] / (1 + ss**2)) \
                            * m.exp(-(tt**2)) ** 2)  

        i+=1  
        c+=1  

    #Equations  
    m.Equation((free * (1 - (sum(squared_defs))**0.5)) - rat <= 0)
    m.Equation(min_v - (free * (1 - (sum(squared_defs))**0.5)) <= 0 )  
    v_s.append(free * (1 - (sum(squared_defs))**0.5))  
    squared_defs.clear()  
    b+=1  
    a=0  
    c=0  

# Inserts free as the first item on the v_s list to
#   increase len(v_s) to nn,so that 'v_s' and 'x'
#   are of same length  
v_s.insert(0,free)                 
beta = list()  
gamma = list()  
for i in range(len(x)):  
    bet = (4*x[i]*((1-x[i])**2) * rho * area) / 2 
    gam = bet * v_s[i]**3
    #Equations  
    m.Equation((((4*x[i]*((1-x[i])**2) * rho * area) / 2) \
                * v_s[i]**3) - p_max <= 0)  
    m.Equation((((4*x[i]*((1-x[i])**2) * rho * area) / 2) \
                * v_s[i]**3) > 0)
    gamma.append(gam)  

#Equation  
m.Equation(col_total - sum(gamma) <= 0)  

#Objective  
y = sum(gamma)  
m.Maximize(y)  # Maximize  

#Set global options  
m.options.IMODE = 3 #steady state optimization  
#Solve simulation  
m.options.SOLVER = 3  
m.solve()   

这给出了一个具有最大化目标 20,000 的成功解决方案:

Number of Iterations....: 12

                                   (scaled)                 (unscaled)
Objective...............:  -4.7394814741924645e+00   -1.9999999999929641e+04
Dual infeasibility......:   4.4698510326511536e-07    1.8862194343304290e-03
Constraint violation....:   3.8275766582203308e-11    1.2941979026166479e-07
Complementarity.........:   2.1543608536533588e-09    9.0911246952931704e-06
Overall NLP error.......:   4.6245685940749926e-10    1.8862194343304290e-03


Number of objective function evaluations             = 80
Number of objective gradient evaluations             = 13
Number of equality constraint evaluations            = 80
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 13
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 12
Total CPU secs in IPOPT (w/o function evaluations)   =      0.010
Total CPU secs in NLP function evaluations           =      0.011

EXIT: Optimal Solution Found.
 
 The solution was found.
 
 The final value of the objective function is   -19999.9999999296     
 
 ---------------------------------------------------
 Solver         :  IPOPT (v3.12)
 Solution time  :   3.210000000399305E-002 sec
 Objective      :   -19999.9999999296     
 Successful solution
 ---------------------------------------------------

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。