我刚开始与Pyomo开始。我试图在Ubuntu 14.06上使用CPLEX 12.8,Python 3.6解决Pyomo Overview中的示例问题。
# abstract1.py
from __future__ import division
from pyomo.environ import *
model = AbstractModel()
model.m = Param(within=NonNegativeIntegers)
model.n = Param(within=NonNegativeIntegers)
model.I = RangeSet(1, model.m)
model.J = RangeSet(1, model.n)
model.a = Param(model.I, model.J)
model.b = Param(model.I)
model.c = Param(model.J)
# the next line declares a variable indexed by the set J
model.x = Var(model.J, domain=NonNegativeReals)
def obj_expression(model):
return summation(model.c, model.x)
model.OBJ = Objective(rule=obj_expression)
def ax_constraint_rule(model, i):
# return the expression for the constraint for i
return sum(model.a[i,j] * model.x[j] for j in model.J) >= model.b[i]
# the next line creates one constraint for each member of the set model.I
model.AxbConstraint = Constraint(model.I, rule=ax_constraint_rule)
# abstract1.dat
param m := 1 ;
param n := 2 ;
param a :=
1 1 3
1 2 4
;
param c:=
1 2
2 3
;
param b := 1 1 ;
运行此
$ pyomo solve abstract1.py abstract1.dat --solver=cplex
但是,没有解决方案。事实上,该模型似乎没有约束,也没有变量,并产生以下结果。
# ==========================================================
# = Solver Results =
# ==========================================================
# ----------------------------------------------------------
# Problem Information
# ----------------------------------------------------------
Problem:
- Lower bound: -inf
Upper bound: inf
Number of objectives: 1
Number of constraints: 0
Number of variables: None
Number of nonzeros: None
Sense: unknown
# ----------------------------------------------------------
# Solver Information
# ----------------------------------------------------------
Solver:
- Status: ok
Termination condition: unknown
Error rc: 0
Time: 0.01150965690612793
我已尝试过ConcreteModel示例以及abstract2.py,但仍然可以获得上述结果。任何人都知道发生了什么,或者我可以在哪里研究?
答案 0 :(得分:1)
我被指向this solution。这是一个愚蠢的错误,我的工作目录名称中有一个空格(例如,'两个字')。摆脱空间应该是开发人员的标准做法(我不是通过培训的开发人员)(例如,'twoWords')解决了这个问题。