Get multiple solutions
AnsweredHey we are using Gurobi to solve IP/MIP problems with trivial objective function and a number of constraints.
We want to check whether the Gurobi API exists for the following scenarios:
A) Validate and return only one solution that satisfies the constraints (thus it is the best),
or
B) Validate and return more than one solution (and the solver returns the best one).
How can we do this by using gurobi?
We have tried setting up parameters Solution Pool (the link we refer to: https://www.gurobi.com/documentation/9.5/refman/finding_multiple_solutions.html ).
For scenario B, we just get exactly duplicates of the same solution by setting up PoolSolutions parameter to some number larger than 1. What should we do to avoid the model producing repeated solutions?
-
Hi Yifeng,
A) Validate and return only one solution that satisfies the constraints (thus it is the best),
If you want only exactly 1 solution without caring about its quality, you can use the SolutionLimit parameter.
If you want the best overall solution, you have to set the MIPGap value to 0. Please note that this might result in a very long runtime.B) Validate and return more than one solution (and the solver returns the best one).
How can we do this by using gurobi?Please refer to the Knowledge Base article How do I find additional solutions to a model?
We have tried setting up parameters Solution Pool (the link we refer to: https://www.gurobi.com/documentation/9.5/refman/finding_multiple_solutions.html ).
Using the solution pool is the correct way to approach this. You can set the PoolSearchMode parameter which controls what kind of solutions you are interested in and then the number of PoolSolutions.
For scenario B, we just get exactly duplicates of the same solution by setting up PoolSolutions parameter to some number larger than 1. What should we do to avoid the model producing repeated solutions?
What exactly do you mean by duplicates? Do you mean that the objective value is the same but the solution point values are different? This would then not be a duplicate but an alternative optimal solution. There indeed was an issue with duplicate solution in a previous Gurobi version so if possible please update to the latest version 10.0.2.
Best regards,
Jaromił0 -
Hi Jaromił,
Thanks for your quick reply! I am wondering if I could apply Gurobi API to achieve the following requirement:
(1) I set up PoolSolutions to 10000.
(2) Instead of using model.optimize() which returns all 10000 solutions all at once, I am applying some other API function to allow the model to output 10000 different feasible solutions one by one.
Best,
Yifeng0 -
Hi Yifeng,
You could use the MIPSOL callback to access each found solution one by one during the optimization process (see callback.py for an example). Once you are satisfied with the solutions, you can prematurely terminate the optimization process from within the callback via the terminate method.
Best regards,
Jaromił0
Please sign in to leave a comment.
Comments
3 comments