Forum Discussion

FICO's avatar
FICO
Community Manager
1 year ago

Is it possible to count all possible Solutions of a Problem?

I wondered wether its possible to either get the number of all possible solutions of a problem or to actually block a solution after an optimization (in my case its minimize an IP) is done to search in the next iteration for another solution?

3 Replies

  • FICO's avatar
    FICO
    Community Manager

    In principle, it is possible to enumerate "all" solutions of a problem. How to do this with Xpress is described in the manual here.

    However, there are some caveats:

    • You can only enumerate different integer solutions and even that only makes sense if all variables are bounded. Consider for example the problem "min x, x >= 0, no further restrictions". Any positive real number is a solution, so there are infinitely many solutions. Even if x is required to be integer, there are infinitely many solutions.
    • Even if all variables are bounded, there may be a lot of solutions, so enumeration may take time.
    • If you have integer and continuous variables in your model then enumeration is only on integer variables. If two solutions differ only in the continuous variables they will be considered equal with respect to enumeration by Xpress.

    If you want to avoid a particular solution to be found (again) then you can add a (no good) constraint that explicitly forbids that solution: Assume your problem is all binary and has N binary variables x. Also suppose you want to forbid the solution represented by s. Then the constraint

    sum(i in N with s == 1) x + sum(i in N with s == 0) (1 - x) < N

    forbids exactly that solution.

    If you only want to find solutions that are better than a certain value then you can add a constraint that requires the objective value to be better than that value. However, having a constraint that is parallel to the objective function can hurt numerics and it may be better to use the MIPABSCUTOFF control. This has the same effect without explicitly introducing that constraint.

    Note however that as soon as Xpress finds a feasible solution, it automatically sets the cutoff so that only better solutions are found. So doing repeated solves will by default only find better solutions.

  • FICO's avatar
    FICO
    Community Manager

    All right, thank you for the quick and detailed response. I appreciate the new insights into the solution finding process very much. I guess that leads to the conclusion, that it is not really implementable in my case (at least in a non tedious and non laborious way) since the explicitly forbidding 'method' seems to be the only way to get the job done. 

    Perhaps it was not quite thought through to think there could be something like a 'block()' method to just iterate through until no more new solution is found.

    Again, thanks for the effort.

  • FICO's avatar
    FICO
    Community Manager

    There may be something else you can do: You could use a preintsol callback to just reject any solution Xpress finds and also inject a no-good cut for that solution to avoid finding it again.

    With this strategy you would have to collect the solutions yourself (because Xpress would never see a feasible solution) and you may not get all solutions to your problem.

    But maybe the set of solutions you get is still good enough in this case?