Skip to content

Possible inconsistency in results object #1033

Open
@blnicho

Description

@blnicho

This question on StackOverflow led me to take a look at some of the information stored in the results object and I noticed a potential inconsistency. If I run the following knapsack model with different solvers:

from pyomo.environ import *

v = {'hammer':8, 'wrench':3, 'screwdriver':6, 'towel':11}
w = {'hammer':5, 'wrench':7, 'screwdriver':4, 'towel':3}

limit = 14

M = ConcreteModel()

M.ITEMS = Set(initialize=v.keys())

M.x = Var(M.ITEMS, within=Binary)

M.value = Objective(expr=sum(v[i]*M.x[i] for i in M.ITEMS), sense=maximize)

M.weight = Constraint(expr=sum(w[i]*M.x[i] for i in M.ITEMS) <= limit)

print('Solved using GLPK')
results = SolverFactory('glpk').solve(M)
print('Objective = ', value(M.value))
results.write()

print('\n\nSolved using Couenne')
results = SolverFactory('couenne').solve(M)
print('Objective = ', value(M.value))
results.write()

print('\n\nSolved using CBC')
results = SolverFactory('cbc').solve(M)
print('Objective = ', value(M.value))
results.write()

print('\n\nSolved using Bonmin')
results = SolverFactory('bonmin').solve(M)
print('Objective = ', value(M.value))
results.write()

they all get the same solution but report different numbers of constraints and variables in the results object:

Solved using GLPK
('Objective = ', 25.0)
# ==========================================================
# = Solver Results                                         =
# ==========================================================
# ----------------------------------------------------------
#   Problem Information
# ----------------------------------------------------------
Problem: 
- Name: unknown
  Lower bound: 25.0
  Upper bound: 25.0
  Number of objectives: 1
  Number of constraints: 2
  Number of variables: 5
  Number of nonzeros: 5
  Sense: maximize
# ----------------------------------------------------------
#   Solver Information
# ----------------------------------------------------------
Solver: 
- Status: ok
  Termination condition: optimal
  Statistics: 
    Branch and bound: 
      Number of bounded subproblems: 1
      Number of created subproblems: 1
  Error rc: 0
  Time: 0.0110940933228
# ----------------------------------------------------------
#   Solution Information
# ----------------------------------------------------------
Solution: 
- number of solutions: 0
  number of solutions displayed: 0


Solved using Couenne
('Objective = ', 25.0)
# ==========================================================
# = Solver Results                                         =
# ==========================================================
# ----------------------------------------------------------
#   Problem Information
# ----------------------------------------------------------
Problem: 
- Lower bound: -inf
  Upper bound: inf
  Number of objectives: 1
  Number of constraints: 0
  Number of variables: 4
  Sense: unknown
# ----------------------------------------------------------
#   Solver Information
# ----------------------------------------------------------
Solver: 
- Status: ok
  Message: couenne\x3a Optimal
  Termination condition: optimal
  Id: 3
  Error rc: 0
  Time: 0.0369369983673
# ----------------------------------------------------------
#   Solution Information
# ----------------------------------------------------------
Solution: 
- number of solutions: 0
  number of solutions displayed: 0


Solved using CBC
('Objective = ', 25.0)
# ==========================================================
# = Solver Results                                         =
# ==========================================================
# ----------------------------------------------------------
#   Problem Information
# ----------------------------------------------------------
Problem: 
- Name: unknown
  Lower bound: 25.0
  Upper bound: 25.0
  Number of objectives: 1
  Number of constraints: 1
  Number of variables: 4
  Number of binary variables: 4
  Number of integer variables: 4
  Number of nonzeros: 4
  Sense: maximize
# ----------------------------------------------------------
#   Solver Information
# ----------------------------------------------------------
Solver: 
- Status: ok
  User time: -1.0
  System time: 0.0
  Wallclock time: 0.01
  Termination condition: optimal
  Termination message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.
  Statistics: 
    Branch and bound: 
      Number of bounded subproblems: 0
      Number of created subproblems: 0
    Black box: 
      Number of iterations: 0
  Error rc: 0
  Time: 0.0510358810425
# ----------------------------------------------------------
#   Solution Information
# ----------------------------------------------------------
Solution: 
- number of solutions: 0
  number of solutions displayed: 0


Solved using Bonmin
('Objective = ', 25.0)
# ==========================================================
# = Solver Results                                         =
# ==========================================================
# ----------------------------------------------------------
#   Problem Information
# ----------------------------------------------------------
Problem: 
- Lower bound: -inf
  Upper bound: inf
  Number of objectives: 1
  Number of constraints: 0
  Number of variables: 4
  Sense: unknown
# ----------------------------------------------------------
#   Solver Information
# ----------------------------------------------------------
Solver: 
- Status: ok
  Message: bonmin\x3a Optimal
  Termination condition: optimal
  Id: 3
  Error rc: 0
  Time: 0.0704910755157
# ----------------------------------------------------------
#   Solution Information
# ----------------------------------------------------------
Solution: 
- number of solutions: 0
  number of solutions displayed: 0

I suspect this perceived inconsistency is caused by the preprocessing step in different solvers causing different problem sizes to be reported in the solution file but I was wondering if this is expected behavior and why the problem information is populated from the solution file instead of querying the Pyomo model directly. This seems to be causing confusion for users especially when they see Number of constraints: 0.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions