Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible inconsistency in results object #1033

Open
blnicho opened this issue May 23, 2019 · 4 comments
Open

Possible inconsistency in results object #1033

blnicho opened this issue May 23, 2019 · 4 comments

Comments

@blnicho
Copy link
Member

blnicho commented May 23, 2019

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.

@ghackebeil
Copy link
Member

ghackebeil commented May 23, 2019 via email

@carldlaird
Copy link
Member

carldlaird commented May 24, 2019 via email

@mrmundt
Copy link
Contributor

mrmundt commented Apr 12, 2021

@blnicho - What is the status of this issue? Is it still a work in progress?

@mrmundt
Copy link
Contributor

mrmundt commented Apr 14, 2021

Linking to #1030

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants