pyomo icon indicating copy to clipboard operation
pyomo copied to clipboard

Possible inconsistency in results object

Open blnicho opened this issue 6 years ago • 5 comments

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.

blnicho avatar May 23 '19 19:05 blnicho

I think this is a good issue to link to the solver redesign PEP.

On May 23, 2019, at 2:31 PM, Bethany Nicholson [email protected] wrote:

This question https://stackoverflow.com/questions/56262241/pyomo-not-building-model-correctly?noredirect=1#comment99148060_56262241 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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Pyomo/pyomo/issues/1033?email_source=notifications&email_token=AARTSZTD2H5IFME6SSB7ASDPW3WIRA5CNFSM4HPJTZ4KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GVRN7DA, or mute the thread https://github.com/notifications/unsubscribe-auth/AARTSZXLPHPBPDW7RAH22SDPW3WIRANCNFSM4HPJTZ4A.

ghackebeil avatar May 23 '19 19:05 ghackebeil

I suspect that this is because we add a dummy variable for the objective for one solver, but this is not required for the other?

carldlaird avatar May 24 '19 14:05 carldlaird

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

mrmundt avatar Apr 12 '21 15:04 mrmundt

Linking to #1030

mrmundt avatar Apr 14 '21 17:04 mrmundt

BWOM: We looked at this issue during the dev call on 1/21/2025 and this will get resolved with the redesign of the results object as part of the solver redesign effort

blnicho avatar Jan 21 '25 20:01 blnicho