Python 如何修复Pyomo MindtPy solver中的整数值错误

Python 如何修复Pyomo MindtPy solver中的整数值错误,python,optimization,pyomo,nonlinear-optimization,mixed-integer-programming,Python,Optimization,Pyomo,Nonlinear Optimization,Mixed Integer Programming,我正在尝试处理MindtPy示例问题(),但它不起作用 这是我的密码: 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-m

我正在尝试处理MindtPy示例问题(),但它不起作用

这是我的密码:

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()
从pyomo.environ导入*
#创建一个简单的模型
模型=混凝土模型()
model.x=Var(界限=(1.0,10.0),初始化=5.0)
model.y=Var(内部=二进制)

model.c1=Constraint(expr=(model.x-3.0)**2这已被报告为MindtPy中的一个bug。

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


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

,并在PR 1391后修复
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