[gecode-users] Modulo operator

Guido Tack tack at ps.uni-sb.de
Wed May 14 08:43:03 CEST 2008


Malcolm Ryan wrote:

> I'd like to express the constraint:
>
> A = (B - C) mod n
> 0 <= A < n
>
> for variables A,B,C and constant n.
>
> How would you advise doing this? The obvious answer is to add an extra
> variable X:
>
> A = (B-C) + n * X
> 0 <= A < n
>
> but I'm not sure if this is best. Can you advise?

As there's no built-in propagator for the modulo constraint, you have  
to decompose into other constraints, so your solution should be ok.   
After all, it's just a linear equation with constant coefficients  
1*A-1*B+1*C-n*X=0, right?  And X will be determined as soon as A,B,C  
are, you don't even have to include X in the branching.

Guido





More information about the gecode-users mailing list