# [gecode-users] Modulo operator

Christian Schulte cschulte at kth.se
Mon Aug 25 15:46:12 CEST 2008

```If you want to write a propagator for this, the non-reified divmod
propagator that is included in the just released 2.2.0 might be a good
starting point.

Christian

--

Christian Schulte, www.ict.kth.se/~cschulte/

From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Mauricio Toro
Sent: Monday, August 25, 2008 3:40 PM
To: gecode list
Subject: Re: [gecode-users] Modulo operator

Hello,

I am trying to write this reified constraint.

(a mod c = d) <-> b

where a,c,d are IntVars and b is BoolVar.

In the past, you recommend to represent

A = (B - C) mod n as  A = (B-C) + n * X.

But, now I am wondering how can I

write a reified propagator for (a mod c = d) <-> b.

Thanks,

Mauricio

2008/5/14 Guido Tack <tack at ps.uni-sb.de>

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.
>
> 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

_______________________________________________
Gecode users mailing list
users at gecode.org
https://www.gecode.org/mailman/listinfo/gecode-users

--
Mauricio Toro Bermudez
Estudiante de Ingeniería de Sistemas