当我尝试优化它时,我有一个MINLP问题要解决并且couenne崩溃了 . 我设法在崩溃的同时显着减少它,并找到了可能的罪魁祸首 .
减少问题的目标函数是交替的polinomial 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) .
-
我've compiled couenne myself using the default flags and downloading the following dependencies (ThirdParties, all downloaded using the wget script provided by the repository): ASL, Blas, Lapack, Metis and Mumps. I didn' t下载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
1 回答
除非你应用一些高级转换(如GDP或DAE),否则Pyomo倾向于将模型完全按照你的公式发送给解算器 .
对于许多求解器,
x * x * x
形式的表达式与x ** 3
的处理方式不同 . 在某些系统中,即使x ** 2
,pow(x, 2)
和sqr(x)
也会给您不同的行为 . 虽然在数学上是等价的,但是边界行为和域限制的处理可能不同 .