Pyomo Ipopt不会返回解决方案

Pau*_*eau 2 ipopt pyomo

我的脚本是:

    from __future__ import division
    import numpy
    import scipy
    from pyomo.environ import *
    from pyomo.dae import *
    from pyomo.opt import SolverFactory
    m=ConcreteModel()

    m.x3=Var(within=NonNegativeReals)
    m.u=Var(within=NonNegativeReals)


   def _con(m):
     return m.x3 >=3 
   m.con=Constraint(rule=_con)

   def _con2(m):
      return 4 >= m.u >=1 
   m.con2=Constraint(rule=_con2)

   m.obj=Objective(expr=m.x3*m.u)
   opt = SolverFactory("Ipopt", executable = "/Ipopt-3.12.6/bin/ipopt")
   results = opt.solve(m)
   results.write()
Run Code Online (Sandbox Code Playgroud)

虽然这是一个非常简单的问题,虽然程序声明已找到最佳解决方案,但解决方案的数量为0并且没有显示任何解决方案.

有任何想法吗??

非常感谢.

Gab*_*eil 5

在Pyomo的最新版本中,默认情况下将解决方案加载到模型中.结果对象应该用于检查状态信息.如果要查询解决方案,可以通过直接访问模型组件并检查其值来执行此操作,或者您可以执行以下操作:

m.solutions.store_to(results)
results.write()
Run Code Online (Sandbox Code Playgroud)