tuxtimo
tuxtimo

Reputation: 2790

Opposite of AddModuloEquality

I'm looking for the opposite of AddModuloEquality in or-tools. Something like x % 3 != y % 3 Is there any constrait which suits that problem? Unfortunately, I could not find anything in the documentation.

Upvotes: 0

Views: 436

Answers (1)

Stradivari
Stradivari

Reputation: 2766

You would have to create intermediate variables and constraint them:

from ortools.sat.python import cp_model

if __name__ == '__main__':

    model = cp_model.CpModel()
    x = model.NewIntVar(0, 10, 'x')
    y = model.NewIntVar(0, 10, 'y')

    x_mod_3 = model.NewIntVar(0, 2, 'x_mod_3')
    y_mod_3 = model.NewIntVar(0, 2, 'y_mod_3')

    model.AddModuloEquality(x_mod_3, x, 3)
    model.AddModuloEquality(y_mod_3, y, 3)

    model.Add(x_mod_3 != y_mod_3)

    solver = cp_model.CpSolver()
    solver.Solve(model)

    print(solver.Value(x), solver.Value(x_mod_3))
    print(solver.Value(y), solver.Value(y_mod_3))

Upvotes: 2

Related Questions