Home / Computer science / Set packing / Computation
Find all optimal solutions
class SolutionPrinter(cp.CpSolverSolutionCallback):
def __init__(self):
cp.CpSolverSolutionCallback.__init__(self)
self.__solution_count = 0
def on_solution_callback(self) -> None:
self.__solution_count += 1
if self.__solution_count > 1: print()
print("Solution #%d" % self.__solution_count)
print("x = %s" % [solver.value(x_i) for x_i in x])
print("y = %s" % y_star)
printer = SolutionPrinter()
status = solver.solve(model, printer)
Solution #1 x = [0, 0, 1, 1, 0, 0] y = 2 Solution #2 x = [0, 0, 1, 1, 0, 0] y = 2 Solution #3 x = [0, 0, 1, 1, 0, 0] y = 2 Solution #4 x = [0, 0, 1, 1, 0, 0] y = 2 Solution #5 x = [0, 0, 1, 1, 0, 0] y = 2