- Mail actions: [ respond to this message ] [ mail a new topic ]
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]

From: Marco Gavanelli <marco.gavanelli_at_...17...>

Date: Fri, 14 Aug 2009 23:18:15 +0200

Date: Fri, 14 Aug 2009 23:18:15 +0200

Dario Campagna wrote: > Hi, > > I have a question concerning the arithmetic operator mod and ic > constraints. > > In SICStus Prolog, with the clpfd solver, it is possible to write the > goal Y in 1..10, X #= Y mod 3, which returns Y in 1..10, X in 0..2. > I would like to write the same goal and, in particular, constraint of > the form A #= B mod n (where n is an integer value) in ECLiPse, but > the set of arithmetic expression that can be used inside ic > constraints does not include an arithmetic expression equivalent to E1 > mod E2. > How can I solve this problem? Hi Dario, I do not know if there is a built-in constraint for doing that. In case there is not, one idea is to use the definition of modulus. By definition, X #= Y mod 3 means that there exists some quotient Q such that Q*3+X=Y and that X :: 0..2. So, your goal could become: [eclipse 3]: Y :: 1..10, X+Q*3 #= Y, X :: 0..2. Y = Y{1 .. 10} X = X{0 .. 2} Q = Q{0 .. 3} Delayed goals: 3 * Q{0 .. 3} + X{0 .. 2} - Y{1 .. 10} #= 0 Yes (0.00s cpu) Is this what you are expecting? Otherwise, you could define yourself a new constraint that does the pruning you require. Library Propia is often a fast way to implement new constraints starting from a predicate (in this case, the mod operator between integers): [eclipse 4]: use_module(library(propia)). propia.eco loaded in 0.00 seconds Yes (0.00s cpu) [eclipse 5]: Y :: 1..10, (indomain(Y), X is Y mod 3) infers most. Y = Y{1 .. 10} X = X{0 .. 2} Delayed goals: (indomain(Y{1 .. 10}), X{0 .. 2} is Y mod 3) infers most Yes (0.00s cpu) If you want something more efficient, you can look in the manual how to define a new constraint. Cheers, Marco -- Marco Gavanelli, Ph.D. in Computer Science Dept of Engineering University of Ferrara Via Saragat 1 - 44100 Ferrara (Italy) Tel +39-0532-97-4833 Fax +39-0532-97-4870 http://www.ing.unife.it/docenti/MarcoGavanelli/Received on Fri Aug 14 2009 - 21:18:30 CEST

*
This archive was generated by hypermail 2.3.0
: Sat Aug 24 2019 - 06:15:04 CEST
*