【问题标题】:Pyomo (using couenne) cannot optimize powers >= 3Pyomo(使用 couenne)无法优化幂 >= 3
【发布时间】:2018-08-02 19:31:49
【问题描述】:

我有一个 MINLP 问题要解决,当我尝试优化它时,couenne 崩溃了。我设法在仍然崩溃的同时显着减少它并找到了可能的罪魁祸首。

简化的问题目标函数是一个交替多项式x[n] - x[n-1] + x[n-2] - ...。有一个变量数组x[k], k=n..1,其中索引表示 x 的指数。还有一个限制数组强制执行这种求幂。

对于大于 2 的幂:

  • 如果我直接对 x[k] = x[1]**k 求幂,就会出现 couenne crastses。
  • 如果我级联指数x[k] = x[k-1]*x[1],couenne 正常求解。

所以我的问题是:从求解器的角度来看有什么区别?这种失败是意料之中的吗?我应该用另一个依赖重新编译couenne吗?

  • 我的环境是 Ubuntu 18.04。
  • 我正在使用通过 conda 安装的 Pyomo 5.5(Linux 4.15.0-29-generic 上的 CPython 3.6.5)。
  • 我自己使用默认标志编译了 couenne,并下载了以下依赖项(第三方,全部使用存储库提供的 wget 脚本下载):ASL、Blas、Lapack、Metis 和 Mumps。我没有下载 HSL、SCIP 和 SoPlex。

这里是测试代码:

#! /usr/bin/env python3

import pyomo.environ
import pyomo.core as pc
from pyomo.opt import SolverFactory

def run(max_pow, cascade):
  model = pc.ConcreteModel()
  model.s = pc.RangeSet(1, max_pow)
  model.x = pc.Var(model.s, bounds=(-1,1))

  model.s_rest = pc.Set(initialize=list(ii for ii in model.s)[1:])

  ## TWO DIFFERENT WAYS OF COMPUTING POWERS ##
  if cascade: # x[k] = x[k-1]*x[1]
    model.x_c = pc.Constraint(model.s_rest, rule=lambda m, s: m.x[s] == m.x[1]*m.x[s-1])
  else:       # x[k] = x[1]**k
    model.x_c = pc.Constraint(model.s_rest, rule=lambda m, s: m.x[s] == m.x[1]**s)

  # Alternating objective function: x[k] - x[k-1] + x[k-2] - ....
  def obj(x, s, pos=True):
    result = x[s]
    if s > 1:
      result = result + obj(x, s-1, not pos)
    if not pos:
      result = -result
    return result

  model.objective = pc.Objective(rule=lambda m: obj(m.x, max_pow), sense=pc.maximize)

  opt = SolverFactory("couenne")
  results = opt.solve(model)

  model.display()

# Test 3 different cases
for max_pow, cascade in [(2, False,), (3, False,), (3, True)]:
  print("\nDegree: {}, cascade: {}".format(max_pow, cascade))
  print("-"*25)
  try:
    run(max_pow, cascade)
  except Exception as e:
    print(e)

结果如下:

Degree: 2, cascade: False
-------------------------
Model unknown

  Variables:
    x : Size=2, Index=s
        Key : Lower : Value : Upper : Fixed : Stale : Domain
          1 :    -1 :  -1.0 :     1 : False : False :  Reals
          2 :    -1 :   1.0 :     1 : False : False :  Reals

  Objectives:
    objective : Size=1, Index=None, Active=True
        Key  : Active : Value
        None :   True :   2.0

  Constraints:
    x_c : Size=1
        Key : Lower : Body : Upper
          2 :   0.0 :  0.0 :   0.0

Degree: 3, cascade: False
-------------------------
ERROR: Solver (asl) returned non-zero return code (-11)
ERROR: Solver log: Couenne 0.5 -- an Open-Source solver for Mixed Integer
    Nonlinear Optimization Mailing list: couenne@list.coin-or.org
    Instructions: http://www.coin-or.org/Couenne couenne:
Solver (asl) did not exit normally

Degree: 3, cascade: True
-------------------------
Model unknown

  Variables:
    x : Size=3, Index=s
        Key : Lower : Value                  : Upper : Fixed : Stale : Domain
          1 :    -1 :  -0.002154434679988468 :     1 : False : False :  Reals
          2 :    -1 :  4.641588790337013e-06 :     1 : False : False :  Reals
          3 :    -1 : -9.999999860147783e-09 :     1 : False : False :  Reals

  Objectives:
    objective : Size=1, Index=None, Active=True
        Key  : Active : Value
        None :   True : 0.002149783091198271

  Constraints:
    x_c : Size=2
        Key : Lower : Body : Upper
          2 :   0.0 :  0.0 :   0.0
          3 :   0.0 :  0.0 :   0.0

【问题讨论】:

    标签: python-3.x pyomo


    【解决方案1】:

    Pyomo 倾向于将模型完全按照您制定的方式发送给求解器,除非您应用一些高级转换(如 GDP 或 DAE)。

    对于许多求解器,x * x * x 形式的表达式的处理方式与 x ** 3 不同。在某些系统中,甚至x ** 2pow(x, 2)sqr(x) 都会给您不同的行为。虽然在数学上是等效的,但对边界行为和域限制的处理可能会有所不同。

    【讨论】:

    • @jabozzo 这个提示解决了你的问题吗?只是好奇...
    猜你喜欢
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 2018-03-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多