28 CHAPTER 2. TOY(FD) Programming Examples
constrain L L 0 Cs, % essential
sum L (#=) N, % redundant #1
scalar_product Cs L (#=) N, % redundant #2
labeling Label L
constrain :: [int] -> [int] -> int -> [int] -> bool
constrain [] A B [] = true
constrain [X|Xs] L I [I|S2] = true <==
count I L (#=) X,
constrain Xs L (I+1) S2 % Functional syntax (I+1)
Below we show an example of solving including compiling and loading process:
TOY(FD)> /compile(magicseq)
Checking syntax Including File cflpfd.toy................
.........................................................
PROCESS COMPLETE
TOY(FD)> /load(magicseq)
{compiling c:/sicstus382/bin/toyfd/magicseq.pl...}
{module plgenerated imported into initToy}
{module toycomm imported into plgenerated}
{module primFunct imported into plgenerated}
{module primitivCod imported into plgenerated}
{module clpfd imported into plgenerated}
{compiled c:/sicstus382/bin/toyfd/magicseq.pl in
module plgenerated, 610 msec -32 bytes}
TOY(FD)> magic 10 L []
yes
L == [ 6, 2, 1, 0, 0, 0, 1, 0, 0, 0 ]
Elapsed time: 0 ms.
more solutions (y/n/d) [y]? ; % Do not look for more solutions
Comentarios a estos manuales