Get real count of solutions
AnsweredI have a MIP model that was already solved to some extent with a time limit, and now I want to get exactly one more solution.
One way to produce one additional solution is to keep doing this from the beginning by incrementing model.Params.SolutionLimit one by one.
But in my situation I don't know how many solutions were produced up until now, so how I can I set a reasonable Params.SolutionLimit that is exactly one higher than the number of solutions until now?
Btw: model.SolCount does not help since that is capped by a certain limit (defaulting to 10)
-
Hi Johannes,
SolCount refers to the number of stored solutions, not the number of solutions found. The maximum number of solutions stored is dictated by PoolSolutions (default = 10). If you make PoolSolutions sufficiently large then number of stored solutions will be equal to the number of solutions found.
- Riley
1 -
Thanks Riley Clement!
But shouldn't there be an internal, hidden counter, that is used by gurobi to compare to SolutionLimit?
0 -
But shouldn't there be an internal, hidden counter
I'd expect so.
0 -
What's the reason for it not to be accessible/documented?
0 -
I can only guess (and that guess is that nobody has ever wanted it before), but I'll see if I can find out if there is another reason.
For your case I think the cleanest solution might be to avoid counting solutions altogether, and use a callback on your second solve to terminate as soon as a solution is found:
def cb(model, where):
if where == GRB.Callback.MIPSOL:
model.terminate()
m = gp.Model()
# define model
m.optimize() # first solve
...
m.optimize(cb) # one more solution- Riley
1 -
|| But shouldn't there be an internal, hidden counter
| I'd expect so.Actually after diving through the source code I don't believe such a counter exists. Only a count of saved solutions seems to be incremented (up to the PoolSolutions value) when a solution is found. I can propose it as a new feature to the dev team.
- Riley
0
Please sign in to leave a comment.
Comments
6 comments