from ortools.sat.python import cp_model


class SolutionPrinter(cp_model.CpSolverSolutionCallback):
    """Print intermediate solutions."""

    def __init__(self, x):
        cp_model.CpSolverSolutionCallback.__init__(self)
        self._solution_count = 1
        self.x = x

    def on_solution_callback(self):
        """Called at each new solution."""

        print(
            "Solution " + str(self._solution_count) + " ---> " + str(self.Value(self.x))
        )

        print("")
        self._solution_count += 1


model = cp_model.CpModel()
model.name = "hint_test_snippet"

x = model.NewIntVar(0, 10, "x")
y = model.NewIntVar(0, 10, "y")

# Maximize x
model.Maximize(x)

# Hint
model.AddHint(x, 1)

solver = cp_model.CpSolver()
solver.parameters.log_search_progress = True
solver.parameters.num_search_workers = 1
solver.parameters.fix_variables_to_their_hinted_value = True
printer = SolutionPrinter(x)

solver.Solve(model, printer)
print(f"x = {solver.Value(x)} and y = {solver.Value(y)}")
