I'm trying to solve a problem with Google OR-Tools' CP-Solver. Is it possible to add a constraint like this: x1 XOR x2 XOR x3 == 0 Thanks in advance.
AddBoolXOr of n booleans means that the sum is odd. You could just add another True boolean.
from ortools.sat.python import cp_model
model = cp_model.CpModel()
solver = cp_model.CpSolver()
a = model.NewBoolVar("")
b = model.NewBoolVar("")
c = model.NewBoolVar("")
model.AddBoolXOr([a, b, c, 1])
solver.Solve(model)
print([solver.Value(x) for x in (a, b, c)])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With