Reputation: 75
I'm just starting out with Pyomo. I tried to solve example problems from Pyomo Overview using CPLEX 12.8, Python 3.6 on Ubuntu 14.06.
# 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 ;
Running this
$ pyomo solve abstract1.py abstract1.dat --solver=cplex
, however, returns no solution. In fact, the model seems to have no constraints and no variables, and produces the following results.
# ==========================================================
# = 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
I have tried the ConcreteModel example, as well as abstract2.py, but still get the above results. Anyone have any idea what's happening, or where I can look into?
Upvotes: 1
Views: 980
Reputation: 75
I was pointed to this solution. It was a silly mistake, I had a space in the name of my working directory (e.g., 'two Words'). Getting rid of the space as should be standard practice for a developer (I'm not a developer by training) (e.g., 'twoWords') fixed this issue.
Upvotes: 1