-
Notifications
You must be signed in to change notification settings - Fork 525
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
Labels
Comments
I think this is a good issue to link to the solver redesign PEP.
… On May 23, 2019, at 2:31 PM, Bethany Nicholson ***@***.***> 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 <#1033?email_source=notifications&email_token=AARTSZTD2H5IFME6SSB7ASDPW3WIRA5CNFSM4HPJTZ4KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GVRN7DA>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AARTSZXLPHPBPDW7RAH22SDPW3WIRANCNFSM4HPJTZ4A>.
|
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?
|
@blnicho - What is the status of this issue? Is it still a work in progress? |
Linking to #1030 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
they all get the same solution but report different numbers of constraints and variables in the results object:
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
.The text was updated successfully, but these errors were encountered: