Dynamically increasing lower bound in CP-SAT from Google's OR tools

120 views Asked by At

I was wondering if there was a way to dynamically increasing the lower-bound of a variable in the on_solution_callback(self) method?

This was just one approach I'd thought of.

I have an array of variables:

vars = [model.NewIntVar(0, suitableUpperBound, f'x{i}') for i in range(some_number)]

The problem is, once I've found a solution (with the constraints I have in place) for a specific array configuration (say, [0,1,4,5] is a solution), I do not want the algorithm to search for solution with the same vars[-1] elemenent (i.e, the same last element). I'd like for it to increment to '6' and search for solutions.

The one approach I thought of was dynamically changing the lower bound each time a solution is found (so it begins the search from another position), but is there a more rigorous, mathematical way to achieve this?

1

There are 1 answers

0
Laurent Perron On

Once solve is started. The model is read-only.

Solution callbacks do not allow modifying the model.

You can patch the model to change the bounds of the variable. There are some slight hints on how to do that here.