Multiscenario python returns same solution for each scenario
OngoingI ran the example https://www.gurobi.com/documentation/9.0/examples/multiscenario_py.html and the output is the same for each scenario:
| Plant |
Scenario | 0 1 2 3 4 | Costs Name
0 | x | 210500 Base model
1 | x | 210500 Increased warehouse demands
2 | x | 210500 Double the warehouse demands
3 | x | 210500 Decreased plant fixed costs
4 | x | 210500 Increased warehouse demands and decreased plant fixed costs
5 | x | 210500 Force plant with largest fixed cost to stay open
6 | x | 210500 Force plant with smallest fixed cost to be closed
Running:
for s in range(m.NumScenarios):
print("scenario: {}".format(s))
# set scenario number
m.Params.ScenarioNumber = s
print("scenario name: {}".format(m.ScenNName))
print("scenario objective value: {}".format(m.ScenNObjVal))
results in a changing scenario name. However, the value ScenNObjVal is not updated and remains the same for each s in m.NumScenarios.
How do I retrieve the objective values for different scenarios? Is the example on the Gurobi website incorrect?
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Olaf,
Is it possible that you are working on a Compute Server or Cloud? If yes, then you have to call the Model.update() function after setting the scenario to properly update the cached values, i.e.,
m.Params.ScenarioNumber = s
m.update()
# rest of the codeBest regards,
Jaromił0 -
Yes! Thanks a lot.
0 -
Please note that this behavior has been fixed for Gurobi 9.0.3 and adding the update() call is not necessary for that version.
0
Post is closed for comments.
Comments
4 comments