访问互补不可行性、对偶不可行性和原始不可行性。

huangapple go评论67阅读模式
英文:

Access the complementarity infeasibility, dual infeasibility, and the primal infeasibility

问题

IPOPT如何在优化后访问互补不可行性、对偶不可行性和原始不可行性?是否需要使用回调函数来实现这一点,还是IPOPT本身已经具备相关功能?

英文:

how can I access the complementarity infeasibility, the dual infeasibility, and primal infeasibility after optimizing with Ipopt? Do I need to use a callback function for this or does IPOPT have a function for this?

答案1

得分: 1

你的另一个回答是正确的;你可以使用特定于求解器的回调来访问原始不可行性和对偶不可行性:

https://github.com/jump-dev/Ipopt.jl#solver-specific-callback

不支持访问互补不可行性。

Ipopt.jl v1.2.0添加了对此的支持:

julia> using JuMP

julia> import Ipopt

julia> model = Model(Ipopt.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Ipopt

julia> @variable(model, 0 <= x <= π)
x

julia> @NLobjective(model, Min, (x - cos(x))^2)

julia> function my_callback(
           alg_mod::Cint,
           iter_count::Cint,
           obj_value::Float64,
           inf_pr::Float64,
           inf_du::Float64,
           mu::Float64,
           d_norm::Float64,
           regularization_size::Float64,
           alpha_du::Float64,
           alpha_pr::Float64,
           ls_trials::Cint,
        )
           m, n = 0, 1
           x, z_L, z_U = zeros(n), zeros(n), zeros(n)
           g, lambda = zeros(m), zeros(m)
           scaled = false
           prob = unsafe_backend(model).inner
           Ipopt.GetIpoptCurrentIterate(prob, scaled, n, x, z_L, z_U, m, g, lambda)
           x_L_violation, x_U_violation = zeros(n), zeros(n)
           compl_x_L, compl_x_U, grad_lag_x = zeros(n), zeros(n), zeros(n)
           nlp_constraint_violation, compl_g = zeros(m), zeros(m)
           Ipopt.GetIpoptCurrentViolations(
               prob,
               scaled,
               n,
               x_L_violation,
               x_U_violation,
               compl_x_L,
               compl_x_U,
               grad_lag_x,
               m,
               nlp_constraint_violation,
               compl_g,
           )
           @show x
           @show z_L
           @show z_U
           @show x_L_violation
           @show x_U_violation
           @show compl_x_L
           @show compl_x_U
           @show grad_lag_x
           return false
       end
my_callback (generic function with 1 method)

julia> MOI.set(model, Ipopt.CallbackFunction(), my_callback)

julia> optimize!(model)
This is Ipopt version 3.14.4, running with linear solver MUMPS 5.4.1.

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

Total number of variables............................:        1
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        1
                     variables with only upper bounds:        0
Total number of equality constraints.................:        0
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

x = [0.00999999]
z_L = [1.0]
z_U = [1.0]
x_L_violation = [0.0]
x_U_violation = [0.0]
compl_x_L = [0.01]
compl_x_U = [3.13159269500572]
grad_lag_x = [-1.999698671463963]
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  9.8000102e-01 0.00e+00 2.00e+00  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0

Number of Iterations....: 0

(scaled)                 (unscaled)
Objective...............:   9.8000102332194250e-01    9.8000102332194250e-01
Dual infeasibility......:   1.9996986714639631e+00    1.9996986714639631e+00
Constraint violation....:   0.0000000000000000e+00    0.0000000000000000e+00
Variable bound violation:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   3.1315926950057200e+00    3.1315926950057200e+00
Overall NLP error.......:   3.1315926950057200e+00    3.1315926950057200e+00

Number of objective function evaluations             = 1
Number of objective gradient evaluations             = 1
Number of equality constraint evaluations            = 0
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 0
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 0
Total seconds in IPOPT                               = 0.064

EXIT: Stopping optimization at current point as requested by user.

有关详细信息,请参阅Ipopt文档:

https://coin-or.github.io/Ipopt/IpStdCInterface_8h.html#acf68350650b7a893061e110ab0e9264f
https://coin-or.github.io/Ipopt/IpStdCInterface_8h.html#ae505cff0e907b9049062f665dadd8be9

英文:

Your other answer is correct; you can access the primal and dual infeasibility using a solver-specific callback:

https://github.com/jump-dev/Ipopt.jl#solver-specific-callback

<s>There is no support for accessing the complementarity infeasibility.</s>

Ipopt.jl v1.2.0 adds support for this:

julia&gt; using JuMP

julia&gt; import Ipopt

julia&gt; model = Model(Ipopt.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Ipopt

julia&gt; @variable(model, 0 &lt;= x &lt;= π)
x

julia&gt; @NLobjective(model, Min, (x - cos(x))^2)

julia&gt; function my_callback(
           alg_mod::Cint,
           iter_count::Cint,
           obj_value::Float64,
           inf_pr::Float64,
           inf_du::Float64,
           mu::Float64,
           d_norm::Float64,
           regularization_size::Float64,
           alpha_du::Float64,
           alpha_pr::Float64,
           ls_trials::Cint,
        )
           m, n = 0, 1
           x, z_L, z_U = zeros(n), zeros(n), zeros(n)
           g, lambda = zeros(m), zeros(m)
           scaled = false
           prob = unsafe_backend(model).inner
           Ipopt.GetIpoptCurrentIterate(prob, scaled, n, x, z_L, z_U, m, g, lambda)
           x_L_violation, x_U_violation = zeros(n), zeros(n)
           compl_x_L, compl_x_U, grad_lag_x = zeros(n), zeros(n), zeros(n)
           nlp_constraint_violation, compl_g = zeros(m), zeros(m)
           Ipopt.GetIpoptCurrentViolations(
               prob,
               scaled,
               n,
               x_L_violation,
               x_U_violation,
               compl_x_L,
               compl_x_U,
               grad_lag_x,
               m,
               nlp_constraint_violation,
               compl_g,
           )
           @show x
           @show z_L
           @show z_U
           @show x_L_violation
           @show x_U_violation
           @show compl_x_L
           @show compl_x_U
           @show grad_lag_x
           return false
       end
my_callback (generic function with 1 method)

julia&gt; MOI.set(model, Ipopt.CallbackFunction(), my_callback)

julia&gt; optimize!(model)
This is Ipopt version 3.14.4, running with linear solver MUMPS 5.4.1.

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

Total number of variables............................:        1
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        1
                     variables with only upper bounds:        0
Total number of equality constraints.................:        0
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

x = [0.00999999]
z_L = [1.0]
z_U = [1.0]
x_L_violation = [0.0]
x_U_violation = [0.0]
compl_x_L = [0.01]
compl_x_U = [3.13159269500572]
grad_lag_x = [-1.999698671463963]
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  9.8000102e-01 0.00e+00 2.00e+00  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0

Number of Iterations....: 0

                                   (scaled)                 (unscaled)
Objective...............:   9.8000102332194250e-01    9.8000102332194250e-01
Dual infeasibility......:   1.9996986714639631e+00    1.9996986714639631e+00
Constraint violation....:   0.0000000000000000e+00    0.0000000000000000e+00
Variable bound violation:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   3.1315926950057200e+00    3.1315926950057200e+00
Overall NLP error.......:   3.1315926950057200e+00    3.1315926950057200e+00


Number of objective function evaluations             = 1
Number of objective gradient evaluations             = 1
Number of equality constraint evaluations            = 0
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 0
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 0
Total seconds in IPOPT                               = 0.064

EXIT: Stopping optimization at current point as requested by user.

See the Ipopt documentation for details:

答案2

得分: 0

看起来我可以从这个函数中获取原始不可行性(inf_pr)和对偶不可行性(inf_du),但互补不可行性呢?

英文:

Looks like I can get primal infeasibility (inf_pr) and dual infeasibility (inf_du) from this function,

 function my_callback(
alg_mod::Cint,
iter_count::Cint,
obj_value::Float64,
inf_pr::Float64,
inf_du::Float64,
mu::Float64,
d_norm::Float64,
regularization_size::Float64,
alpha_du::Float64,
alpha_pr::Float64,
ls_trials::Cint)
return true
end

but what about complementarity infeasibility?

huangapple
  • 本文由 发表于 2023年2月24日 00:20:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547527.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定