google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
10.79k stars 2.09k forks source link

Inverse constraint crashes presolve #4072

Open IgnaceBleukx opened 5 months ago

IgnaceBleukx commented 5 months ago

Hi,

I was trying to generate some random problems involving Inverse constraints and found OR-tools crashing on some of the instances. Below, is a minimal example in Python:

from ortools.sat.python import cp_model as ort

model = ort.CpModel()
solver = ort.CpSolver()

x = [model.NewIntVar(0,1,name=f"x_{i}") for i in range(4)]
rev1 = [model.NewIntVar(0,1,name=f"rev1_{i}") for i in range(2)]
rev2 = [model.NewIntVar(0, 1, name=f"rev2_{i}") for i in range(2)]
rev3 = [model.NewIntVar(0, 1, name=f"rev3_{i}") for i in range(2)]

model.AddInverse([x[0], x[3]], rev1)
model.AddInverse([x[0], x[1]], rev2)
model.AddInverse([x[2], x[0]], rev3)

# solver.parameters.cp_model_presolve=False # EDIT: uncommenting this makes the model run fine
status = solver.Solve(model)

if status == ort.INFEASIBLE:
    print("Model is UNSAT")
else:
    print("Found solution")

>> Output: 
Check failed: FixFromAssignment(sat_solver->Assignment(), new_to_old_index, context_) 
*** Check failure stack trace: ***

By disabling presolve the solver does find a solution.

I am using OR-tools version 9.8.3296 on Ubuntu 22.04.

Kind regards, Ignace

lperron commented 5 months ago

Actually no, it works fine with presolve, and crashes without it.

IgnaceBleukx commented 5 months ago

Oh it seems I forgot to comment in the solver.parameters.cp_model_presolve = False line in the code snippet. I fixed it now to reflect the actual output : )