Last active
April 30, 2022 14:51
-
-
Save mlabonne/5391d243f757d6f62cf28aedd021ccd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = cp_model.CpModel() | |
solver = cp_model.CpSolver() | |
# 1. Variable | |
army = model.NewIntVar(1, 100000, 'army') | |
# 2. Constraints | |
model.AddModuloEquality(0, army, 13) | |
model.AddModuloEquality(0, army, 19) | |
model.AddModuloEquality(0, army, 37) | |
class PrintSolutions(cp_model.CpSolverSolutionCallback): | |
"""Callback to print every solution.""" | |
def __init__(self, variable): | |
cp_model.CpSolverSolutionCallback.__init__(self) | |
self.__variable = variable | |
def on_solution_callback(self): | |
print(self.Value(self.__variable)) | |
# Solve with callback | |
solution_printer = PrintSolutions(army) | |
solver.parameters.enumerate_all_solutions = True | |
status = solver.Solve(model, solution_printer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment