Working with Pyomo 5.1.1 (CPython 2.7.10 on Windows 7), I'm trying to execute the easiest Pyomo example, the concrete model shown at https://software.sandia.gov/downloads/pub/pyomo/PyomoOnlineDocs.html#_a_simple_concrete_pyomo_model
from __future__ import division
from pyomo.environ import *
model = ConcreteModel()
model.x = Var([1,2], domain=NonNegativeReals)
model.OBJ = Objective(expr = 2*model.x[1] + 3*model.x[2])
model.Constraint1 = Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)
I execute:
> pyomo solve Pyomo_concrete_v1.py --solver=glpk
According to my own calculations, the results should be:
x[1]=0
x[2]=0.25
OBJ=0.75
However, I find the following 'results.yml':
# ----------------------------------------------------------
# Problem Information
# ----------------------------------------------------------
Problem:
- Name: unknown
Lower bound: 0.666666666667
Upper bound: 0.666666666667
Number of objectives: 1
Number of constraints: 2
Number of variables: 3
Number of nonzeros: 3
Sense: minimize
# ----------------------------------------------------------
# Solver Information
# ----------------------------------------------------------
Solver:
- Status: ok
Termination condition: optimal
Statistics:
Branch and bound:
Number of bounded subproblems: 0
Number of created subproblems: 0
Error rc: 0
Time: 0.018000125885
# ----------------------------------------------------------
# Solution Information
# ----------------------------------------------------------
Solution:
- number of solutions: 1
number of solutions displayed: 1
- Gap: 0.0
Status: feasible
Message: None
Objective:
OBJ:
Value: 0.666666666667
Variable:
x[1]:
Value: 0.333333333333
Constraint: No values
I do not understand why there are "2 constraints" (there is actually only one constraint), "3 variables" (actually, 2), and the results is a vector of size 1.
This 'results.yml' changes everytime I execute 'pyomo', but the contents are always the same.
This is due to a quirk in the LP file format. Specifically, some solvers do not allow constant terms in the objective. To work around this, Pyomo automatically adds a trivial variable (named ONE_VAR_CONSTANT
) and a constraint that forces it to 1 (literally, ONE_VAR_CONSTANT == 1
) to all models output in LP file format. This generally does not impact solver performance, as solvers have presolve steps that will remove the variable and constraint from the model before solving it.
Also, note that the results you are seeing in the summary are correct: the optimal solution to your model is:
x[1]=0.3333333
x[2]=0
OBJ=0.666666
and can be verified by substituting the answer into the constraint and objective (the constraint is active and satisfied, and the objective is lower than your hand-calculated value of 0.75).