如何在Pyomo MindtPy求解器中修复整数值错误

问题描述 投票:0回答:1

我正在尝试解决MindtPy示例问题(https://pyomo.readthedocs.io/en/stable/contributed_packages/mindtpy.html),它不起作用。

这是我的代码:

from pyomo.environ import *

#Create a simple model
model = ConcreteModel()

model.x = Var(bounds=(1.0,10.0),initialize=5.0)
model.y = Var(within=Binary)

model.c1 = Constraint(expr=(model.x-3.0)**2 <= 50.0*(1-model.y))
model.c2 = Constraint(expr=model.x*log(model.x)+5.0 <= 50.0*(model.y))

model.objective = Objective(expr=model.x, sense=minimize)

#Solve the model using MindtPy
SolverFactory('mindtpy').solve(model, mip_solver='cplex', nlp_solver='ipopt',integer_tolerance=0.1,tee=True) 

model.objective.display()

model.display()

model.pprint()

这是输出:

INFO: ---Starting MindtPy---
INFO: Original model has 2 constraints (2 nonlinear) and 0 disjunctions, with
    2 variables, of which 1 are binary, 0 are integer, and 1 are continuous.
WARNING: DEPRECATED: The differentiate function in pyomo.core.base.symbolic
    has been deprecated. Please use the differentiate function in
    pyomo.core.expr.  (deprecated in TBD,will be removed in 5.7)
WARNING: DEPRECATED: The differentiate function in pyomo.core.base.symbolic
    has been deprecated. Please use the differentiate function in
    pyomo.core.expr.  (deprecated in TBD,will be removed in 5.7)
INFO: NLP 1: Solve relaxed integrality
INFO: NLP 1: OBJ: 1.0  LB: 1.0  UB: inf
INFO: ---MindtPy Master Iteration 0---
INFO: MIP 1: Solve master problem.
Traceback (most recent call last):

  File "<ipython-input-6-4da2d909ee40>", line 1, in <module>
    runfile('C:/Users/Desktop/untitled0.py', wdir='C:/Users/Desktop')

  File "C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Desktop/untitled0.py", line 22, in <module>
    SolverFactory('mindtpy').solve(model, mip_solver='cplex', nlp_solver='ipopt',integer_tolerance=0.1,tee=True)

  File "C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\pyomo\contrib\mindtpy\MindtPy.py", line 373, in solve
    MindtPy_iteration_loop(solve_data, config)

  File "C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\pyomo\contrib\mindtpy\iterate.py", line 30, in MindtPy_iteration_loop
    handle_master_mip_optimal(master_mip, solve_data, config)

  File "C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\pyomo\contrib\mindtpy\mip_solve.py", line 62, in handle_master_mip_optimal
    config)

  File "C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\pyomo\contrib\gdpopt\util.py", line 162, in copy_var_list_values
    v_to.set_value(value(v_from, exception=False))

  File "C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\pyomo\core\base\var.py", line 172, in set_value
    if valid or self._valid_value(val):

  File "C:\Users\AppData\Local\Continuum\anaconda3\lib\site-packages\pyomo\core\base\var.py", line 184, in _valid_value
    "domain %s" % (val, type(val), self.domain))

ValueError: Numeric value `0.22709088987977696` (<class 'float'>) is not in domain Binary

您可以看到整数公差已经高达0.1,这是非常高的。如果我将整数公差放在0.22709088987977696以上,它将解决,但这并没有真正的帮助。我也尝试使用GLPK作为LP解算器,但结果完全相同。我还没找到其他东西。

任何帮助将不胜感激。谢谢

python optimization pyomo nonlinear-optimization mixed-integer-programming
1个回答
0
投票

据报道,这是MindtPy中的错误。https://github.com/Pyomo/pyomo/issues/1187

问题在于,第一个主问题根本不涉及变量y,因此优化程序不会更新其值。请注意,这两个约束都是非线性的,并且由于某些原因似乎未添加OA切割。

© www.soinside.com 2019 - 2024. All rights reserved.