Closed johnnymo87 closed 1 year ago
Thanks @johnnymo87, looks great! fwiw, Python has this method as well.
from ortools.sat.python import cp_model
model = cp_model.CpModel()
x = model.NewIntVar(0, 10, 'x')
y = model.NewIntVar(0, 10, 'y')
z = model.NewIntVar(0, 10, 'z')
model.AddDivisionEquality(x, y, z)
solver = cp_model.CpSolver()
status = solver.Solve(model)
print(status)
print(solver.SolutionInfo())
Hi @ankane, I'm not sure about this PR, but I figured that I'd open it to get your feedback.
I was playing around with division in the CP-SAT solver, and I ran into a problem where I got back a
model_invalid
status from the solver.The docs suggest multiple things for debugging this, such as calling
ValidateCpModel(model_proto)
for C++ ormodel.Validate()
for python.Less documented, however, is the
solution_info
attribute in theCpSolverResponse
proto, whichSolveCpModel
sets with an error message if there is one while doing validation before solving.To debug my problem locally, I ultimately took this
solution_info
path. And I was curious about your thoughts on it. I'm not sure if we want to go down the path of exposingCpSolverResponse.solution_info()
when to my casual reading it seems less documented compared toValidateCpModel(model_proto)
. But I thought I'd offer this up here to start a discussion.