From d0ed31d92e89787a065e6c48a21de3a99c49e0f5 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Tue, 23 Jul 2024 19:35:24 +0200 Subject: [PATCH] specify the modulo convention in python CP-SAT --- ortools/sat/python/cp_model.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ortools/sat/python/cp_model.py b/ortools/sat/python/cp_model.py index be6f2282b3b..27513448c84 100644 --- a/ortools/sat/python/cp_model.py +++ b/ortools/sat/python/cp_model.py @@ -2205,7 +2205,19 @@ def add_abs_equality(self, target: LinearExprT, expr: LinearExprT) -> Constraint def add_modulo_equality( self, target: LinearExprT, expr: LinearExprT, mod: LinearExprT ) -> Constraint: - """Adds `target = expr % mod`.""" + """Adds `target = expr % mod. + + It uses the C convention, that is the result is the remainder of the + integral divisiion rounded towards 0. + + Args: + target: the target expression. + expr: the expression to compute the modulo of. + mod: the modulus expression. + + Returns: + A `Constraint` object. + """ ct = Constraint(self) model_ct = self.__model.constraints[ct.index] model_ct.int_mod.exprs.append(self.parse_linear_expression(expr))