简体   繁体   English

Gekko 错误:2 和 -13 显示未找到解决方案

[英]Gekko error: 2 and -13 showing no solution found

I am trying to use gekko for optimization, but I am getting error - 13 (If I use the commented equation (see below) and an error code 2 if I use different version of that equation).我正在尝试使用 gekko 进行优化,但出现错误 - 13(如果我使用注释方程(见下文),如果我使用该方程的不同版本,则会出现错误代码 2)。 Kindly guide how to solve this.请指导如何解决这个问题。 I am unable to get a solution.我无法得到解决方案。 I tried to add a lower bound, but still it is not working.我试图添加一个下限,但它仍然无法正常工作。 The two equations are same, one is with log y and other one is with y value.这两个方程是相同的,一个是 log y,另一个是 y value。

import numpy as np
from gekko import GEKKO
import pandas as pd
import matplotlib.pyplot as plt
import math

# Data points
xm = np.array([0.122, 0.276, 0.303, 0.356, 0.384, 0.444, 0.662 , 0.779, 0.867, 0.964 ,1.09, 1.17, 1.3, 1.33 ,1.41])
ym = np.array([0.00515, 0.00297, 0.00271, 0.00249, 0.00228, 0.00216, 0.0016, 0.00139, 0.0013, 0.00116, 0.00105, 0.00101, 0.000888, 0.000904, 0.000854])

# Define GEKKO model
# Parameters and variable

m = GEKKO(remote=False)
a= m.FV(lb=-4000.0,ub=-4000.0)
b= m.FV(lb=-4000.0,ub=-4000.0)


lower = 1e-4

x =m.Param(value=xm)
y_measure = m.Param(value =ym)
y_predict=m.Var(lb = lower)

# Parameters and variable options
# 1 = avaiable to optimizer to minimize objective
a.status = 1  
b.status = 1


# Equation


m.Equation(m.log(y_predict) == a + b * m.log (x))

#m.Equation(y_predict == m.exp(a + b * m.log (x)))

# Objective
           
m.Minimize(((y_predict-y_measure)/y_measure)**2)
# application options
m.options.IMODE = 2   # regression mode

# m.options.SOLVER=1

# solve
m.solve() # remote=False for local solve

# show final objective
print('Final SSE Objective: ' + str(m.options.objfcnval))

# print solution
print('Solution')
print('a = ' + str(a.value[0]))
print('b = ' + str(b.value[0]))

it looks like you accidentally made the upper bounds for the a and b coefficients -4000.看起来您不小心将 a 和 b 系数的上限设为 -4000。 By changing them to 4000, the solver now works for either prediction function.通过将它们更改为 4000,求解器现在适用于任一预测函数。

import numpy as np
from gekko import GEKKO
import pandas as pd
import matplotlib.pyplot as plt
import math

# Data points
xm = np.array([0.122, 0.276, 0.303, 0.356, 0.384, 0.444, 0.662 , 0.779, 0.867, 0.964 ,1.09, 1.17, 1.3, 1.33 ,1.41])
ym = np.array([0.00515, 0.00297, 0.00271, 0.00249, 0.00228, 0.00216, 0.0016, 0.00139, 0.0013, 0.00116, 0.00105, 0.00101, 0.000888, 0.000904, 0.000854])

# Define GEKKO model
# Parameters and variable

m = GEKKO(remote=False)
a= m.FV(lb=-4000.0,ub=4000.0)
b= m.FV(lb=-4000.0,ub=4000.0)


lower = 1e-4

x =m.Param(value=xm)
y_measure = m.Param(value =ym)
y_predict=m.Var(lb = lower)

# Parameters and variable options
# 1 = avaiable to optimizer to minimize objective
a.status = 1  
b.status = 1


# Equation


m.Equation(m.log(y_predict) == a + b * m.log (x))

#m.Equation(y_predict == m.exp(a + b * m.log (x)))

# Objective
           
m.Minimize(((y_predict-y_measure)/y_measure)**2)
# application options
m.options.IMODE = 2   # regression mode

# m.options.SOLVER=1

# solve
m.solve() # remote=False for local solve

# show final objective
print('Final SSE Objective: ' + str(m.options.objfcnval))

# print solution
print('Solution')
print('a = ' + str(a.value[0]))
print('b = ' + str(b.value[0]))
----------------------------------------------------------------
 APMonitor, Version 1.0.0
 APMonitor Optimization Suite
 ----------------------------------------------------------------
 
 
 --------- APM Model Size ------------
 Each time step contains
   Objects      :  0
   Constants    :  0
   Variables    :  5
   Intermediates:  0
   Connections  :  0
   Equations    :  2
   Residuals    :  2
 
 Number of state variables:    17
 Number of total equations: -  15
 Number of slack variables: -  0
 ---------------------------------------
 Degrees of freedom       :    2
 
 **********************************************
 Model Parameter Estimation with Interior Point Solver
 **********************************************
  
  
 Info: Exact Hessian

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************

This is Ipopt version 3.10.2, running with linear solver mumps.

Number of nonzeros in equality constraint Jacobian...:       45
Number of nonzeros in inequality constraint Jacobian.:        0
Number of nonzeros in Lagrangian Hessian.............:       18

Total number of variables............................:       17
                     variables with only lower bounds:       15
                variables with lower and upper bounds:        2
                     variables with only upper bounds:        0
Total number of equality constraints.................:       15
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0 7.0504855e+002 9.90e-001 8.09e+002   0.0 0.00e+000    -  0.00e+000 0.00e+000   0
   1 3.9209717e+001 4.16e-001 2.77e+002  -3.1 9.98e-001    -  9.90e-001 8.74e-001f  1
   2 3.6268661e+001 3.79e-001 2.52e+002  -5.1 9.95e-001    -  9.90e-001 9.31e-002h  1
   3 1.2792383e+001 1.39e-001 9.28e+001  -2.3 9.95e-001    -  1.00e+000 1.00e+000f  1
   4 1.2870911e+001 5.13e-002 3.41e+001  -4.2 9.86e-001    -  1.00e+000 1.00e+000h  1
   5 1.2255837e+001 1.89e-002 1.25e+001  -5.6 9.63e-001    -  1.00e+000 1.00e+000h  1
   6 1.0837548e+001 6.92e-003 4.58e+000  -6.9 9.08e-001    -  1.00e+000 1.00e+000h  1
   7 8.4929354e+000 2.52e-003 1.63e+000  -7.9 7.96e-001    -  1.00e+000 1.00e+000h  1
   8 6.2935389e+000 9.00e-004 3.10e+001 -11.0 6.27e-001    -  2.60e-001 1.00e+000h  1
   9 2.8727265e+000 1.70e-004 8.26e+001  -5.1 3.67e-001    -  1.32e-003 1.00e+000f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10 8.3643158e-001 1.24e-003 2.17e-001  -5.8 6.36e-001    -  1.00e+000 1.00e+000f  1
  11 2.2427664e-001 1.82e-003 2.02e-001  -5.8 4.50e-001    -  1.00e+000 1.00e+000f  1
  12 1.8136589e-002 3.88e-004 3.61e-002  -7.0 1.40e-001    -  1.00e+000 1.00e+000h  1
  13 1.0934780e-002 3.04e-005 2.25e-003  -8.8 4.72e-002    -  1.00e+000 1.00e+000h  1
  14 1.1280858e-002 1.81e-007 1.13e-005 -11.0 3.75e-003    -  1.00e+000 1.00e+000h  1
  15 1.1283202e-002 5.56e-012 3.14e-010 -11.0 2.07e-005    -  1.00e+000 1.00e+000h  1

Number of Iterations....: 15

                                   (scaled)                 (unscaled)
Objective...............:  5.4569096085891645e-004   1.1283201917622072e-002
Dual infeasibility......:  3.1361952979191013e-010   6.4846822354946330e-009
Constraint violation....:  5.5613083582706224e-012   5.5613083582706224e-012
Complementarity.........:  1.0000596947430242e-011   2.0678142529061207e-010
Overall NLP error.......:  3.1361952979191013e-010   6.4846822354946330e-009


Number of objective function evaluations             = 16
Number of objective gradient evaluations             = 16
Number of equality constraint evaluations            = 16
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 16
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 15
Total CPU secs in IPOPT (w/o function evaluations)   =      0.019
Total CPU secs in NLP function evaluations           =      0.003

EXIT: Optimal Solution Found.

 The solution was found.

 The final value of the objective function is  0.011283201917622072
 
 ---------------------------------------------------
 Solver         :  IPOPT (v3.12)
 Solution time  :  0.022600000000000002 sec
 Objective      :  0.011283201917622073
 Successful solution
 ---------------------------------------------------
 

Final SSE Objective: 0.011283201918
Solution
a = -6.7849216408
b = -0.74185760092
​```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不可行性,未找到解决方案 - Gekko 错误 - Infeasibilities, Solution Not Found - Gekko Error 如何修复 Python GEKKO 最优控制代码中的“Solution Not Found”错误 - How to Fix "Solution Not Found" Error in Python GEKKO Optimal Control Code 使用 gekko 进行优化时返回“@Error:未找到解决方案” - '@Error: Solution not found' being returned when using gekko for optimization 使用 Gekko 的最优控制问题:“未找到解决方案” - Optimal control problem using Gekko: “Solution Not Found” Gekko错误“未找到结果文件。 APM没有找到解决方案或服务器无法访问“ - Gekko error “ Results files not found. APM did not find a solution or the server is unreachable” 在更改参数、目标 function 和初始条件时使用 Gekko 优化套件出现“未找到解决方案”错误 - “Solution Not Found” error using Gekko optimization suite when changing parameters, objective function, and initial condition GEKKO - 超时错误 - ImportError: No solution or server unreachable - GEKKO - timeout error - ImportError: No solution or server unreachable Gekko:获得的解决方案有问题 - Gekko: Problem with the obtained solution Gekko 求解器不提供任何解决方案 - Gekko solver offers no solution Gekko:MINLP - 错误 options.json 文件未找到 - Gekko: MINLP - Error options.json file not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM