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

时间:2019-11-21 17:31:55

标签: python optimization pyomo nonlinear-optimization mixed-integer-programming

我正在尝试解决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解算器,但结果完全相同。我还没找到其他东西。

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

2 个答案:

答案 0 :(得分:1)

此问题已解决,是Pyomo当前版本的一部分。该问题已在PR 1500中解决,并于2020年6月30日在提交a1f7c4ca85e058dbf1ee66c0425f4b9ee4b41ecb上添加到Pyomo代码库中。当时的版本是5.7

答案 1 :(得分:0)

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

  

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