Retrieving multiple optimal solutions for multiscenario in Python
AnsweredHi, I used below code to create 5 scenarios and I want to find 10 best solutions for each scenario, but I don't know how to retrieve all solutions for each scenario. I can only obtain 10 best solutions for the first scenario. Could you please let me know how to resolve it? Thank you!
# set parameters
m.setParam(GRB.Param.PoolSolutions, 10)
m.setParam(GRB.Param.PoolSearchMode, 2)
m.NumScenarios = 5
for i in range(5):
m.Params.ScenarioNumber = i
m.ScenNName = 'change = ' + str(5 - i)
changeConstr.ScenNRhs = 5 - i
# retrieve solutions
for i in range(m.SolCount):
m.setParam(GRB.Param.SolutionNumber, i)
m.update()
sol = (A.getAttr("xn"),B.getAttr("xn"),m.PoolObjVal)
0
-
Official comment
This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support. -
At present, obtaining n best solutions for each scenario in a multi-scenario model through solution pools is not supported.
0 -
Hi,
Not the best way, but maybe you can extract each scenario using m.SingleScenarioModel(), and then optimize all of them to retrieve all solutions for each scenario.
I am trying the below as well:
0
Post is closed for comments.
Comments
3 comments