Skip to main content

Get real count of solutions

Answered

Comments

6 comments

  • Riley Clement
    • Gurobi Staff

    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
  • Johannes Kager
    • Gurobi-versary
    • First Comment
    • First Question

    Thanks Riley Clement!

    But shouldn't there be an internal, hidden counter, that is used by gurobi to compare to SolutionLimit?

    0
  • Riley Clement
    • Gurobi Staff
    But shouldn't there be an internal, hidden counter

    I'd expect so.

    0
  • Johannes Kager
    • Gurobi-versary
    • First Comment
    • First Question

    What's the reason for it not to be accessible/documented?

    0
  • Riley Clement
    • Gurobi Staff

    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
  • Riley Clement
    • Gurobi Staff
    || 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.