如何从 pyomo 的 ipopt 接口中找到违反了哪个约束?

Posted

技术标签:

【中文标题】如何从 pyomo 的 ipopt 接口中找到违反了哪个约束?【英文标题】:How to find which constraint is violated from pyomo's ipopt interface? 【发布时间】:2017-11-17 09:59:54 【问题描述】:

我正在使用 pyomo 的 ipopt 求解器运行优化问题。我的问题有点复杂,IPOPT 将其声明为infeasible。除非需要,否则我不会发布整个问题。但是,需要注意的一点是,我为这个问题提供了一个温暖的开端,我认为这将有助于防止不可行性抬头。

当我在求解器中设置tee=True 时,这是pyomoipopt 的输出:

Ipopt 3.12.4: 

******************************************************************************
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.12.4, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation).

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

Total number of variables............................:       31
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:       29
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  0.0000000e+00 1.00e+01 1.00e+02  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
WARNING: Problem in step computation; switching to emergency mode.
   1r 0.0000000e+00 1.00e+01 9.99e+02   1.0 0.00e+00  20.0 0.00e+00 0.00e+00R  1
WARNING: Problem in step computation; switching to emergency mode.
Restoration phase is called at point that is almost feasible,
  with constraint violation 0.000000e+00. Abort.
Restoration phase in the restoration phase failed.

Number of Iterations....: 1

                                   (scaled)                 (unscaled)
Objective...............:   0.0000000000000000e+00    0.0000000000000000e+00
Dual infeasibility......:   9.9999999999999986e+01    6.0938999999999976e+02
Constraint violation....:   1.0000000000000000e+01    1.0000000000000000e+01
Complementarity.........:   0.0000000000000000e+00    0.0000000000000000e+00
Overall NLP error.......:   9.9999999999999986e+01    6.0938999999999976e+02


Number of objective function evaluations             = 2
Number of objective gradient evaluations             = 2
Number of equality constraint evaluations            = 2
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 2
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 2
Total CPU secs in IPOPT (w/o function evaluations)   =      0.008
Total CPU secs in NLP function evaluations           =      0.000

EXIT: Restoration Failed!


    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
 model, tee=True)
          4 

/Library/<path to solvers.pyc> in solve(self, *args, **kwds)
    616                         result,
    617                         select=self._select_index,
--> 618                         default_variable_value=self._default_variable_value)
    619                     result._smap_id = None
    620                     result.solution.clear()

/Library/Frameworks<path to>/PyomoModel.pyc in load_from(self, results, allow_consistent_values_for_fixed_vars, comparison_tolerance_for_fixed_vars, ignore_invalid_labels, id, delete_symbol_map, clear, default_variable_value, select, ignore_fixed_vars)
    239             else:
    240                raise ValueError("Cannot load a SolverResults object "
--> 241                                 "with bad status: %s" % str(results.solver.status))
    242         if clear:
    243             #

ValueError: Cannot load a SolverResults object with bad status: error

您实际上可以从上面输出的日志中看到,这一行只有 2 个约束评估:

Number of equality constraint evaluations            = 2

所以,它实际上很快就被宣布为不可行,所以我想不难找出违反了哪个约束。

如何找出违反了哪个约束?或者哪个约束使它不可行?

这是一个不同的问题,但仍然可以提供有关 IPOPT 的信息:IPOPT options for reducing constraint violation after fewer iterations

【问题讨论】:

我知道理论上可以使用对偶+分辨率定理+互补松弛来找出违反了哪个约束。 【参考方案1】:

在选项 print_level 设置为 8 的情况下运行 Ipopt 给我输出像

DenseVector "modified d_L scaled" with 1 elements:
modified d_L scaled[    1]= 2.4999999750000001e+01
DenseVector "modified d_U scaled" with 0 elements:
...
DenseVector "curr_c" with 1 elements:
curr_c[    1]= 7.1997853012817359e-08
DenseVector "curr_d" with 1 elements:
curr_d[    1]= 2.4999999473733212e+01
DenseVector "curr_d - curr_s" with 1 elements:
curr_d - curr_s[    1]=-2.8774855209690031e-07

curr_c 是等式约束的活动(在 Ipopt 内部被视为 c(x)=0),curr_d 是不等式约束的活动(在内部被视为 d_L

Ipopt 也返回包含约束活动的最后一次迭代,并且可能会传回 Pyomo,因此您可以将这些值与约束的左侧和右侧进行比较。

【讨论】:

以上是关于如何从 pyomo 的 ipopt 接口中找到违反了哪个约束?的主要内容,如果未能解决你的问题,请参考以下文章

PyOmo/Ipopt 因“无法评估 pow”而失败

在jupyter笔记本中的pyomo scriting

如何在 pyomo 中使用/选择/安装混合整数非线性求解器

多目标优化示例 Pyomo

Pyomo:使用 if 语句进行约束

PYOMO:如何创建约束松弛? (从 Pyomo 中的 CPLEX 重写约束)