L`UNIVERSITE D`ORLEANS

L`UNIVERSITE D`ORLEANS
THESE
presentee a
DOCTEUR EN INFORMATIQUE
par
G. File
J.P. Delahaye
P. van Hentenryck
D.H.D. Warren
F. Benhamou
P. Codognet
P. Deransart
G. Ferrand
::::::::::::
::::::::::::
::::::::::::
::::::::::::
::::::::::::
::::::::::::
::::::::::::
::::::::::::
1
2
1.2 Approche RISC versus approche CISC : : : : : : : : : : : : : : : : : : : :
4
6
1.4 Contraintes booleennes : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
7
8
10
10
12
12
13
2.3 Le cas C =FD : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
14
14
in
in
r et operation Tell : : : : : : : : : : : : : : : 19
22
3 Implantation de wamcc
24
24
25
28
29
30
3.1.5 Registres : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
32
33
38
48
3.2.1 Cahier des charges : : : : : : : : : : : : : : : : : : : : : : : : : : :
48
49
50
51
52
53
3.2.7 La methode Erlang : : : : : : : : : : : : : : : : : : : : : : : : : : :
54
3.2.8 La methode wamcc : : : : : : : : : : : : : : : : : : : : : : : : : : :
56
61
61
62
63
65
3.4 Evaluation de wamcc : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
66
67
3.4.2 Le jeu de benchmarks : : : : : : : : : : : : : : : : : : : : : : : : :
68
3.4.3
wamcc
69
3.4.4
wamcc
versus des Prolog professionnels : : : : : : : : : : : : : : : :
70
74
4.1 Extension de la WAM : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
74
74
77
83
4.1.4 Operation Tell : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
89
4.2 Integration de clp(FD) dans wamcc : : : : : : : : : : : : : : : : : : : : : :
90
93
4.3.1 Le jeu de benchmarks : : : : : : : : : : : : : : : : : : : : : : : : :
93
94
95
5 Contraintes booleennes
107
5.5
5.4.2
clp(B/FD)
5.4.3
clp(B/FD)
clp(B)
5.5.1 La contrainte primitive l0
l : : :,ln : : : : : : : : : : : : : : : : 122
<= 1 ,
134
149
in
r : : : : : : : : : : : : : : : : : : : : 157
8 Regulation du trac aerien avec clp(FD)
170
8.1 Introduction : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 171
8.2 Problem Context : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 173
8.2.1 Air Trac Flow Management Overview : : : : : : : : : : : : : : : : 173
8.2.2 The Slot Allocation Problem : : : : : : : : : : : : : : : : : : : : : : 174
8.3
clp(FD)
in a Nutshell : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 175
8.3.1 The Constraint X
in
r : : : : : : : : : : : : : : : : : : : : : : : : 176
8.3.2 High-Level Constraints and Propagation Mechanism : : : : : : : : : 177
8.3.3 Optimizations : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 178
8.3.4 Performances : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 179
8.3.5
atmos interval
8.4 Slot Allocation Satisfying Capacity Constraints : : : : : : : : : : : : : : : 180
8.4.1 A Small Example : : : : : : : : : : : : : : : : : : : : : : : : : : : : 180
8.4.2
clp(FD)
Model : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 180
8.4.3
clp(FD)
Implementation of our Small Example : : : : : : : : : : : 181
8.4.4 Optimization Trials - Heuristics : : : : : : : : : : : : : : : : : : : : 182
8.4.5 Results : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 183
8.4.6 Extension of the Model to Integrate Flow Rate Constraints : : : : : 185
8.4.7 A Simulation Aid Tool for Regulators - Cost estimation of Regulation
Plans : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 187
8.5 Conclusion and Further Works : : : : : : : : : : : : : : : : : : : : : : : : : 187
9 Conclusion
188
A Programme crypta
191
B Programme eq10
193
195
D Programme alpha
198
200
F Programme five
202
G Programme cars
204
H Programme bridge
209
216
I.1 Using wamcc - Modularity : : : : : : : : : : : : : : : : : : : : : : : : : : : 217
I.2 From Prolog modules to Unix Executables : : : : : : : : : : : : : : : : : : 219
I.2.1 Compiling Prolog Modules : : : : : : : : : : : : : : : : : : : : : : : 219
I.2.2 Generating Object Files : : : : : : : : : : : : : : : : : : : : : : : : 221
I.2.3 Linking Object Files : : : : : : : : : : : : : : : : : : : : : : : : : : 221
I.2.4 Stack Overow Messages : : : : : : : : : : : : : : : : : : : : : : : : 222
I.2.5 Makele Generator - bmf wamcc Utility : : : : : : : : : : : : : : : : 222
I.3 Built-in Predicates : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 223
I.3.1 Input / Output : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 223
I.3.2 Arithmetic : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 228
I.3.3 Term Management : : : : : : : : : : : : : : : : : : : : : : : : : : : 230
I.3.4 Test Predicates : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 234
I.3.5 Control : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 235
I.3.6 List Processing : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 237
I.3.7 Operators : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 238
I.3.8 Modication of the Program : : : : : : : : : : : : : : : : : : : : : : 239
I.3.9 All Solutions : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 240
I.3.10 Global Variables : : : : : : : : : : : : : : : : : : : : : : : : : : : : 242
I.3.11 Miscellaneous : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 247
I.4 Debugger : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 249
254
J.1 Introduction : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 255
J.2 Finite Domain variables : : : : : : : : : : : : : : : : : : : : : : : : : : : : 256
J.3 Finite Domain built-in predicates / constraints : : : : : : : : : : : : : : : : 257
J.3.1 The constraint X
in
r : : : : : : : : : : : : : : : : : : : : : : : : : 257
J.3.2 Linear arithmetic constraints : : : : : : : : : : : : : : : : : : : : : 258
J.3.3 Other arithmetic constraints : : : : : : : : : : : : : : : : : : : : : : 259
J.3.4 Domain Handling : : : : : : : : : : : : : : : : : : : : : : : : : : : : 260
J.3.5 Enumeration predicates : : : : : : : : : : : : : : : : : : : : : : : : 261
J.3.6 Symbolic constraints : : : : : : : : : : : : : : : : : : : : : : : : : : 261
J.3.7 Symbolic constraints : : : : : : : : : : : : : : : : : : : : : : : : : : 262
J.4 Boolean built-in predicates / constraints : : : : : : : : : : : : : : : : : : : 262
J.4.1 Basic boolean constraints : : : : : : : : : : : : : : : : : : : : : : : 262
J.4.2 Symbolic boolean constraints : : : : : : : : : : : : : : : : : : : : : 263
2
20
3
48
4
64
5
performances de wamcc (temps en sec.) : : : : : : : : : : : : : : : : : : : :
68
6
wamcc
69
7
wamcc
71
8
88
9
92
92
94
95
98
98
in
r : : : : : : : : : : : : : : : : : : : : : : : : 16
clp(FD)
versus CHIP (temps en sec.) : : : : : : : : : : : : : : : : : : : : : 106
20
clp(FD)
clp(B/FD)
versus CHIP (temps en sec.) : : : : : : : : : : : : : : : : : : : 118
24
clp(B/FD)
25
clp(B/FD)
26
clp(B/FD)
27
clp(B/FD)
l : : :,ln : : : : : : : : : : : : : : : : : : : : 123
<= 1 ,
29 denition du resolveur booleen de clp(B) : : : : : : : : : : : : : : : : : : : 124
30 code genere pour and(X,Y,Z) : : : : : : : : : : : : : : : : : : : : : : : : : 130
31
clp(B)
f
g
in - val(Y)
f
in
r : : : : : : : : : : : : : : : : : : : 159
g
& - val(Y)-I
f
& - val(Y)+I
g : : : : : : : : : 161
39 fragment of the constraint system syntax : : : : : : : : : : : : : : : : : : : 176
40 implementation of our small problem with clp(FD) constraints : : : : : : : 182
26
2
29
3
31
4
33
5
processus de compilation : : : : : : : : : : : : : : : : : : : : : : : : : : : :
61
6
62
7
77
8
78
9
80
82
82
97
<= [-X,Y]
: : : : : 128
19 proportion de chaque issue de la procedure de consistance : : : : : : : : : : 131
20 Display of SPORT system : : : : : : : : : : : : : : : : : : : : : : : : : : : 172
21 Graphical representation of a small problem : : : : : : : : : : : : : : : : : 180
22 UM trac before CLP process : : : : : : : : : : : : : : : : : : : : : : : : : 184
23 UM trac after CLP process : : : : : : : : : : : : : : : : : : : : : : : : : 184
CHAPITRE 1. INTRODUCTION
2
CHAPITRE 1. INTRODUCTION
3
CHAPITRE 1. INTRODUCTION
4
CHAPITRE 1. INTRODUCTION
5
CHAPITRE 1. INTRODUCTION
6
CHAPITRE 1. INTRODUCTION
7
CHAPITRE 1. INTRODUCTION
8
CHAPITRE 1. INTRODUCTION
9
clp(FD)
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
11
S; c ` c (Struct)
S1 ` c1 S2 ; c1 ` c2
(Cut)
S1 ; S2 ` c2
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
12
p(X ) : q1 (Y1); :::; qn(Yn)
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
13
0
; 0 > est < G ; ; >, et ou < Gi+1 ; i+1 > se derive de < Gi ; i > comme suit.
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
14
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
15
2.3.2 La contrainte
X
in
r
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
16
in
r ou X 2 Vd et r 2
r
r ::= t1 ..t2
ftg
R
dom(Y )
r1 : r2
r1 & r2
-r
r + ct
r - ct
r * ct
r / ct
t ::=
in
Y (terme indexical min)
Y (terme indexical max)
ct j t t j t1-t2 j t1 *t2 j t1 /<t2 j t1 />t2
min( )
max( )
1+ 2
ct ::= C
nj
(parametre terme)
j ct1 +ct2 j ct1 -ct2 j ct1*ct2 j ct1 /<ct2 j ct1 />ct2
infinity
in
in
r
n..n.
dom( )
min( )
max( )
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
17
in
r.
in
X in 10..50
fX
fX
in
in
X in 30..50
X in min(Y)..40
3
in
fX
fX
in 3..20 &
in 5..20 &
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
18
X in dom(Y)+1
fX
fX
in
in
Exemple 2.1
'x=y+c'(X,Y,C):- X in min(Y)+C..max(Y)+C,
Y in min(X)-C..max(X)-C.
3
Exemple 2.2
'x+y=z'(X,Y,Z):- X in min(Z)-max(Y)..max(Z)-min(Y),
Y in min(Z)-max(X)..max(Z)-min(X),
Z in min(X)+min(Y)..max(X)+max(Y).
3
Exemple 2.3
'x=y+c'(X,Y,C):- X in dom(Y)+C,
Y in dom(X)-C.
3
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
Exemple 2.4
'xy'(X,Y):Exemple 2.5
'xay'(X,A,Y):-
X in min(Y)..infinity,
Y in 0..max(X).
19
3
X in A*min(Y)..infinity,
Y in 0..max(X)/<A.
3
Exemple 2.6
'x=
6 y'(X,Y):-
X in -dom(Y),
Y in -dom(X).
3
X
in
r
et operation
T ell
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
DomSyn : domaines syntaxiques T : Contr ! Store ! Store
TermSyn : termes syntaxiques
T 0 : Contr ! Store ! Store
Dom
: domaines
Er : DomSyn ! Store ! Dom
N
: entiers naturels
Et : TermSyn ! Store ! N
Contr
: contraintes X in r
Store
: stores
T [ c] s
= fix ( s : Sc 2s[fcg T 0 [ c0 ] s)
T 0 [ x in r ] s
= let d = dEr [ r ] se in s [ f x in d g [ f x in r g
0
Er [ t1 ..t2 ] s
Er [ ftg ] s
Er [ R ] s
Er [ dom(Y ) ] s
Er [ r1 : r2 ] s
Er [ r1 & r2 ] s
Er [ -r ] s
Er [ r + ct ] s
Er [ r - ct ] s
Er [ r * ct ] s
Er [ r / ct ] s
= Et [ t1 ] s :: Et [ t2 ] s
= fEt [ t ] sg
= lookup range(R)
= cur domain(X ,s)
= Er [ r1 ] s [ Er [ r2 ] s
= Er [ r1 ] s \ Er [ r2 ] s
= 0::infinity n Er [ r ] s
= Er [ r ] s + Et [ ct ] s
= Er [ r ] s Et [ ct ] s
= Er [ r ] s Et [ ct ] s
= Er [ r ] s = Et [ ct ] s
Et [ n ] s
Et [ infinity ] s
Et [ C ] s
Et [ min(Y ) ] s
Et [ max(Y ) ] s
Et [ t1 + t2 ] s
Et [ t1 - t2 ] s
Et [ t1 * t2 ] s
Et [ t1 /< t2 ] s
Et [ t1 /> t2 ] s
=n
= infinity
= lookup term(C )
= min(cur domain(X ,s))
= max(cur domain(X ,s))
= Et [ t1 ] s + Et [ t2 ] s
= Et [ t1 ] s Et [ t2 ] s
= Et [ t1 ] s Et [ t2 ] s
= bEt [ t1 ] s = Et [ t2 ] sc
= dEt [ t1 ] s = Et [ t2 ] se
X s
X s
cur domain( , )
lookup store( , )
R
C
lookup range( )
lookup term( )
= Er lookup store(X ,s) ;
= if 9 X in r 2 s then r else 0..infinity
retourne le domaine lie a R
retourne l'entier lie a C
20
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
21
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
22
Denition 2.13 Un domaine r est monotone (resp. anti-monotone) ssi
8S; S 0 S 0 v S ) rS rS (resp. rS rS ).
Une contrainte c X in r est (anti-)monotone ssi r est (anti-)monotone.
0
0
S0
S ` c ssi 8S 0 S 0 v S ) XS rS
0
Un store S contredit une contrainte c X
in
in
0
r ssi S satisfait :c, i.e. S ` X
r.
in -
CHAPITRE 2. LA PROGRAMMATION LOGIQUE PAR CONTRAINTES
23
0
0
0
0
0
0
0
0
0
24
CHAPITRE 3. IMPLANTATION DE WAMCC
25
t1 ; :::; Xn
tng),
CHAPITRE 3. IMPLANTATION DE WAMCC
26
<0,{},p(s(0),0,R) p(A,B,R)>
<2,{X1
0,Y1
0,s(Z1)
<1,{X2
<1,{0
A,X3
s(0),s(0)
0,0
R},p(0,0,Z1) p(A,B,s(Z1))>
Z1},p(A,B,s(0))>
B},_>
succes
A
B
R
<2,{s(X3)
<1,{0
0
s(0)
s(0)
A,Y3
B,Z3
X3,X4
B},_>
succes
A
B
R
1) p(0,X,X).
2) p(S(X),Y,s(Z)):− p(X,Y,Z).
0,0
0},p(X3,B,0)>
s(0)
0
s(0)
but: p(s(0),0,R), p(A,B,R).
CHAPITRE 3. IMPLANTATION DE WAMCC
27
retour-arriere (backtracking) : consistant a reprendre le calcul a la derniere alternative
CHAPITRE 3. IMPLANTATION DE WAMCC
28
CHAPITRE 3. IMPLANTATION DE WAMCC
TUV
adresse donn
ee
Trail Unbound Variable
TOV
valeur
adresse donn
ee
Trail One Value
TMV
valeur n
.
.
.
valeur 1
n
adresse donn
ee
Trail Multiple Values
TFC
adresse code
29
Trail for Function Call
traduction de tagged word.
CHAPITRE 3. IMPLANTATION DE WAMCC
30
CHAPITRE 3. IMPLANTATION DE WAMCC
31
Argument n−1
:
Argument 0
structure
STC
liste
LST
INT
constante
CST
entier
Argument Car
Heap
variable
REF
CHAPITRE 3. IMPLANTATION DE WAMCC
32
(Program Counter)
(Continuation Program)
(Environment)
(Backtrack)
(Backtrack Cut)
(Heap)
(Structure pointer)
(Trail)
(Arguments)
CHAPITRE 3. IMPLANTATION DE WAMCC
33
Code Alternat.
Sauvegarde CP
Sauvegarde E
Pt choix prec.
Sauvegarde BC
Sauvegarde H
Sauvegarde TR
Sauvegarde A[0]
:
A[m] Sauvegarde A[m]
PILE DE CONTROLE
HEAP
PC
CP
E
B
BC
H
S
TR
A[0]
TRAIL
(bas)
CHAPITRE 3. IMPLANTATION DE WAMCC
34
traduction de dangling reference.
CHAPITRE 3. IMPLANTATION DE WAMCC
35
CHAPITRE 3. IMPLANTATION DE WAMCC
Si
36
B>E
:=max(B,E)
CHAPITRE 3. IMPLANTATION DE WAMCC
37
CHAPITRE 3. IMPLANTATION DE WAMCC
38
CHAPITRE 3. IMPLANTATION DE WAMCC
39
CHAPITRE 3. IMPLANTATION DE WAMCC
40
entier N :
get integer(N,A)
liste vide :
get nil(A)
structure F/N :
get structure(F/N,A)
unify ...
.
.
.
unify ...
CHAPITRE 3. IMPLANTATION DE WAMCC
41
premiere occurrence d'une variable V :
constante C :
unify constant(C)
entier N :
unify integer(N)
liste vide :
unify nil.
CHAPITRE 3. IMPLANTATION DE WAMCC
42
CHAPITRE 3. IMPLANTATION DE WAMCC
43
entier N :
put integer(N,A)
liste vide :
put nil(A)
structure F/N :
put structure(F/N,A)
unify ...
.
.
.
unify ...
CHAPITRE 3. IMPLANTATION DE WAMCC
44
< recuperation des registres >
proceed
q(...).
:
q1 (...), q2 (...), ..., qk (...).
allocate(N)
call(q2 )
.
.
.
deallocate
execute(qk )
:
CHAPITRE 3. IMPLANTATION DE WAMCC
45
L1 :
retry me else(L2 )
CHAPITRE 3. IMPLANTATION DE WAMCC
Lm :
46
trust me else fail
switch on constant(N,[(cte1 ,Lcte1 ),...,(cteN ,LcteN )])
try(Lj1 )
retry(Lj2 )
...
trust(Ljk )
CHAPITRE 3. IMPLANTATION DE WAMCC
Llst :
47
try(Lj1 )
retry(Lj2 )
...
trust(Ljk )
try me else(Lvar2 )
L1 :
Lvar2 :
retry me else(Lvar3 )
L2 :
Lvarp :
Lp :
trust me else fail
try(L), retry(L)
et
CHAPITRE 3. IMPLANTATION DE WAMCC
48
p/3:
switch on term(L3,fail,L1,fail,L2)
L1:
switch on integer(1,[(0,L4)])
L2:
switch on structure(1,[(s/1,L6)])
L3:
try me else(5)
L4:
get integer(0,X[0])
get value(X[1],X[2])
proceed
L5:
trust me else fail
L6:
get structure(s/1,X[0])
unify variable(X[0])
get structure(s/1,X[2])
unify variable(X[2])
execute(p/3)
% p(0,X,X).
% p(s(X),Y,s(Z)):- p(X,Y,Z).
CHAPITRE 3. IMPLANTATION DE WAMCC
49
portabilite : de maniere a permettre une large diusion et eviter l'obsolescence inherente a l'attachement a une machine donnee.
CHAPITRE 3. IMPLANTATION DE WAMCC
50
CHAPITRE 3. IMPLANTATION DE WAMCC
51
allocate
call(q)
deallocate
execute(r)
/* p:- q, r. */
q:
proceed
/* q. */
CHAPITRE 3. IMPLANTATION DE WAMCC
52
f
label switch:
switch(PC)
case p:
label p:
push(CP);
CP=p1;
goto label q;
f
case p1:
pop(CP);
goto label r;
g
g
case q:
label q:
PC=CP;
goto label switch;
.
.
.
/* p:- q,r . */
allocate
call(q)
:
deallocate
execute(r)
/* q. */
proceed
:
CHAPITRE 3. IMPLANTATION DE WAMCC
53
f
g
while(PC)
(*PC)();
void fct p()
f
g
push(CP);
CP=fct p1;
PC=fct q;
/* p:- q,r. */
allocate
call(q)
:
void fct p1()
f
g
pop(CP);
PC=fct r;
f
g
PC=CP;
deallocate
execute(r)
/* q. */
proceed
CHAPITRE 3. IMPLANTATION DE WAMCC
54
CHAPITRE 3. IMPLANTATION DE WAMCC
void fct p()
f
g
jmp tbl[p]=&&label p;
jmp tbl[p1]=&&label p1;
return;
g
/* p:- q,r. */
(initialisation)
label p:
push(CP);
CP=&&label p1;
goto *jmp tbl[q];
allocate
call(q)
:
label p1:
pop(CP);
goto *jmp tbl[r];
deallocate
execute(r)
void fct q()
f
55
jmp tbl[q]=&&label q;
return;
label q:
goto *CP;
/* q. */
(initialisation)
proceed
CHAPITRE 3. IMPLANTATION DE WAMCC
56
CHAPITRE 3. IMPLANTATION DE WAMCC
57
label
label
label
label
p();
p1();
q();
r();
/* prototypes */
#define Direct Goto(lab)
#define Indirect Goto(p lab)
lab()
(*p lab)()
void fct p()
/* p:- q,r. */
f
g
asm("label p:");
push(CP);
CP=label p1;
Direct Goto(label q);
allocate
call(q)
:
void fct p1()
f
g
asm("label p1:");
pop(CP);
Direct Goto(label r);
void fct q()
f
g
asm("label q: ");
Indirect Goto(CP);
deallocate
execute(r)
/* q. */
proceed
CHAPITRE 3. IMPLANTATION DE WAMCC
58
Indirect Goto(p lab)
de p lab.
CHAPITRE 3. IMPLANTATION DE WAMCC
59
CHAPITRE 3. IMPLANTATION DE WAMCC
#include <setjmp.h>
jmp buf jumper;
void Label Success();
void Label Fail();
Bool Call Prolog(WamCont p lab)
f
Create Choice Point();
ALTB(B)=Label Fail;
CP=Label Success;
ret val=setjmp(jumper);
if (ret val==0)
Call Next(p lab);
g
Delete Choice Point();
return ret val==2;
60
void Call Next(WamCont p lab)
f
g
int t[1024];
Indirect Goto(p lab);
void Call Prolog Success(void)
f
g
asm("Label Success:");
longjmp(jumper,2);
void Call Prolog Fail(void)
f
g
asm("Label Fail:");
longjmp(jumper,3);
CHAPITRE 3. IMPLANTATION DE WAMCC
61
wamcc
mod1.c
wamcc
modk.c
...
gcc
libc.a
modk.pl
...
mod1.o
gcc
...
modk.o
libwamcc.a
linker
executable
CHAPITRE 3. IMPLANTATION DE WAMCC
62
heap
trail
(bas)
CHAPITRE 3. IMPLANTATION DE WAMCC
63
CHAPITRE 3. IMPLANTATION DE WAMCC
64
@begin regs
@reg 3 WamCont
@reg 2 WamWordP
@reg 2 WamWordP
@reg 4 WamWordP
@reg 1 WamWordP
@reg 2 WamWordP
@reg 9 WamWordP
@end regs
CP
E
B
BC
H
TR
S
/*
/*
/*
/*
/*
/*
/*
continuation pointer
last environment pointer
last choice point pointer
backtrack cut pointer
top of the heap
top of the trail
Unification pointer
*/
*/
*/
*/
*/
*/
*/
@begin tags
@tag INT int
@tag REF stack
@tag CST malloc
@tag LST stack
@tag STC stack
@end tags
/*
/*
/*
/*
/*
Integer
Reference
Constant
List
Structure
*/
*/
*/
*/
*/
@begin stacks
@stack trail
512 TR
@stack global 4096 H
@stack local 1024 ((B>=E) ? B : E)
@end stacks
/* Trail stack
/* Global stack
/* Local stack
*/
*/
*/
CHAPITRE 3. IMPLANTATION DE WAMCC
65
CHAPITRE 3. IMPLANTATION DE WAMCC
66
CHAPITRE 3. IMPLANTATION DE WAMCC
67
7
traduction de \bootstrapped".
CHAPITRE 3. IMPLANTATION DE WAMCC
68
Programme
boyer
browse
cal
chat parser
crypt
ham
meta qsort
nand
poly 10
queens (16)
queens n (8)
queens n (10)
reducer
sdda
sendmore
tak
zebra
395
111
202
1184
96
90
146
574
112
95
79
79
388
327
66
35
57
CHAPITRE 3. IMPLANTATION DE WAMCC
69
3.4.3
wamcc
Programme
boyer
browse
cal
chat parser
crypt
ham
meta qsort
nand
poly 10
queens (16)
queens n (8)
queens n (10)
reducer
sdda
sendmore
tak
zebra
wamcc
2.2
3.450
4.020
0.300
0.980
0.016
4.330
0.045
0.120
0.300
2.440
0.700
13.680
0.270
0.015
0.230
0.550
0.260
1.000
BinProlog XSB-Prolog SWI-Prolog
3.0
1.4.0
1.8.11
6.700
11.450
21.200
7.930
11.850
18.180
0.920
1.420
5.120
1.200
1.790
2.050
0.017
0.040
0.100
5.280
8.840
12.650
0.100
0.140
0.130
0.320
overflow
0.420
0.420
0.720
1.200
4.670
6.480
31.220
0.920
1.560
3.450
16.030
28.541
56.180
0.550
overflow
0.930
0.030
0.050
0.030
1.100
0.670
2.580
1.400
1.430
651.000
0.400
0.530
0.580
2.005
2.716
5.632
CHAPITRE 3. IMPLANTATION DE WAMCC
70
3.4.4
wamcc
versus des Prolog professionnels
8
traduction de speedup.
CHAPITRE 3. IMPLANTATION DE WAMCC
wamcc
Programme
boyer
browse
cal
chat parser
crypt
ham
meta qsort
nand
poly 10
queens (16)
queens n (8)
queens n (10)
reducer
sdda
sendmore
tak
zebra
2.2
3.450
4.020
0.300
0.980
0.016
4.330
0.045
0.120
0.300
2.440
0.700
13.680
0.270
0.015
0.230
0.550
0.260
1.000
71
Sicstus Sicstus Quintus Aquarius
2.1
2.1
2.5.1
(emule) (natif)
4.940 2.350
2.850
2.750
6.630 2.020
3.340
1.380
0.890 0.540
0.500
0.290
1.130 0.500
0.650
0.350
0.027 0.013
0.017
0.010
5.050 2.090
3.000
0.950
0.048 0.021
0.050
0.015
0.200 0.084
0.130
0.040
0.320 0.150
0.250
0.070
4.930 1.280
2.820
0.610
0.980 0.370
0.580
0.130
18.200 7.250 10.780
2.250
0.270 0.120
0.270
0.100
0.023 0.016
0.017
0.010
0.630 0.170
0.280
0.080
1.020 0.390
1.620
0.060
0.300 0.230
0.230
0.160
1.582 # 1.624 # 1.026 # 3.398
CHAPITRE 3. IMPLANTATION DE WAMCC
72
CHAPITRE 3. IMPLANTATION DE WAMCC
73
74
CHAPITRE 4. IMPLANTATION DE CLP(FD)
75
CHAPITRE 4. IMPLANTATION DE CLP(FD)
76
in
n..n .
in dom(
X ).
Y et
in dom( )
CHAPITRE 4. IMPLANTATION DE CLP(FD)
77
!
:
Argument 0
sera transformee a la compilation en le pseudo-code clp(FD) :
'x=y+c'(X,Y,C):- cr
eer un environnement a 3 el
ements,
charger X a l'indice 0 (X=fv(0)),
charger Y a l'indice 1 (Y=fv(1)),
charger C a l'indice 2 (C=fp(2)),
fv(0) in min(fv(1))+fp(2)..max(fv(1))+fp(2),
fv(1) in min(fv(0))-fp(2)..max(fv(0))-fp(2).
CHAPITRE 4. IMPLANTATION DE CLP(FD)
78
CF
!
Cstr Address
Tell Fdv Adr
AF Pointer
in
r et stocke les dierentes
CHAPITRE 4. IMPLANTATION DE CLP(FD)
79
X in 0..512
X in 0..3:10..512
X in 0..100
;
128::512
;
X in 0..512
X in 0..3:10..512
X in 256..300
80
Extra contraint ?
Extra contraint ?
Extra contraint ?
CHAPITRE 4. IMPLANTATION DE CLP(FD)
81
CHAPITRE 4. IMPLANTATION DE CLP(FD)
Chain_Val
Chain_Dom
Chain_Min_Max
Chain_Max
Chain_Min
Chains_Mask
Chains_Stamp
82
Vector
Max
Min
Extra_Cstr
Domaine
Nb_Elem
Range_Stamp
FDV
variable DF
Bool contrainte()
{
eval(r);
Tell(X,r);
}
Variables DF
Info. chainages
Argument 0
Info. domaine
FDV
CHAPITRE 4. IMPLANTATION DE CLP(FD)
83
CHAPITRE 4. IMPLANTATION DE CLP(FD)
84
fd variable in A frame(V)
fd value in A frame(V)
fd range parameter in A frame(V)
fd term parameter in A frame(V)
AF. AF
CHAPITRE 4. IMPLANTATION DE CLP(FD)
85
fd install constraint(install proc,V)
fd call constraint
8
>>
>>
><
fd install
>
>>
>:
ind min
ind max
ind min max
ind dom
dly val
9
>>
>>
>=
>(fv)
>>
>;
fd proceed
CHAPITRE 4. IMPLANTATION DE CLP(FD)
86
fd term parameter(T[t],fp)
8
<
fd ind
:
fd ind min max(T[tmin],T[tmax],fv)
fd ind dom(R[r],fv)
CHAPITRE 4. IMPLANTATION DE CLP(FD)
87
fd dly val(T[t],fv,lab else)
8<
fd
:
union
inter
9=
;(R[r],R[r1]) execute R[r]
fd compl(R[r])
execute R[r] 0::infinityn
fd compl of singleton(R[r],T[t])
8
>>
><
fd range
>>
>:
add
sub
mul
div
fd integer(T[t],n)
add
sub
mul
floor div
ceil div
8
>> +pointwise
><
pointwise
R[r]
>> pointwise
>:
=pointwise
n.
execute T[t]
9
>>
>=
>>T[t].
>;
R[r1].
9>
>>
>>
=
>> term(T[t],T[t1]) execute T[t]
>>
>;
fd term copy(T[t],T[t1]
2
R[r].
execute R[r] 0::infinity n fT[t]g.
execute R[r]
execute T[t]
T[tmin]..T[tmax].
8< 9=
[ R[r1].
R[r]
:\;
9
>>
>=
>> term(R[r],T[t]) execute R[r]
>;
fd range copy(R[r],R[r1])
8>
>>
>>
<
fd term
>>
>>
>:
execute R[r]
8>
>>
>>
<
T[t]
>>
>>
>:
T[t1].
CHAPITRE 4. IMPLANTATION DE CLP(FD)
88
in R[r]
fd tell interval(T[tmin],T[tmax])
in T[tmin]..T[tmax]
(i.e. r est un intervalle).
fd set AF(3,X[3])
fd value in A frame(X[0])
fd value in A frame(X[1])
fd term parameter in A frame(X[2])
fd install constraint(inst 1,X[3])
fd call constraint
fd install constraint(inst 2,X[3])
fd call constraint
proceed
inst 1:
fd create C frame(cstr 1,0)
fd install ind min max(fv(1))
fd proceed
cstr 1:
fd
fd
fd
fd
fd
fd
inst 2:
(
ind min max(T[0],T[1],fv(1))
term parameter(T[2],fp(2))
term add term(T[0],T[2])
term add term(T[1],T[2])
tell interval(T[0],T[1])
proceed
CHAPITRE 4. IMPLANTATION DE CLP(FD)
4.1.4 Operation
89
T ell
CHAPITRE 4. IMPLANTATION DE CLP(FD)
90
CHAPITRE 4. IMPLANTATION DE CLP(FD)
91
CHAPITRE 4. IMPLANTATION DE CLP(FD)
static Bool cstr 1(WamWord *CF)
f
g
92
X in min(Y)+C..max(Y)+C
WamWord *AF=AF Pointer(CF);
WamWord *fdv adr;
WamWord tr0,tr1,tr2;
Bool
ok;
fdv adr=(WamWord *) (AF[1]);
tr0=Range(fdv adr)->min;
tr1=Range(fdv adr)->max;
fd ind min max(T[0],T[1],fv(1))
:
:
tr2=(int) (AF[2]);
fd term parameter(T[2],fp(2))
tr0+=tr2;
tr1+=tr2;
fd term add term(T[0],T[2])
fd term add term(T[1],T[2])
fdv adr=Tell Fdv Adr(CF);
ok=Tell Interval(fdv adr,tr0,tr1);
return ok;
fd tell interval(T[0],T[1])
:
fd proceed
cstr 1:
save %sp,-104,%sp
ld [%i0],%o3
ld [%i0+4],%o0
ld [%o3+4],%o2
ld [%o3+8],%o3
ld [%o2+32],%o1
ld [%o2+36],%o2
add %o1,%o3,%o1
call Tell Interval,0
add %o2,%o3,%o2
ret
rstore %g0,%o0,%o0
en entr
ee: %i0=CF
prologue
%o3=AF=AF Pointer(CF)
%o0=adresse de X
%o2=adresse de Y
%o3=C
%o1=min(Y)
%o2=max(Y)
%o1=min(Y)+C
%o0=Tell Interval(%o0,%o1,%o2)
%o2=max(Y)+C (delay slot)
retour de %o0
epilogue (delay slot)
CHAPITRE 4. IMPLANTATION DE CLP(FD)
93
crypta
eq10
eq20
alpha
five
cars
CHAPITRE 4. IMPLANTATION DE CLP(FD)
94
CHIP
3.2
0.120
0.170
0.300
61.800
0.280
2.830
0.990
42.150
1.620
0.030
0.120
clp(FD)
2.21
0.090
0.110
0.170
9.290
0.160
1.620
0.220
47.960
0.430
0.010
0.040
CHAPITRE 4. IMPLANTATION DE CLP(FD)
95
fX
g
in 5..15, Y in 0..10
CHAPITRE 4. IMPLANTATION DE CLP(FD)
fX
96
in 5..15, Y in 0..10,
(CX ),
min(X)-5..max(X)-5 (CY )g
X in min(Y)+5..max(Y)+5
Y in
equivalent a c.
CHAPITRE 4. IMPLANTATION DE CLP(FD)
Chain_Val
Chain_Dom
Chain_Min_Max
Chain_Max
Chain_Min
Chains_Mask
Chains_Stamp
97
Vector
Max
Min
Extra_Cstr
Domaine
Nb_Elem
Range_Stamp
Q_Next_Fdv_Adr
Q_Propag_Mask
Q_Date_At_Push
FDV
variable DF
CHAPITRE 4. IMPLANTATION DE CLP(FD)
98
fX
g
in 1..10, Y in 1..10
fX
in 1..10, Y in 1..10,
CHAPITRE 4. IMPLANTATION DE CLP(FD)
99
f
g (CX ),
-fval(X)g (CY )g
X in - val(Y)
Y in
fX=5, Y
in 1..4:6..10,
CX , CY g
in
r si X a ete instanciee
CHAPITRE 4. IMPLANTATION DE CLP(FD)
Chain_Val
Chain_Dom
Chain_Min_Max
Chain_Max
Chain_Min
Chains_Mask
Chains_Stamp
100
Vector
Max
Min
Extra_Cstr
Domaine
Nb_Elem
Range_Stamp
Q_Next_Fdv_Adr
Q_Propag_Mask
Q_Date_At_Push
INT_Date
Date d’instanciation finale
FDV
variable DF
70
nb. de Tells Temps
total inutile exec.
5%
6 % 25 %
34 % 47 % 24 %
ff) 85 %
94 % 74 %
CHAPITRE 4. IMPLANTATION DE CLP(FD)
101
CHAPITRE 4. IMPLANTATION DE CLP(FD)
102
Execution de utile ?
T in :::
oui
CX (T )
oui
CZ (X; Y; T )
oui
CY (X )
oui
CZ (X; Y; T )
oui
CA(Z )
oui
CZ (X; Y; T ) non
CA(Z )
non
R
oui
propag R
oui
le de propagation
| CX (T ) CZ (X; Y; T )
CZ (X; Y; T ) | CY (X ) CZ (X; Y; T )
CY (X ) CZ (X; Y; T ) | CA(Z )
CZ (X; Y; T ) CA(Z ) | CZ (X; Y; T )
CA(Z ) CZ (X; Y; T ) | CA(Z )
CZ (X; Y; T ) CA(Z ) | R
CA(Z ) R |
R|
| propag R
|
le de propagation
| CX (T ) CZ (X; Y; T )
CZ (X; Y; T ) | CY (X ) (CZ (X; Y; T ) non rajoute)
CY (X ) | CA(Z )
CA(Z ) | CZ (X; Y; T )
CZ (X; Y; T ) | R
R | CA(Z )
CA(Z) | propag R
propag R | R
|R
| propag R
|
CHAPITRE 4. IMPLANTATION DE CLP(FD)
103
CHAPITRE 4. IMPLANTATION DE CLP(FD)
104
70
nb. de Tells Temps
total inutile exec.
6%
8 % 25 %
37 % 52 % 36 %
ff) 85 %
94 % 77 %
Gain moyen
Nombre total de Tells
Initial Final Gain
8919
7057 21 %
15746 12479 21 %
24546 18963 23 %
904936 641204 29 %
15124 10429 31 %
64619 33481 48 %
4556
2143 53 %
2009404 292381 85 %
10633
3787 64 %
566
397 30 %
2483
2324 6 %
37 %
Nombre de Tells inutiles
Initial Final Gain
6794
4931 27 %
12679
9435 26 %
19343 13888 28 %
642127 377826 41 %
12439
7650 38 %
41654 10516 75 %
2722
309 89 %
1828969 111946 94 %
7620
774 90 %
325
158 51 %
2081
1922 8 %
52 %
Temps d'execution
Initial Final Gain
0.090 0.070 22 %
0.110 0.080 27 %
0.170 0.125 26 %
9.290 7.770 16 %
0.160 0.110 31 %
1.620 0.890 45 %
0.220 0.130 41 %
47.960 11.070 77 %
0.430 0.210 51 %
0.010 0.010 0 %
0.040 0.030 25 %
36 %
CHAPITRE 4. IMPLANTATION DE CLP(FD)
Version
de Base
105
Version
finale
100 %
75 %
Tells
inutiles
50 %
25 %
0 %
Temps
Tells
Temps
Tells
CHAPITRE 4. IMPLANTATION DE CLP(FD)
106
CHIP
3.2
0.120
0.170
0.300
61.800
0.280
2.830
0.990
42.150
1.620
0.030
0.120
2.750
clp(FD)
2.21
0.070
0.080
0.130
7.770
0.110
0.890
0.130
11.070
0.210
0.010
0.030
0.640
CHIP
compil.
0.040
0.490
14.560
2.068
clp(FD)
2.21
0.010
0.130
6.930
0.640
107
CHAPITRE 5. CONTRAINTES BOOLEENNES
108
CHAPITRE 5. CONTRAINTES BOOLEENNES
109
CHAPITRE 5. CONTRAINTES BOOLEENNES
110
X
Y
Z
1
0
CHAPITRE 5. CONTRAINTES BOOLEENNES
111
CHAPITRE 5. CONTRAINTES BOOLEENNES
112
CHAPITRE 5. CONTRAINTES BOOLEENNES
113
CHAPITRE 5. CONTRAINTES BOOLEENNES
0=0
114
1=1
and(X,Y,Z), X=0 ! Z=0 and(X,Y,Z), Y=0 ! Z=0
and(X,Y,Z), X=1 ! Z=Y and(X,Y,Z), Y=1 ! Z=X
and(X,Y,Z), Z=1 ! X=1 and(X,Y,Z), Z=1 ! Y=1
or(X,Y,Z), X=1 ! Z=1
or(X,Y,Z), X=0 ! Z=Y
or(X,Y,Z), Z=0 ! X=0
or(X,Y,Z), Y=1 ! Z=1
or(X,Y,Z), Y=0 ! Z=X
or(X,Y,Z), Z=0 ! Y=0
not(X,Y), X=0 ! Y=1
not(X,Y), Y=0 ! X=1
not(X,Y), X=1 ! Y=0
not(X,Y), Y=1 ! X=0
Tableau 21 : theorie de propagation booleenne B
CHAPITRE 5. CONTRAINTES BOOLEENNES
115
or(X; Y; Z )
satisfait Z = X + Y X Y
Z (1 Y ) X Z
Z (1 X ) Y Z
not(X; Y )
CHAPITRE 5. CONTRAINTES BOOLEENNES
and(X,Y,Z):-
Z in min(X)*min(Y)..max(X)*max(Y),
X in min(Z)..max(Z)*max(Y)+1-min(Y),
Y in min(Z)..max(Z)*max(X)+1-min(X).
or(X,Y,Z):-
Z in min(X)+min(Y)-min(X)*min(Y)..
max(X)+max(Y)-max(X)*max(Y),
X in min(Z)*(1-max(Y))..max(Z),
Y in min(Z)*(1-max(X))..max(Z).
not(X,Y):-
X in
Y in
116
f1-val(Y)g,
f1-val(X)g.
pigeon:
schur:
CHAPITRE 5. CONTRAINTES BOOLEENNES
ramsey:
117
5.4.2
clp(B/FD)
CHAPITRE 5. CONTRAINTES BOOLEENNES
Programme
schur 13
schur 14
schur 30
schur 100
pigeon 6/5
pigeon 6/6
pigeon 7/6
pigeon 7/7
pigeon 8/7
pigeon 8/8
queens 8
queens 9
queens 10
queens 14 1st
queens 16 1st
queens 18 1st
queens 20 1st
ramsey 12 1st
ramsey 13 1st
ramsey 14 1st
ramsey 15 1st
ramsey 16 1st
CHIP
3.2
0.830
0.880
9.370
200.160
0.300
1.800
1.700
13.450
12.740
117.800
4.410
16.660
66.820
6.280
26.380
90.230
392.960
1.370
7.680
33.180
9381.430
31877.520
118
clp(B/FD)
2.21
0.100
0.100
0.250
1.174
0.050
0.360
0.310
2.660
2.220
24.240
0.540
2.140
8.270
0.870
3.280
10.470
43.110
0.190
1.500
2.420
701.106
1822.220
CHIP
clp(B=FD)
8.30
8.80
37.48
170.49
6.00
5.00
5.48
5.05
5.73
4.85
8.16
7.78
8.07
7.21
8.04
8.61
9.11
7.21
5.12
13.71
13.38
17.49
5.4.3
clp(B/FD)
CHAPITRE 5. CONTRAINTES BOOLEENNES
119
clp(B/FD)
2.21
0.100
0.100
0.310
2.660
2.220
24.240
0.060
0.170
0.490
Pire BDD Meil. BDD
=
clp(B=FD)
32.60
11.10
50.50
14.30
3.90
# 2.81
1.13
# 10.64
2.04
# 7.16
# 1.56
# 41.79
40.16
16.83
70.76
26.76
120.83
109.69
clp(B FD)
CHAPITRE 5. CONTRAINTES BOOLEENNES
clp(B/FD)
120
et une methode enumerative
Enum.
0.810
0.880
0.210
0.120
2.290
0.840
0.370
1.440
6.900
clp(B/FD)
2.21
0.100
0.100
0.060
0.050
0.360
0.310
0.170
0.540
2.140
Enum
clp(B=FD)
8.10
8.80
3.50
2.40
6.36
2.70
2.17
2.66
3.22
BCons.
0.070
0.080
0.870
7.230
6.820
67.550
1.810
7.752
32.720
3.140
17.960
121
clp(B/FD)
2.21
0.100
0.100
0.310
2.660
2.220
24.240
0.540
2.140
8.270
0.870
3.280
BCons
clp(B=FD)
# 1.42
# 1.25
2.80
2.71
3.07
2.78
3.35
3.62
3.95
3.60
5.47
5.5
clp(B)
CHAPITRE 5. CONTRAINTES BOOLEENNES
Programme
pigeon
pigeon
pigeon
pigeon
pigeon
ramsey
ramsey
7/7 1st
8/7 1st
8/8 1st
9/8 1st
9/9 1st
10 1st
12 1st
FAST93
0.250
1.940
0.630
4.230
0.690
11.500
81.440
122
clp(B/FD)
2.21
0.020
2.220
0.030
20.190
0.040
0.110
0.190
FAST93
clp(B=FD)
12.50
# 1.14
21
# 4.77
17.25
104.54
428.42
in
5.5.1 La contrainte primitive
l
CHAPITRE 5. CONTRAINTES BOOLEENNES
123
si l'on se reporte a notre theorie de propagation booleenne (cf. table 21) l'on se rend
c ::= l0
l ::=
X
X
-
l ::: l
<= [ 1 , , n ]
(litteral positif)
(litteral negatif)
l : : :,ln
<= 1 ,
CHAPITRE 5. CONTRAINTES BOOLEENNES
124
or(X,Y,Z):-
not(X,Y):-
Z <= [X,Y],
X <= [Z],
Y <= [Z],
-Z <= [-X], -Z <= [-Y],
-X <= [Y,-Z],
-Y <= [X,-Z].
-Z <= [-X,-Y], Z <= [X],
Z <= [Y],
-X <= [-Z],
X <= [-Y,Z],
-Y <= [-Z],
Y <= [-X,Z].
X <= [-Y],
Y <= [-X],
-X <= [Y],
-Y <= [X].
CHAPITRE 5. CONTRAINTES BOOLEENNES
125
CHAPITRE 5. CONTRAINTES BOOLEENNES
126
BLV
variable booleenne
CHAPITRE 5. CONTRAINTES BOOLEENNES
127
Bvalue_2
Blv_2_Adr
Bloc2_Flag
cas n=2 ?
Tell_Bvalue
Tell_Blv_Adr
Next_Record
<= 1 ,
CHAPITRE 5. CONTRAINTES BOOLEENNES
128
Chain_1
Chain_1
Chain_0
Chain_0
BLV
BLV
Variable X
Variable Y
BValue_2=1
BValue_2=0
Blv_2_Adr
Blv_2_Adr
Bloc2_Flag=On
Bloc2_Flag=On
Tell_BValue=1
Tell_BValue=1
Tell_Blv_Adr
Tell_Blv_Adr
Next_Record
Next_Record
Chain_1
Chain_0
BLV
Variable Z
<= [-X,Y]
b load value(V,X)
CHAPITRE 5. CONTRAINTES BOOLEENNES
129
b install and tell cstr2(X0,bvalue0,X1,bvalue1,X2,bvalue2)
X1
X2
b install and tell cstr1(X0,bvalue0,X2,bvalue2).
b install and tell cstr1(X0,bvalue0,X1,bvalue1).
CHAPITRE 5. CONTRAINTES BOOLEENNES
and/3:
b load value(X[0],X[0])
b load value(X[1],X[1])
b load value(X[2],X[2])
b install and tell cstr2(X[2],1,X[0],1,X[1],1)
b install and tell cstr1(X[2],0,X[0],0)
b install and tell cstr1(X[2],0,X[1],0)
b install and tell cstr1(X[0],1,X[2],1)
b install and tell cstr2(X[0],0,X[1],1,X[2],0)
b install and tell cstr1(X[1],1,X[2],1)
b install and tell cstr2(X[1],0,X[0],1,X[2],0)
proceed
Tableau 30 : code genere pour and(X,Y,Z)
SI X est un entier, celui-ci doit ^etre egal a Bvalue :
ReducDomaine : la variable booleenne X est instanciee a Bvalue.
VerifEntier : X est deja egal a Bvalue.
CHAPITRE 5. CONTRAINTES BOOLEENNES
131
38000
8400
28500
5600
19000
2800
9500
0
0
ReducDomaine
VerifEntier
pigeon 6/6
schur 13
EchecEntier
Suspend
63800
150000
47850
112500
31900
75000
15950
37500
0
DejaResolue
ramsey 13
CHAPITRE 5. CONTRAINTES BOOLEENNES
132
clp(B)
Temps (s)
0.040
0.040
0.100
0.620
0.020
0.180
0.110
1.390
0.790
12.290
0.090
0.230
0.860
3.000
0.500
1.510
4.450
17.130
0.130
0.690
1.060
292.220
721.640
clp(B/FD)
clp(B)
2.50
2.50
2.50
1.89
2.50
2.00
2.81
1.91
2.81
1.97
1.88
2.34
2.48
2.75
1.74
2.17
2.35
2.51
1.46
2.17
2.28
2.39
2.52
133
CHIP Meil. BDD Enum BCons
clp(B)
clp(B)
clp(B) clp(B)
20.57
27.75 20.25
1.75
22.00
35.75 22.00
2.00
93.70 overflow
?
?
322.83 overflow
?
?
15.00
3.00
2.00
6.50
10.00
# 1.80 12.72 4.88
15.45
1.00
7.63
7.90
9.67
# 5.56
?
5.20
16.12
# 2.54
?
8.63
9.58
# 21.18
?
5.49
?
50.55
4.11
?
19.17
233.73
6.26
7.86
19.37 overflow
8.02
9.01
22.27 overflow
? 10.90
12.56 overflow
?
6.28
17.47 overflow
? 11.89
20.27 overflow
?
?
22.93 overflow
?
?
10.53 overflow
?
?
11.13 overflow
?
?
31.30 overflow
?
?
32.10 overflow
?
?
44.17 overflow
?
?
Exemple 6.1
'x=
6 y'(X,Y):
X in -dom(Y),
Y in -dom(X).
(c X )
(cY )
134
3
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
Exemple 6.2
'x2y'(X,Y):-
X in 2*min(Y)..infinity
Y in 0..max(X)/<2.
(c X )
(cY )
135
3
in
S ` c ssi 8S 0 S 0 v S ) XS rS
0
0
S `f c ssi 8S 0 S 0 v S ) XS rS
in
r (note `f )
0
0
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
136
2
0
in
0
0
2
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
137
alors :
E (c) =
^n
i=1
E (ci)
E (:c) =
_n
i=1
E (:ci)
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
138
a partir de l'exemple 6.1 nous derivons :
E1 (cX ) = ground(Y) ^ dom(X) -dom(Y) E1 (cY ) = ground(X) ^ dom(Y) -dom(X) ground(Y)
ground(X)
^ Y 26
^ X 26
dom(X)
dom(Y)
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
139
E1 (X 2 Y ) = E1 (cX ) _ E1(cY )
variables est instanciee.
Terme t
ct
min(Y )
max(Y )
t1 : t2 (: 2 f+;*g)
t1 : t2 (: 2 f-;/<;/>g)
inf (t)
ct
min(Y )
min(Y )
inf (t1 ) : inf (t2 )
inf (t1 ) : sup(t2)
sup(t)
ct
max(Y )
max(Y )
sup(t1) : sup(t2)
sup(t1) : inf (t2)
Proposition 6.3 (correction de inf et sup)
8S; t Inf (t)S tS Sup(t)S .
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
140
in
in
Domaine r
t1 ..t2
dom(Y )
r1 : r2 (: 2 f:;&g)
-r
r : ct (: 2 f+;-;*;/g)
A(r) (resp. X
in
M (r)).
A(r )
sup(t1)..inf (t2 )
A(min(Y )..max(Y ))
A(r1 ) : A(r2)
-M (r )
A(r) : ct
M (r )
inf (t1 )..sup(t2)
dom(Y )
M (r1 ) : M (r2 )
-A(r )
M (r) : ct
Proposition 6.5 8S; r A(r)S rS M (r)S
Preuve :
2
2
0
2
in
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
141
dom(Y) =
dom(X) =
;
;
2*max(Y)
min(X)/<2
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
142
E2 (cX ) = dom(X) 2*max(Y)..infinity
min(X) 2*max(Y)
X ) t1 ^
max(
X ) t2
in
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
Domaine r
t1 ..t2
dom(Y )
r1 : r2 (: 2 f:;&g)
-r
r : ct (: 2 f+;-g)
A(r )
sup(t1)..inf (t2 )
A(min(Y )..max(Y ))
A(r1) : A(r2 )
-M (r )
A(r) : ct
143
M (r )
inf (t1 )..sup(t2 )
M (min(Y )..max(Y ))
M (r1 ) : M (r2 )
-A(r )
M (r) : ct
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
144
Exemple 6.3
Soit c X in -dom(Y), A(c) = X in -(min(Y)..max(Y))
E (c) = min(X)..max(X) -(min(Y)..max(Y))
! COM min(X)..max(X) 0..min(Y)-1 : max(Y)+1..infinity
! IU min(X)..max(X) 0..min(Y)-1 _
min(X)..max(X) max(Y)+1..infinity
! INC (min(X) 0 ^ max(X) min(Y)-1) _
(min(X)..max(X) max(Y)+1..infinity)
! INC (min(X) 0 ^ max(X) min(Y)-1) _
(min(X) max(Y)+1 ^ max(X) infinity)
Remarques :
cette strategie peut ^etre vue comme un partial lookahead pour la detection.
a partir de l'exemple 6.1 nous derivons :
E (cX ) = min(X)..max(X) -(min(Y)..max(Y))
E (cY ) = min(Y)..max(Y) -(min(X)..max(X))
apres simplication par reecriture (cf. exemple 6.3) :
E3 (cX ) (min(X) 0 ^ max(X) min(Y)-1) _
(min(X)
E3 (cY ) (min(Y)
(min(Y)
max(Y)+1 ^ max(X) infinity
0 ^ max(Y) min(X)-1) _
max(X)+1 ^ max(Y) infinity)
max(Y)+1
max(X)+1
3
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
E3 (X 6= Y ) = E3(cX ) ^ E3 (cY ) E3 (cX )
max(X) min(Y)+1
_
min(X)
145
max(Y)+1
min(X) 2*max(Y)
min(X)/<2
2*max(Y)
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
146
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
147
2
multiplication.
Formule
bx=yc < z , x < z y
dx=ye > z , x > z y
bx=yc z , x z y
dx=ye z , x z y
bx=yc > z 6, x > z y
dx=ye < z 6, x < z y
bx=yc z 6, x z y
dx=ye z 6, x z y
preuve 1: bx=yc < z , x < z y
) : bx=yc < z ) bx=yc + 1 z or x=y < bx=yc + 1 donc x=y < z i.e. x < z y.
( : x < z y ) x=y < z or bx=yc x=y donc bx=yc < z.
preuve 2: bx=yc z , x z y
) : bx=yc z or x=y bx=yc donc x=y z i.e. x z y.
( : x z y ) x=y z or bx=yc + 1 > x=y donc bx=yc + 1 > z ) bx=yc z.
La preuve 1' (resp. 2') s'obtient a partir de la preuve 1 (resp. 2) en interchangeant : bx=yc
et dx=ye, < et >, et , et +.
2
CHAPITRE 6. DETECTION DE LA SATISFACTION DE CONTRAINTES
148
Exemple 6.4
'x2y'(X,Y):-
X in 2*min(Y)..infinity
Y in 0..max(X)/>2.
(c X )
(cY )
3
E3 (X
E3 (X
in 1..5 : 6..10)
in 1..10)
= (min(X) =
(min(X)
min(X)
^
6^
1^
1
max(X)
max(X)
max(X)
5)
_
10)
10
149
CHAPITRE 7. CONTRAINTES COMPLEXES
150
G = H + 10 F
G in min(H)+10-max(F)..max(H)+10-min(F)
(cG)
H = F + G 10
H in min(F)+min(G)-10..max(F)+max(G)-10
(cH )
CHAPITRE 7. CONTRAINTES COMPLEXES
151
fF
g
in 0..15, G in 0..15
fF
in 0..15, G in 0..15, H in 0..20,
cF , cG , cH g
F +G=I
'x+y=z'(F,G,I)
I = H + 10
'x=y+c'(I,H,10)
CHAPITRE 7. CONTRAINTES COMPLEXES
152
fF
g
in 0..15, G in 0..15
fF
in 0..15, G in 0..15, I in 10..30, H in 0..20,
F + G = I , I = H + 10g
CHAPITRE 7. CONTRAINTES COMPLEXES
153
CHAPITRE 7. CONTRAINTES COMPLEXES
154
xi =
ou (x = y) vaut 1 si x = y et 0 si x 6= y.
nX1
j =0
(xj = i)
Exemple 7.1
'x=a , b'(X,A,B):-
X
X
B
B
=
6
=
=
=
A
A
1
0
!
!
!
!
B
B
X
X
=
=
=
6
=
1,
0,
A,
A.
3
CHAPITRE 7. CONTRAINTES COMPLEXES
155
10
20
30
40
50
ff
ff
ff
ff
ff
CHIP
3.2
0.180
1.510
11.200
66.750
334.870
clp(FD)
2.21
0.040
0.130
0.270
0.470
0.720
j =0
(xj = V ) N
m
X
j =0
Bi N
CHAPITRE 7. CONTRAINTES COMPLEXES
cardinality(L,Cs,U):- N in L..U,
card(Cs,N).
card([],0).
card([C|Cs],N):- B in 0..1,
C
B=1,
C
B=0,
B=1
C,
B=0
C,
N = M + B,
card(Cs,M).
156
!
: !
!
!:
3
!
!
'xy=z'(X,Y,Z):- Y = 0
X in min(Z)/>max(Y)..max(Z)/<min(Y),
X = 0
Y in min(Z)/>max(X)..max(Z)/<min(X),
Z in min(X)*min(Y)..max(X)*max(Y).
6
3
CHAPITRE 7. CONTRAINTES COMPLEXES
157
fX
g
in 1..40, Y in 6..30
in
r
[
k2d2
d1 k ( 2 f+; ; ; =; g)
Exemple 7.4
div(X,Y,Q,R):-Y in 1..infinity,
R #
Y,
X in dom(Y)*dom(Q)+dom(R),
Q = 0
Y in (dom(X)-dom(R))/dom(Q),
6
<
!
CHAPITRE 7. CONTRAINTES COMPLEXES
Q in (dom(X)-dom(R))/dom(Y),
R in dom(X)-dom(Y)*dom(Q).
158
3
Une telle contrainte dans le store :
fX
in 2..10, Y=2, R=1
g
CHAPITRE 7. CONTRAINTES COMPLEXES
c ::= X
in
r
r ::= t1 ..t2
ftg
R
dom(Y )
r1 : r2
r1 & r2
-r
r + ct
r - ct
r * ct
r / ct
fr (a1 ,:::,ak )
a ::= r j t
t ::=
159
Y
(terme indexical min)
Y
(terme indexical max)
ct j t t j t1-t2 j t1 *t2 j t1 /<t2 j t1 />t2
f a ::: ak ) (fonction utilisateur)
min( )
max( )
1+ 2
t( 1, ,
ct ::= C
nj
infinity
(parametre terme)
j ct1 +ct2 j ct1 -ct2 j ct1*ct2 j ct1 /<ct2 j ct1 />ct2
in
r
CHAPITRE 7. CONTRAINTES COMPLEXES
160
Exemple 7.5
'xy=z'(X,Y,Z):- X in div e(min(Z),max(Y))..div d(max(Z),min(Y)),
Y in div e(min(Z),max(X))..div d(max(Z),min(X)),
Z in min(X)*min(Y)..max(X)*max(Y).
La fonction div e(x,y) (resp.
(resp. infinity) sinon.
3
x y retourne dx=ye (resp. bx=yc) si y 6= 0 et 0
div d( , ))
fX
g
in 1..100, Z in 5..24
Exemple 7.6
'xx=z'(X,Z):- X in sqrt e(min(Z))..sqrt d(max(Z)),
Z in min(X)*min(X)..max(X)*max(X).
3
fX
g
in 1..100, Z in 5..24
CHAPITRE 7. CONTRAINTES COMPLEXES
161
X 2 = Y , avec un store initial :
fX
g
in 1..100, Z in 5..24
Exemple 7.7
f
f
g
g
diff(X,Y,I):- X in - val(Y)
Y in - val(X)
f
f
g
g
& - val(Y)-I
& - val(X)-I
f
f
g
g
(cX )
(cY )
& - val(Y)+I ,
& - val(X)+I .
3
end:
fd
fd
fd
fd
fd
fd
fd
fd
fd
fd
fd
fd
dly val(1,1,end)
compl of singleton(0,1)
term copy(3,1)
term parameter(2,2)
term sub term(3,2)
compl of singleton(3,3)
inter(0,3)
term add term(1,2)
compl of singleton(1,1)
inter(0,1)
tell range(0)
proceed
f
g
in - val(Y)
T(1)=Y (si Y est clos)
R(0)=- Y
T(3)=Y
T(2)=I
T(3)=Y-I
R(3)=- Y-I
R(0)=- Y & - Y-I
T(1)=Y+I
R(1)=- Y+I
R(0)=- Y & - Y-I & - Y+I
X in - Y & - Y-I & - Y+I
retour d'ex
ecution
fg
f g
fg f g
f g
fg f g
fg f g
f
& - val(Y)-I
g
f
f g
f g
& - val(Y)+I
g
CHAPITRE 7. CONTRAINTES COMPLEXES
diff(X,Y,I):- X in f diff(val(Y),I),
Y in f diff(val(X),I).
162
(cX )
(cY )
3
16
64 ff
70 ff
81 ff
CHIP
3.2
2.830
0.990
42.150
1.620
clp(FD)
clp(FD)
2.21 2.21+fct
0.890
0.570
0.130
0.100
11.070
7.830
0.210
0.170
CHAPITRE 7. CONTRAINTES COMPLEXES
163
CHAPITRE 7. CONTRAINTES COMPLEXES
164
_ N5
= C4 - 1
3
Exemple 7.10
plus or minus(X,Y,C):- X in dom(Y)-C : dom(Y)+C,
Y in dom(X)+C : dom(X)-C.
3
fX
in 1..3, Y in 1..5
g
CHAPITRE 7. CONTRAINTES COMPLEXES
165
E
c1 _ : : : _ cn
X1 in r11 ^ : : : ^ Xk in rk1
W
:::
X1 in r1n ^ : : : ^ Xk in rkn
CHAPITRE 7. CONTRAINTES COMPLEXES
166
Exemple 7.11
'max(x,y)=z'(X,Y,Z):- Z in min(X)..infinity,
Z in min(Y)..infinity,
Z in dom(X) : dom(Y).
3
CHAPITRE 7. CONTRAINTES COMPLEXES
167
fX
g
in 5..10, Y in 7..11, Z in 1..12
^
^
T2 in min(T1)+D1..infinity
T1 in min(T2)+D2..infinity.
_
Exemple 7.12
no overlap(T1,D1,T2,D2):T1 in 0..max(T2)-D1 : min(T2)+D2..infinity,
T2 in 0..max(T1)-D2 : min(T1)+D1..infinity.
3
fT1
g
in 1..10, T2 in 1..10
CHAPITRE 7. CONTRAINTES COMPLEXES
168
Exemple 7.13
'|x-y|>=c'(X,Y,C):- X in min(Y)+C..infinity : 0..max(Y)-C,
Y in min(X)+C..infinity : 0..max(X)-C.
3
Considerons le store :
fX
g
in 1..10, Y in 1..10
CHAPITRE 7. CONTRAINTES COMPLEXES
169
3
fX
in 0..2, Y in 0..2, Z in 0..1
g
170
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
171
Using clp(FD) to Support Air Trac Flow
Management
Denise Chemla1;3 , Daniel Diaz2 , Philippe Kerlirzin1 , Serge Manchon1
1
Abstract. In this paper, a Constraint Logic Programming (CLP) approach is used to solve
an Air Trac Flow Management (ATFM) problem, the aircraft departure slot allocation.
Moreover, our purpose is to show that CLP, combining the declarativity of logic programming with the eciency of constraint solving, is well suited to model many combinatorial
optimization problems involved in the ATFM domain. clp(FD), a Constraint Logic Programming language with Finite Domain constraints has been chosen to implement our
practical application.
8.1 Introduction
The density of trac over Europe has been steadily increasing for several years. This
growth is dicult to manage and causes delays for passengers and work overloads for
controllers. ATFM aims at adapting a variable demand (the airplanes which want to y)
to the variable available capacity of the system of control so as to use this capacity at best.
It has signicant safety and economic consequences as well.
Our research is pursued in the French Air Navigation Research Center (CENA), that is
involved in the development of the future Air Trac Control system. This work will be
integrated into the SPORT decision support system for trac ow management. This
system helps ow managers in analyzing trac data and in preparing ow management
measures. It is operational in the six French Air Control Centers and at the Eurocontrol
Central Flow Management Unit located in Brussels. Figure 20 is a view of the SPORT
system showing the French sectors and the most congested routes.
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
172
Figure 20 : Display of SPORT system
In this paper, a CLP approach is used to solve the ATFM problem of departure slot
allocation. clp(FD), a CLP language with Finite Domain constraints has been chosen to
implement this practical application. The departure slot allocation is done manually until
now, so we couldn't compare our approach with linear methods that could have been yet
used. Such a comparison (linear versus CLP methods to solve ATFM problems will be
done in our next research).
The structure of this paper is as follows: Sect. 2 gives a brief description of ATFM; the third
one presents the clp(FD) language features and a new constraint developed for our needs;
Sect. 4 shows how clp(FD) can be used to solve the departure slot allocation problem
under capacity and/or ow rate constraints.
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
173
8.2 Problem Context
8.2.1 Air Trac Flow Management Overview
ATFM aims at adapting a variable demand to the variable capacity of the system of control.
Its rst objective is to assure, by smoothing the ow of aircraft, that unacceptable levels of
trac congestion do not develop. Its second goal is to perform this task without imposing
unnecessary ow restrictions.
France is overown by all European air-carriers and even more. Its airspace is a patchwork
of about 90 sectors. Each of them is under the responsibility of a pair of controllers. A
ight crosses several sectors along its route. The radar controller works on a radar position
and gives instructions to pilots via a radio link. He (she) maintains separation between
planes and keep them away from specic dangers such as military areas, storms. The
planning controller takes it on to nd convenient entry and exit ight levels and the right
coordination with neighbouring sectors. When trac allows it, sectors can be grouped
(there are about 120 possible groups of sectors).
The European ATFM activity is structured in three levels:
1. strategic level: at this level, long term measures are dened such as the trac
orientation scheme that dictates the routes operators have to use to go from specic
departure areas to specic arrival areas. National measures are also dened at this
level: modulation of controllers working hours, agreements between military and civil
air trac services, or use of main platforms scheduling;
2. pre-tactical level: an important feature of the sector is its capacity, i.e. the maximum number of ights that can enter the sector per hour. This capacity is variable
along the day and along the year. Generally, it is greater than the demand when one
team of controllers manages one sector. However, some sectors are regularly overloaded due to a limited number of controllers, to structural reasons, or to peak trac: in
that case, the demand can be greater than the capacity during certain periods of the
day. The pre-tactical ATFM consists in preparing, two days before the tactical day,
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
174
a regulation plan which is a set of ow rate restrictions intended to avoid overloads
within critical sectors.
3. tactical level: is sub-divided into two processes:
slot allocation: airline operators aected by the regulation plan have to ask for
departure slots two hours before scheduled take-o, so that each aircraft enters
critical sectors at the right time. In the French ow management unit, slots are
allocated according to a rst-demander-rst-served principle.
real time supervision: during the pre-tactical phase, relying on trac periodicity, ow managers forecast the trac to come using recorded data. Because
of last time changes (weather conditions, technical failures, ...), it is necessary
to monitor the eects of the regulation plan and to adapt some restrictions in
real time to cope with excess demand and under-used capacities.
8.2.2 The Slot Allocation Problem
First of all, we will focus on solving the slot allocation problem under capacity constraints;
a small example is presented in Sect. 4. We will then extend the model in order to integrate
another type of constraints, called \ow rate constraints", to organize the delays undergone
by the ights in the rst application.
Capacity Constraint Denition.
A capacity constraint is a relation between an airspace volume A (a sector or a group of
sectors), a temporal period T and an hourly rate N=t (N is the maximum number of
aircraft that can enter the sector each t minutes). The constraint is satised if during T ,
at most N ights per contiguous slices of t minutes width enter A1. N is called capacity
of A. The problem consists in avoiding overloads all along the tactical day by delaying
certain ights. In our model, we have made the choice that capacity constraints aect all
ights without any discrimination: no ight is privileged with regard to CLP slot allocation.
We have developed a new constraint, the atmost_interval constraint that enables the implementation
of a certain number of aircraft per contiguous slices of t-minute width; the cumulative constraint (of CHIP)
allows reasoning on sliding windows of t-minute width and is so too stringent for our needs.
1
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
175
Description Of The Slot Allocation Problem Model.
The slot allocation problem under capacity constraint can be dened by its input and
output data. The input data are:
the demand: constituted of a set of lled ight plans:
fFi : (Oi; Di; SRi : (Si;1; EETi;1; : : : ; Si;n; EETi;n))g;
where Fi is a ight identier, Oi and Di are its origin and destination, Si;1; : : : ; Si;n
are the sectors crossed by the ight, EETi;1; : : : ; EETi;n are the expected (by the
ight carrier) entry times in those sectors (EETi;1 is the expected departure time of
the ight). There are 6000 ight plans a day on average.
the resources: dened by a set of airspace volume capacity constraints:
fCCj : (fSj;1; : : : ; Sj;mg; Capaj ; H 1j ; H 2j )g
where CCj is a constraint identier, Sj;1; : : : ; Sj;m are the constrained airspace volumes by the capacity constraint, Capaj is the capacity (half-hourly maximum number of ights entering in the constrained airspace volume), H 1j and H 2j are the
bounds of the application period of the constraint. An example of such a capacity
constraint is
CC1 : (0UT 0;0 TU 0 ; 26; 600; 660)
that expresses that at most 26 aircraft can enter the group of sectors f0UT 0 ;0 TU 0g
from 10am to 11am (in minutes from 0am).
The output data is a set of satisfactory departure times fSETk;1g of the ights Fk such
that all capacity constraints are satised and the average delay undergone by a ight is
minimized.
8.3
clp(FD)
in a Nutshell
As introduced in Logic Programming by the CHIP language, clp(FD) [24] is a constraint
logic language based on nite domains, where constraint solving is done by propagation
and consistency techniques originating from Constraint Satisfaction Problems [49, 53, 71].
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
c ::=
r ::=
X in r
ftg
t..t
(interval range)
(singleton range)
C
n
min(X)
max(X)
val(X)
t + t
t - t
t * t
(parameter)
(integer)
(indexical min)
(indexical max)
(delayed value)
(addition)
(subtraction)
(multiplication)
:::
t ::=
:::
176
Tableau 39 : fragment of the constraint system syntax
The novelty of clp(FD) is the use of a unique primitive constraint which allows users to
dene their own high-level constraints. The black-box approach gives way to glass-box
approach.
8.3.1 The Constraint
X
in
r
The main idea is to use a single primitive constraint X in r, where X is a nite domain
(FD) variable and r denotes a range, which can be not only a constant range, e.g. 1::10
but also an indexical range using:
min(Y ) which represents the minimal value of Y (in the current store),
max(Y ) which represents the maximal value of Y ,
val(Y ) which represents the value of Y as soon as Y is ground.
A fragment of the syntax of this (simple) constraint system is given in table 39.
The intuitive meaning of such a constraint is: \X must belong to r in any store".
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
177
The initial domain of an FD variable is 0..1 and is gradually reduced by X in r constraints which replace the current domain of X (DX ) by DX0 = DX \ r at each modication
of r. An inconsistency is detected when DX0 is empty. Obviously, such a detection is correct
if the range denoted by r can only decrease. So, there are some monotone restrictions about
the constraints [69]. To deal with the special case of anti-monotone constraints we use the
general forward checking propagation mechanism [40] which consists in awaking a constraint only when its arguments are ground (i.e. with singleton domains). In clp(FD) this
is achieved using a new indexical term val(X ) which delays the activation of a constraint
in which it occurs until X is ground.
As shown in the previous table, it is possible to dene a constraint w.r.t. the min or
the max of some other variables, i.e. reasoning about the bounds of the intervals (partial
lookahead [67]). clp(FD) also allows operations about the whole domain in order to also
propagate the \holes" (full lookahead [67]). Obviously, these possibilities are useless when
we deal with boolean variables since the domains are restricted to 0::1.
8.3.2 High-Level Constraints and Propagation Mechanism
From X in r constraints, it is possible to dene high-level constraints (called user constraints) as Prolog predicates. Each constraint species how the constrained variable must
be updated when the domains of other variables change. In the following examples X , Y
are FD variables and C is a parameter (runtime constant value).
'x+y=c'(X,Y,C):-
X in C-max(Y)..C-min(Y),
Y in C-max(X)..C-min(X).
'x-y=c'(X,Y,C):-
X in min(Y)+C..max(Y)+C,
Y in min(X)-C..max(X)-C.
The constraint x+y=c is a classical FD constraint reasoning about intervals. The domain
of X is dened w.r.t. the bounds of the domain of Y .
In order to show how the propagation mechanism works, let us trace the resolution of the
system fX + Y = 4; X Y = 2g (translated via 'x+y=c'(X,Y,4) and 'x-y=c'(X,Y,2)):
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
178
after executing 'x+y=c'(X,Y,4), the domain of X and Y are reduced to 0::4 (C1 is in the
current store: X in 1::4, C2 : Y in 1::4). And, after executing 'x-y=c'(X,Y,2),
the domain of X is reduced to 2::4 (C3 : X in 2::6), which then reduces the domain of Y
to 0::2 (C4 : Y in 0::2).
Note that the unique solution fX = 3; Y = 1g has not yet been found. So, in order to
eciently achieve consistency, the traditional method (arc-consistency) only checks that,
for any constraint C involving X and Y , for each value in the domain of X there exists
a value in the domain of Y satisfying C and vice-versa. So, once arc-consistency has been
achieved and the domains have been reduced, an enumeration (called labeling) has to be
done on the domains of the variables to yield the exact solutions. Namely, X is assigned
to one value in DX , its consequences are propagated to other variables, and so on. If an
inconsistency arises, other values for X are tried by backtracking. Note that the order
used to enumerate the variables and to generate the values for a variable can improve the
eciency in a very signicant manner (see heuristics in [67]).
In our example, when the value 2 is tried for X , C2 and C4 are woken (because they depend
on X ). C2 sets Y to 2 and C4 detects the inconsistency when it tries to set Y to 0. The
backtracking reconsiders X and tries value 3 and, as previously, C2 and C4 are reexecuted
to set (and check) Y to 1. The solution fX = 3; Y = 1g is then obtained.
8.3.3 Optimizations
The uniform treatment of a single primitive for all complex user constraints leads to a
better understanding of the overall constraint solving process and allows for (a few) global
optimizations, as opposed to the many local and particular optimizations hidden inside
the black-box. When a constraint X in r has been reexecuted, if DX0 = DX it was useless
to reexecute it (i.e. it has neither failed nor reduced the domain of X ). Hence, we have
designed three simple but powerful optimizations for the X in r constraint [24, 25] which
encompass many previous particular optimizations for FD constraints:
some constraints are equivalent so only the execution of one of them is needed. In
the previous example, when C2 is called in the store fX in 0::4; Y in 0::1g Y is set
to 0::4. Since the domain of Y has been updated, all constraints depending on Y are
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
179
reexecuted and C1 (X in 0::4) is woken unnecessarily (C1 and C2 are equivalent).
it is useless to reexecute a constraint as soon as it is entailed. In clp(FD), only one
approximation is used to detect the entailment of a constraint X in r which is \X is
ground ". So, it is useless to reexecute a constraint X in r as soon as X is ground.
when a constraint is woken more than once from several distinct variables, only one
reexecution is necessary. This optimization is obvious since the order of constraints,
during the execution, is irrelevant for correctness.
These optimizations make it possible to avoid on average 50% of the total number of
constraint executions on a traditional set of FD benchmarks (see [24, 25] for full details)
and up to 57% on the set of boolean benchmarks presented below.
8.3.4 Performances
Full implementation results about the performances of clp(FD) can be found in [24, 25],
and show that this \glass-box" approach is sound and can be competitive in terms of
eciency with the more traditional \black-box" approach of languages such as CHIP. On
a traditional set of benchmark programs, mostly taken from [67], the clp(FD) engine is on
average about four times faster than the CHIP system, with peak speedup reaching eight.
8.3.5
atmos interval
To model capacity constraints, we needed to dene a new constraint, the atmost_interval
constraint.
The symbolic constraint atmost_interval(N; [X1 ; :::; Xm]; L; U ) is a user-dened constraint that holds if and only if at most N variables Xi are included within the interval
[L; U ]. This constraint can be dened via the relation:
CardinalfXi =L Xi U g N
A boolean Bi is associated with each variable Xi and set to 1 if L Xi U and to 0
otherwise. The sum of all Bi must be less than or equal to N . It is worth noticing that
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
V’11V’12
V1
S1 S2
V’21
V2
S3
S1
S4
V’32
V3
V4
180
V’41
S1
2
S2
S5
V’42
3
4
S2
5
6
S6
7
8
S7
10
t
[2s1]
[ 3s2 ]
Figure 21 : Graphical representation of a small problem
such a constraint should be \wired" in CHIP by the designers of the system whereas it is
dened in clp(FD) as a user constraint.
8.4 Slot Allocation Satisfying Capacity Constraints
8.4.1 A Small Example
In the graphical representation (Fig. 21), 4 ights are represented as connected segments.
Each segment corresponds to the crossing of a sector by a ight and is characterized by
its length proportional to the crossing duration. The capacity constraints are represented
on time axis: only 2 aircraft are allowed to enter S1 between times 2 and 3, and only 3
aircraft are allowed to enter S2 between times 3 and 5. Variables Vi represent the expected
departure times of ights; variables Vj0 are S1 and S2 the expected entry times (S1 and S2
are the only constrained sectors so only those variables are necessary).
8.4.2
clp(FD)
Model
The slot allocation problem under capacity constraints can be modelled using 3 types of
constraints:
1. Domain constraints on departure time variables: we saw that a CLP variable corresponding to the departure time is associated with each ight; in order to satisfy
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
181
capacity constraints, the departure of a ight can be delayed, up to 3 hours (= 180
min, during our experiments).
Each departure time variable will have to satisfy the following constraint:
Vi in EETi;1 ::EETi;1 + max delay
where Vi is the departure time variable of ight Fi and EETi;1 is the constant corresponding to the requested time of the ight (see 2.2 and 4.2).
2. relations between sector entry time variables and departure time variables: for each
capacity constraint, a variable is created for a ight if the entering time in the rst
sector Si of its route SRj that belongs to A (where A is the constraint group of
sectors - possibly a singleton) is within T (the constraint period) - see 4.1 and 4.2.
Therefore, we set a new constraint on each of these variables V 0, as follows:
V 0# = V + where V is the departure time and is the time the ight needs to reach the sector
Si (translation constant).
3.
constraints: nally, each capacity constraint is modelled using an
atmost_interval constraint, dened in 3.5. Its arguments are the capacity, the list
of the variables identied in step 2, and the bounds of the constraint period interval
(see 3.5 and 4.1).
atmost_interval
This model is interesting because of its simplicity and transparency: since a ight can
cross many sectors, it can be aected by several atmost_interval constraints. Regulators
speak about \combining" restrictions but it is dicult for them to evaluate the eects of
such restrictions. Such an overlapping problem is modelled in a transparent way. Another
interest of our model is its extensibility: for instance, it would be obvious to aect a distinct
delay to ights if we considered that some special ights could not be delayed.
8.4.3
clp(FD)
Implementation of our Small Example
The clp(FD) implementation of the small problem presented in 4.3 is provided in table 40.
The solution found by clp(FD) to this problem is S 1 = fV 1 = 2; V 2 = 3; V 3 = 6; V 4 = 4g.
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
182
Solution([V1, V2, V3, V4]) :V1 in 2..12,
V2 in 3..13,
V3 in 6..16,
V4 in 2..12,
V'11 #= V1+1,
V'21 #= V2,
V'41 #= V4,
V'12 #= V1+2,
V'22 #= V2+2,
V'32 #= V3,
V'42 #= V4+3,
atmost interval(2, [V'11, V'21, V'41], 2, 3),
atmost interval(3, [V'12, V'22, V'32, V'42], 3, 5),
labeling([V1, V2, V3, V4]).
Tableau 40 : implementation of our small problem with clp(FD) constraints
Flights 1, 2 and 3 can take-o at their requested time, while ight 4 undergoes a 2 unitof-time delay.
8.4.4 Optimization Trials - Heuristics
To solve real cases, we needed to implement some heuristics that we describe in the three
points here below:
1. labeling strategy: clp(FD) labeling works on a list of variables L and backtracks rst
on the last element of L, then on the last but one and so on. This has a shortcoming:
a solution of average delay d1 can be labeled before a solution of average delay d2 with
d2 d1. In our small example, the solution S 2 = fV 1 = 2; V 2 = 4; V 3 = 6; V 4 = 2g
is not found whereas it is better in term of average delay than S 1. For that reason,
we have implemented a new labeling strategy that enumerates solutions in the order
of increasing average delays. The solution S 2 is encountered by such a labeling before
S 1. But we could not use this labeling in practical examples because it is too slow
to nd a solution. To solve practical problems, we have used an heuristic that leads
clp(FD) labeling to nd a good solution rst. It consists rst in ordering take-o
variables in L: the lower bound of the domain of an element i of L is always less than
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
183
or equal to the lower bound of the domain of its successor in L. The second part of
the heuristic consists in setting constraints according to an increasing order among
the beginning of their application period. Thanks to this heuristic, clp(FD) nds a
solution that minimizes the average delay;
2. time granularity: the variable domains have bounds from 0 to 1440 (number of minutes of a day); if we allow ights to be delayed up to 3 hours, domains can contain
180 values. Those size considerations can be redhibitory in practical examples (see
the size of such examples in next section). So, to reduce memory size model, we have
chosen to divide all variables and domain bounds by a \time granularity" that can
be 5 or 10 minutes (or else);
3. discrete approach: because of the number of variables and constraints involved, it
is dicult to treat a day taken as a whole. So, we have cut it in slices of 4 hours:
when a ight is delayed by the constraints of a slice, its maximum delay is reduced
accordingly.
8.4.5 Results
Figures 22 and 23 show trac histograms of UM sector before and after the clp(FD)
process: Fig. 22 depicts an overload between 10a.m. and 11a.m. while Fig. 23 has absorbed
it.
Table 41 provides some runtime characteristics: the total number of variables is equal to the
sum of the number of \indomain" constraints and of the number of \equality" constraints.
was processed on a pattern containing about 100 days of a year. This proves a
certain stability with regard to the density of the trac. When no solution is found, we
decrease the period length and/or increase the maximum delay that can be undergone by
a ight.
clp(FD)
To conclude this subsection, we can underline the fact that dealing only with capacity
constraints to make slot allocation has some weaknesses: delays are distributed among all
ights without any discrimination. So, if a regulation plan were created in such a way, it
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
Figure 22 : UM trac before CLP process
Figure 23 : UM trac after CLP process
184
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
period
length (h)
3
4
5
5
6
3
10
runtime average
delay
(among
delayed
ights)
003900
200300
400800
004400
104200
error
error
average
delay
(among
all
ights)
max
delay
delayed
ights
(p.c.)
number
of
indom.
constr.
numer
of
atmost
constr.
19:160 5:380 500
18:830 4:450 550
17:500 1:900 500
25:780 10:200 750
5:730 2:510 160
28:10
23:64
10:88
39:58
43:80
957
1184
1397
815
1071
814
1761
193
256
320
218
282
199
393
number
of
equality
constr.
13031
21700
29006
12069
19269
9967
40187
185
number
of
ights
4714
4714
4714
4714
4714
4714
4714
Tableau 41 : some runtime examples
would have been impossible to adapt the restrictions to last minute changes during the
real time supervision phase. Hereafter, we describe an extension of the model seen so far
which permits to organize delays in a fairly manner. It corresponds to the way French ow
managers work.
8.4.6 Extension of the Model to Integrate Flow Rate Constraints
Flow Constraint Denition.
A ow constraint (called in Europe a \regulation") is a relation between a trac ow
F , a temporal period T and a rate N=t (N is the maximum number of aircraft that
can feed the ow each t minutes). F can be dened by a set of origins and/or a set of
destinations and/or a set of beacons and/or a set of sectors and/or a ight level layer.
Those properties of a ow are the characteristics that a ight must fulll to be submitted
to the ow constraint.
Generic example of ow constraint:
from SetOfOrigins entering GroupOfSectors
h1 - h2 : N /t
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
186
Instantiated example of ow constraint:
from UK to Balearic
10am - 11am : 1/8
The constraint is satised if during T , there are at most N ights belonging to F per slice
of t-minute width.
clp(FD)
Model.
We can detail the 3 types of constraints shown in 4.4 that are necessary to model the
extension to ow rate constraints:
1. domain constraints on departure time variables: this step is identical to the rst step
dened in 4.4;
2. relations between sector entry time variables and departure time variables: capacity
constraints are modelled in the same way than in 4.4; for each ow constraint, a
variable V 0 that corresponds to the adequate instant is created for a ight if the
ight belongs to the constrained ow and \reaches" the constraint (at instant V 0)
within T . \Reaches" means that we will be interested in dierent instants of the ight
according to the constraint type. This instant can be a sector entry time, a beacon
over-ying time, a departure or arrival time. Except this, step 2 is identical to the
second step above-mentioned in 4.4;
3.
atmost_interval
in 4.4;
constraints: this step is identical to the third step above-mentioned
As we can see, the integration of ow rate constraints is very natural. This illustrates the
declarativity and extensibility of our model.
CHAPITRE 8. REGULATION DU TRAFIC AERIEN AVEC CLP(FD)
187
8.4.7 A Simulation Aid Tool for Regulators - Cost estimation
of Regulation Plans
Whatever the point of view may be, either local or global, regulators cannot have a precise
idea of the eects of restrictions on trac ows they impose because of the very large
volume of data, the great interdependency between sectors, and the complexity of the air
route network.
The interest of a simulation aid tool is to let the prominent r^ole and the nal choice to
the regulators when they have at their disposal the cost estimation of a regulation plan
provided by clp(FD). Cost estimation can integrate criteria such as the average or maximum delay, the number of delayed ights, the number and duration of planned restrictions,
the average number of restrictions aecting a ight, the dierence between demand and
capacity (it allows to save a security margin for imponderables). Such a tool can help them
to avoid imposing unnecessary restrictions on ows. Our work has been integrated into the
simulation aid tool SPORT (from which we have provided hardcopies in this paper). This
integration has been easy to do because clp(FD) allows to obtain a C runtime program.
8.5 Conclusion and Further Works
This paper has shown how CLP is well adapted to solve ATFM problems such as departure
slot allocation satisfying dierent types of constraints. Describing a possible extension of
this practical application (ow rate regulation), we have highlighted expressiveness and
exibility of the CLP approach. It seems that numerous ATFM applications can benet
from CLP advantages. Among them, we will now investigate other applications like rerouting, automatic search of ow rate regulations, evaluation of a capacity change cost,
evaluation of ow constraints cost. The eciency of clp(FD) language gives us a good
hope to realize interesting further works.
CHAPITRE 9. CONCLUSION
189
CHAPITRE 9. CONCLUSION
190
Annexe A
Programme crypta
/*----------------------------------------------------------------------*/
/* Benchmark (Finite Domain)
INRIA Rocquencourt - ChLoE Project */
/*
*/
/* Name
: crypta.pl
*/
/* Title
: crypt-arithmetic
*/
/* Original Source: P. Van Hentenryck's book
*/
/* Adapted by
: Daniel Diaz - INRIA France
*/
/* Date
: September 1992
*/
/*
*/
/* Solve the operation:
*/
/*
*/
/*
B A I J J A J I I A H F C F E B B J E A
*/
/* + D H F G A B C D I D B I F F A G F E J E
*/
/* ----------------------------------------*/
/* = G J E G A C D D H F A F J B F I H E E F
*/
/*
*/
/* Solution:
*/
/* [A,B,C,D,E,F,G,H,I,J]
*/
/* [1,2,3,4,5,6,7,8,9,0]
*/
/*----------------------------------------------------------------------*/
crypta(LD):fd_vector_max(9),
LD=[A,B,C,D,E,F,G,H,I,J],
alldifferent(LD),
domain(LD,0,9),
191
ANNEXE A. PROGRAMME CRYPTA
domain([Sr1,Sr2],0,1),
B in 1..9,
D in 1..9,
G in 1..9,
A+10*E+100*J+1000*B+10000*B+100000*E+1000000*F+
E+10*J+100*E+1000*F+10000*G+100000*A+1000000*F
#= F+10*E+100*E+1000*H+10000*I+100000*F+1000000*B+10000000*Sr1,
C+10*F+100*H+1000*A+10000*I+100000*I+1000000*J+
F+10*I+100*B+1000*D+10000*I+100000*D+1000000*C+Sr1
#= J+10*F+100*A+1000*F+10000*H+100000*D+1000000*D+10000000*Sr2,
A+10*J+100*J+1000*I+10000*A+100000*B+
B+10*A+100*G+1000*F+10000*H+100000*D+Sr2
#= C+10*A+100*G+1000*E+10000*J+100000*G,
labeling(LD).
192
Annexe B
Programme eq10
/*----------------------------------------------------------------------*/
/* Benchmark (Finite Domain)
INRIA Rocquencourt - ChLoE Project */
/*
*/
/* Name
: eq10.pl
*/
/* Title
: linear equations
*/
/* Original Source: Thomson LCR
*/
/* Adapted by
: Daniel Diaz - INRIA France
*/
/* Date
: September 1992
*/
/*
*/
/* A system involving 7 variables and 10 equations
*/
/*
*/
/* Solution:
*/
/* [X1,X2,X3,X4,X5,X6,X7]
*/
/* [ 6, 0, 8, 4, 9, 3, 9]
*/
/*----------------------------------------------------------------------*/
eq10(Lab):LD = [X1,X2,X3,X4,X5,X6,X7],
domain(LD,0,10),
0+98527*X1+34588*X2+5872*X3+59422*X5+65159*X7
#= 1547604+30704*X4+29649*X6,
0+98957*X2+83634*X3+69966*X4+62038*X5+37164*X6+85413*X7
#= 1823553+93989*X1,
900032+10949*X1+77761*X2+67052*X5
193
ANNEXE B. PROGRAMME EQ10
#= 0+80197*X3+61944*X4+92964*X6+44550*X7,
0+73947*X1+84391*X3+81310*X5
#= 1164380+96253*X2+44247*X4+70582*X6+33054*X7,
0+13057*X3+42253*X4+77527*X5+96552*X7
#= 1185471+60152*X1+21103*X2+97932*X6,
1394152+66920*X1+55679*X4
#= 0+64234*X2+65337*X3+45581*X5+67707*X6+98038*X7,
0+68550*X1+27886*X2+31716*X3+73597*X4+38835*X7
#= 279091+88963*X5+76391*X6,
0+76132*X2+71860*X3+22770*X4+68211*X5+78587*X6
#= 480923+48224*X1+82817*X7,
519878+94198*X2+87234*X3+37498*X4
#= 0+71583*X1+25728*X5+25495*X6+70023*X7,
361921+78693*X1+38592*X5+38478*X6
#= 0+94129*X2+43188*X3+82528*X4+69025*X7,
labeling(LD).
194
Annexe C
Programme eq20
/*----------------------------------------------------------------------*/
/* Benchmark (Finite Domain)
INRIA Rocquencourt - ChLoE Project */
/*
*/
/* Name
: eq20.pl
*/
/* Title
: linear equations
*/
/* Original Source: Thomson LCR
*/
/* Adapted by
: Daniel Diaz - INRIA France
*/
/* Date
: September 1992
*/
/*
*/
/* A system involving 7 variables and 20 equations
*/
/*
*/
/* Solution:
*/
/* [X1,X2,X3,X4,X5,X6,X7]
*/
/* [ 1, 4, 6, 6, 6, 3, 1]
*/
/*----------------------------------------------------------------------*/
eq20(LD):LD = [X1,X2,X3,X4,X5,X6,X7],
domain(LD,0,10),
876370+16105*X1+6704*X3+68610*X6
#= 0+62397*X2+43340*X4+95100*X5+58301*X7,
533909+96722*X5
#= 0+51637*X1+67761*X2+95951*X3+3834*X4+59190*X6+15280*X7,
915683+34121*X2+33488*X7
195
ANNEXE C. PROGRAMME EQ20
#= 0+1671*X1+10763*X3+80609*X4+42532*X5+93520*X6,
129768+11119*X2+38875*X4+14413*X5+29234*X6
#= 0+71202*X1+73017*X3+72370*X7,
752447+58412*X2
#= 0+8874*X1+73947*X3+17147*X4+62335*X5+16005*X6+8632*X7,
90614+18810*X3+48219*X4+79785*X7
#= 0+85268*X1+54180*X2+6013*X5+78169*X6,
1198280+45086*X1+4578*X3
#= 0+51830*X2+96120*X4+21231*X5+97919*X6+65651*X7,
18465+64919*X1+59624*X4+75542*X5+47935*X7
#= 0+80460*X2+90840*X3+25145*X6,
0+43525*X2+92298*X3+58630*X4+92590*X5
#= 1503588+43277*X1+9372*X6+60227*X7,
0+47385*X2+97715*X3+69028*X5+76212*X6
#= 1244857+16835*X1+12640*X4+81102*X7,
0+31227*X2+93951*X3+73889*X4+81526*X5+68026*X7
#= 1410723+60301*X1+72702*X6,
0+94016*X1+35961*X3+66597*X4
#= 25334+82071*X2+30705*X5+44404*X6+38304*X7,
0+84750*X2+21239*X4+81675*X5
#= 277271+67456*X1+51553*X3+99395*X6+4254*X7,
0+29958*X2+57308*X3+48789*X4+4657*X6+34539*X7
#= 249912+85698*X1+78219*X5,
0+85176*X1+57898*X4+15883*X5+50547*X6+83287*X7
#= 373854+95332*X2+1268*X3,
0+87758*X2+19346*X4+70072*X5+44529*X7
#= 740061+10343*X1+11782*X3+36991*X6,
0+49149*X1+52871*X2+56728*X4
#= 146074+7132*X3+33576*X5+49530*X6+62089*X7,
196
ANNEXE C. PROGRAMME EQ20
0+29475*X2+34421*X3+62646*X5+29278*X6
#= 251591+60113*X1+76870*X4+15212*X7,
22167+29101*X2+5513*X3+21219*X4
#= 0+87059*X1+22128*X5+7276*X6+57308*X7,
821228+76706*X1+48614*X6+41906*X7
#= 0+98205*X2+23445*X3+67921*X4+24111*X5,
labeling(LD).
197
Annexe D
Programme alpha
/*----------------------------------------------------------------------*/
/* Benchmark (Finite Domain)
INRIA Rocquencourt - ChLoE Project */
/*
*/
/* Name
: alpha.pl
*/
/* Title
: alphacipher
*/
/* Original Source: Daniel Diaz - INRIA France
*/
/* Adapted by
:
*/
/* Date
: January 1993
*/
/*
*/
/* This problem comes from the news group rec.puzzle.
*/
/* The numbers 1 - 26 have been randomly assigned to the letters of the */
/* alphabet. The numbers beside each word are the total of the values
*/
/* assigned to the letters in the word. e.g for LYRE L,Y,R,E might equal*/
/* 5,9,20 and 13 respectively or any other combination that add up to 47*/
/* Find the value of each letter under the equations:
*/
/*
*/
/*
BALLET 45
GLEE 66
POLKA
59
SONG
61
*/
/*
CELLO
43
JAZZ 58
QUARTET
50
SOPRANO 82
*/
/*
CONCERT 74
LYRE 47
SAXOPHONE 134
THEME
72
*/
/*
FLUTE
30
OBOE 53
SCALE
51
VIOLIN 100
*/
/*
FUGUE
50
OPERA 65
SOLO
37
WALTZ
34
*/
/*
*/
/* Solution:
*/
/*[A, B,C, D, E,F, G, H, I, J, K,L,M, N, O, P,Q, R, S,T,U, V,W, X, Y, Z]*/
/*[5,13,9,16,20,4,24,21,25,17,23,2,8,12,10,19,7,11,15,3,1,26,6,22,14,18]*/
/*----------------------------------------------------------------------*/
198
ANNEXE D. PROGRAMME ALPHA
alpha(LD):fd_vector_max(26),
LD=[A,B,C,_D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z],
alldifferent(LD),
domain(LD,1,26),
B+A+L+L+E+T
C+E+L+L+O
C+O+N+C+E+R+T
F+L+U+T+E
F+U+G+U+E
G+L+E+E
J+A+Z+Z
L+Y+R+E
O+B+O+E
O+P+E+R+A
P+O+L+K+A
Q+U+A+R+T+E+T
S+A+X+O+P+H+O+N+E
S+C+A+L+E
S+O+L+O
S+O+N+G
S+O+P+R+A+N+O
T+H+E+M+E
V+I+O+L+I+N
W+A+L+T+Z
%
labeling(LD).
labelingff(LD).
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
#=
45,
43,
74,
30,
50,
66,
58,
47,
53,
65,
59,
50,
134,
51,
37,
61,
82,
72,
100,
34,
199
Annexe E
Programme queens
/*----------------------------------------------------------------------*/
/* Benchmark (Finite Domain)
INRIA Rocquencourt - ChLoE Project */
/*
*/
/* Name
: queens.pl
*/
/* Title
: N-queens problem
*/
/* Original Source: P. Van Hentenryck's book
*/
/* Adapted by
: Daniel Diaz - INRIA France
*/
/* Date
: January 1993
*/
/*
*/
/* Put N queens on an NxN chessboard so that there is no couple of
*/
/* queens threatening each other.
*/
/*
*/
/* Solution:
*/
/* N=4 [2,4,1,3]
*/
/* N=8 [1,5,8,6,3,7,2,4]
*/
/* N=16 [1,3,5,2,13,9,14,12,15,6,16,7,4,11,8,10]
*/
/*----------------------------------------------------------------------*/
queens(N,L):fd_vector_max(N),
length(L,N),
domain(L,1,N),
safe(L),
labeling(L).
%
labelingff(L).
200
ANNEXE E. PROGRAMME QUEENS
safe([]).
safe([X|L]):noattack(L,X,1),
safe(L).
noattack([],_,_).
noattack([Y|L],X,I):diff(X,Y,I),
I1 is I+1,
noattack(L,X,I1).
diff(X,Y,I):X in -{val(Y)} & -{val(Y)-I} & -{val(Y)+I},
Y in -{val(X)} & -{val(X)-I} & -{val(X)+I}.
201
Annexe F
Programme ve
/*----------------------------------------------------------------------*/
/* Benchmark (Finite Domain)
INRIA Rocquencourt - ChLoE Project */
/*
*/
/* Name
: five.pl
*/
/* Title
: five house puzzle
*/
/* Original Source: P. Van Hentenryck's book
*/
/* Adapted by
: Daniel Diaz - INRIA France
*/
/* Date
: September 1992
*/
/*
*/
/* A logic puzzle
*/
/*
*/
/* Solution:
*/
/* [N1,N2,N3,N4,N5,
[3,4,5,2,1,
*/
/*
C1,C2,C3,C4,C5,
5,3,1,2,4,
*/
/*
P1,P2,P3,P4,P5,
5,1,4,2,3,
*/
/*
A1,A2,A3,A4,A5,
4,5,1,3,2,
*/
/*
D1,D2,D3,D4,D5]
4,1,2,5,3]
*/
/*----------------------------------------------------------------------*/
five_house(L):fd_vector_max(5),
L=[N1,N2,N3,N4,N5,
C1,C2,C3,C4,C5,
P1,P2,P3,P4,P5,
A1,A2,A3,A4,A5,
D1,D2,D3,D4,D5],
202
ANNEXE F. PROGRAMME FIVE
domain(L,1,5),
N5 #= 1,
D5 #= 3,
alldifferent([C1,C2,C3,C4,C5]),
alldifferent([P1,P2,P3,P4,P5]),
alldifferent([N1,N2,N3,N4,N5]),
alldifferent([A1,A2,A3,A4,A5]),
alldifferent([D1,D2,D3,D4,D5]),
N1
N2
N3
N4
P3
C1
P5
P2
C1
#=
#=
#=
#=
#=
#=
#=
#=
#=
C2,
A1,
P1,
D3,
D1,
D4,
A4,
C3,
C5+1,
plus_or_minus(A3,P4,1),
plus_or_minus(A5,P2,1),
plus_or_minus(N5,C4,1),
labeling(L).
% partial lookahead
plus_or_minus(X,Y,C):X #= Y+C.
plus_or_minus(X,Y,C):X+C #= Y.
% constructive disjunction and partial lookahead
/*
plus_or_minus(X,Y,C):X in min(Y)+C..max(Y)+C:min(Y)-C..max(Y)-C,
Y in min(X)+C..max(X)+C:min(X)-C..max(X)-C.
*/
203
Annexe G
Programme cars
/*----------------------------------------------------------------------*/
/* Benchmark (Finite Domain)
INRIA Rocquencourt - ChLoE Project */
/*
*/
/* Name
: cars.pl
*/
/* Title
: car sequencing problem
*/
/* Original Source: Dincbas, Simonis and Van Hentenryck
*/
/* Adapted by
: Daniel Diaz - INRIA France
*/
/* Date
: September 1992
*/
/*
*/
/* Car sequencing problem with 10 cars
*/
/* Solution:
*/
/*
[1,2,6,3,5,4,4,5,3,6]
*/
/*
[1,3,6,2,5,4,3,5,4,6]
*/
/*
[1,3,6,2,6,4,5,3,4,5]
*/
/*
[5,4,3,5,4,6,2,6,3,1]
*/
/*
[6,3,5,4,4,5,3,6,2,1]
*/
/*
[6,4,5,3,4,5,2,6,3,1]
*/
/*
*/
/*----------------------------------------------------------------------*/
cars(X):fd_vector_max(6),
X=[X1,X2,X3,X4,X5,X6,X7,X8,X9,X10],
Y=[O11,O12,O13,O14,O15,
O21,O22,O23,O24,O25,
O31,O32,O33,O34,O35,
204
ANNEXE G. PROGRAMME CARS
O41,O42,O43,O44,O45,
O51,O52,O53,O54,O55,
O61,O62,O63,O64,O65,
O71,O72,O73,O74,O75,
O81,O82,O83,O84,O85,
O91,O92,O93,O94,O95,
O101,O102,O103,O104,O105],
L1=[1,0,0,0,1,1],
L2=[0,0,1,1,0,1],
L3=[1,0,0,0,1,0],
L4=[1,1,0,1,0,0],
L5=[0,0,1,0,0,0],
domain(Y,0,1),
domain(X,1,6),
205
206
ANNEXE G. PROGRAMME CARS
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
2
2
2
2
2
2
1
1
1
1
1
1
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
#>=
O21+O31,
O31+O41,
O41+O51,
O51+O61,
O61+O71,
O71+O81,
O81+O91,
O91+O101,
O12+O22+O32,
O22+O32+O42,
O32+O42+O52,
O42+O52+O62,
O52+O62+O72,
O62+O72+O82,
O72+O82+O92,
O82+O92+O102,
O13+O23+O33,
O23+O33+O43,
O33+O43+O53,
O43+O53+O63,
O53+O63+O73,
O63+O73+O83,
O73+O83+O93,
O83+O93+O103,
O14+O24+O34+O44+O54,
O24+O34+O44+O54+O64,
O34+O44+O54+O64+O74,
O44+O54+O64+O74+O84,
O54+O64+O74+O84+O94,
O64+O74+O84+O94+O104,
O15+O25+O35+O45+O55,
O25+O35+O45+O55+O65,
O35+O45+O55+O65+O75,
O45+O55+O65+O75+O85,
O55+O65+O75+O85+O95,
O65+O75+O85+O95+O105,
O11+O21+O31+O41+O51+O61+O71+O81 #>= 4,
207
ANNEXE G. PROGRAMME CARS
208
O11+O21+O31+O41+O51+O61
O11+O21+O31+O41
O11+O21
#>= 3,
#>= 2,
#>= 1,
O12+O22+O32+O42+O52+O62+O72
O12+O22+O32+O42
O12
#>= 4,
#>= 2,
#>= 0,
O13+O23+O33+O43+O53+O63+O73
O13+O23+O33+O43
O13
#>= 2,
#>= 1,
#>= 0,
O14+O24+O34+O44+O54
#>= 2,
O15+O25+O35+O45+O55
#>= 1,
labeling(X).
Annexe H
Programme bridge
/*----------------------------------------------------------------------*/
/* Benchmark (Finite Domain)
INRIA Rocquencourt - ChLoE Project */
/*
*/
/* Name
: bridge.pl
*/
/* Title
: bridge scheduling problem
*/
/* Original Source: P. Van Hentenryck's book and
*/
/*
COSYTEC (vers. of "Overview of a CHIP Compiler")
*/
/* Adapted by
: Daniel Diaz - INRIA France
*/
/* Date
: October 1994
*/
/*
*/
/* Find a scheduling that minimizes the time to build a 5-segment bridge*/
/*
*/
/* Solution:
*/
/*
*/
/* Optimal (End=104)
*/
/*
*/
/*[[start,0,0],[a1,4,3],[a2,2,13],[a3,2,7],[a4,2,15],[a5,2,1],[a6,5,38],*/
/*[p1,20,9],[p2,13,29],[ue,10,0],[s1,8,10],[s2,4,18],[s3,4,29],[s4,4,42]*/
/*[s5,4,6],[s6,10,46],[b1,1,18],[b2,1,22],[b3,1,33],[b4,1,46],[b5,1,10],*/
/*[b6,1,56],[ab1,1,19],[ab2,1,23],[ab3,1,34],[ab4,1,47],[ab5,1,11],
*/
/*[ab6,1,57],[m1,16,20],[m2,8,36],[m3,8,44],[m4,8,52],[m5,8,12],
*/
/*[m6,20,60],[l1,2,30],[t1,12,44],[t2,12,56],[t3,12,68],[t4,12,92],
*/
/*[t5,12,80],[ua,10,78],[v1,15,56],[v2,10,92],[k1,0,42],[k2,0,80],
*/
/*[stop,0,104]]
*/
/*----------------------------------------------------------------------*/
bridge(K,Ende):-
209
ANNEXE H. PROGRAMME BRIDGE
210
setup(K,Ende,Disj),
minof(choice(Disj,K),Ende).
setup(K,Ende,Disj):jobs(L),
make_vars(L,K),
member([stop,_,Ende],K),
precedence(M),
make_precedence(M,K),
max_nf(M1),
make_max_nf(M1,K),
max_ef(M2),
make_max_ef(M2,K),
min_af(M3),
make_min_af(M3,K),
min_sf(M4),
make_min_sf(M4,K),
min_nf(M5),
make_min_nf(M5,K),
resources(R),
make_disj(R,K,[],Disj1),
reverse(Disj1,Disj).
choice(Disj,K):disjunct(Disj),
label(K).
make_vars([],[]).
make_vars([H|T],[[H,D,A]|R]):duration(H,D),
A in 0..200,
make_vars(T,R).
make_precedence([],_).
make_precedence([[A,B]|R],L):member([A,Ad,Aa],L),
member([B,Bd,Ba],L),
greatereqc(Ba,Aa,Ad),
make_precedence(R,L).
make_max_nf([],_).
% Ba #>= Aa+Ad,
ANNEXE H. PROGRAMME BRIDGE
make_max_nf([[A,B,C]|R],L):member([A,Ad,Aa],L),
member([B,Bd,Ba],L),
C1 is C + Ad,
smallereqc(Ba,Aa,C1),
make_max_nf(R,L).
make_max_ef([],_).
make_max_ef([[A,B,C]|R],L):member([A,Ad,Aa],L),
member([B,Bd,Ba],L),
C1 is Ad + C - Bd,
smallereqc(Ba,Aa,C1),
make_max_ef(R,L).
make_min_af([],_).
make_min_af([[A,B,C]|R],L):member([A,Ad,Aa],L),
member([B,Bd,Ba],L),
greatereqc(Ba,Aa,C),
make_min_af(R,L).
make_min_sf([],_).
make_min_sf([[A,B,C]|R],L):member([A,Ad,Aa],L),
member([B,Bd,Ba],L),
C1 is C - Bd,
smallereqc(Ba,Aa,C1),
make_min_sf(R,L).
make_min_nf([],_).
make_min_nf([[A,B,C]|R],L):member([A,Ad,Aa],L),
member([B,Bd,Ba],L),
C1 is C + Ad,
greatereqc(Ba,Ad,C1),
make_min_nf(R,L).
make_disj([],R,D,D).
make_disj([[H,R]|T],K,Din,Dout):el_list(R,K,R1),
make_disj1(R1,Din,D1),
make_disj(T,K,D1,Dout).
211
% Ba #<= Aa+C1,
% Ba #<= Aa+C1,
% Ba #>= Aa+C,
% Ba #<= Aa+C1,
% Ba #>= Ad+C1,
ANNEXE H. PROGRAMME BRIDGE
212
make_disj1([],D,D).
make_disj1([H|T],Din,Dout):make_disj2(H,T,Din,D1),
make_disj1(T,D1,Dout).
make_disj2(H,[],D,D).
make_disj2([A,B],[[C,D]|S],Din,Dout):make_disj2([A,B],S,[[A,B,C,D]|Din],Dout).
el_list([],_,[]).
el_list([H|T],L,[[A,D]|S]):member([H,D,A],L),
el_list(T,L,S).
disjunct([]).
disjunct([[A,B,C,D]|R]):disj(A,B,C,D),
disjunct(R).
disj(Aa,Ad,Ba,Bd):greatereqc(Ba,Aa,Ad).
% Ba #>= Aa+Ad.
disj(Aa,Ad,Ba,Bd):greatereqc(Aa,Ba,Bd).
% Aa #>= Ba+Bd.
label([]).
label([[A,Ad,Aa]|R]):indomain(Aa),
label(R).
/* constraint definitions */
smallereqc(X,Y,C):X in 0
..max(Y)+C,
Y in min(X)-C..infinity.
% X #<= Y+C
ANNEXE H. PROGRAMME BRIDGE
greatereqc(X,Y,C):X in min(Y)+C..infinity,
Y in 0
..max(X)-C.
213
% X #>= Y+C.
/*
DATA
ANNEXE H. PROGRAMME BRIDGE
duration(ab2,1).
duration(ab3,1).
duration(ab4,1).
duration(ab5,1).
duration(ab6,1).
duration(m1,16).
duration(m2,8).
duration(m3,8).
duration(m4,8).
duration(m5,8).
duration(m6,20).
duration(l1,2).
duration(t1,12).
duration(t2,12).
duration(t3,12).
duration(t4,12).
duration(t5,12).
duration(ua,10).
duration(v1,15).
duration(v2,10).
duration(k1,0).
duration(k2,0).
duration(stop,0).
precedence([[start,a1],[start,a2],[start,a3],[start,a4],[start,a5],
[start,a6],[start,ue],[a1,s1],[a2,s2],[a5,s5],
[a6,s6],[a3,p1],[a4,p2],[p1,s3],[p2,s4],
[p1,k1],[p2,k1],[s1,b1],[s2,b2],
[s3,b3],[s4,b4],[s5,b5],[s6,b6],[b1,ab1],
[b2,ab2],[b3,ab3],[b4,ab4],[b5,ab5],[b6,ab6],
[ab1,m1],[ab2,m2],[ab3,m3],[ab4,m4],[ab5,m5],
[ab6,m6],[m1,t1],[m2,t1],[m2,t2],[m3,t2],
[m3,t3],[m4,t3],[m4,t4],[m5,t4],[m5,t5],
[m6,t5],[m1,k2],[m2,k2],[m3,k2],[m4,k2],
[m5,k2],[m6,k2],[l1,t1],[l1,t2],[l1,t3],
[l1,t4],[l1,t5],[t1,v1],[t5,v2],[t2,stop],
[t3,stop],[t4,stop],[v1,stop],[v2,stop],[ua,stop],
[k2,stop]]).
max_nf([[start,l1,30],[a1,s1,3],[a2,s2,3],[a5,s5,3],
[a6,s6,3],[p1,s3,3],[p2,s4,3]]).
min_sf([[ua,m1,2],[ua,m2,2],[ua,m3,2],[ua,m4,2],
214
resources([[crane,[l1,t1,t2,t3,t4,t5]],
[bricklaying,[m1,m2,m3,m4,m5,m6]],
[schal,[s1,s2,s3,s4,s5,s6]],
[excavator,[a1,a2,a3,a4,a5,a6]],
[ram,[p1,p2]],
[pump,[b1,b2,b3,b4,b5,b6]],
[caterpillar,[v1,v2]]]).
215
Annexe I
Manuel d'utilisation de wamcc
wamcc 2.21
User's Manual
July 1994
This manual is based on DECsystem-10 Prolog User's Manual by D.L.
Bowen, L. Byrd, F.C.N. Pereira, L.M. Pereira, D.H.D. Warren
and on SICStus Prolog User's Manual by Mats Carlsson
216
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
217
I.1 Using wamcc - Modularity
is a Prolog compiler which translates Prolog to C via the WAM (Warren Abstract
Machine). A Prolog le will give rise to a C source le which will be compiled by gcc.
Several Prolog les can be compiled separately and linked by the loader to provide a Unix
executable. A prolog le is a module. It is possible (and recommended) to split a big
application into several little modules. Each module has its own independent predicate
name space. This is an important feature for the development of larger programs. The
module system of wamcc Prolog is procedure based. This means that only the predicates
are local to a module, whereas terms are global. The module system is at, not hierarchical,
so all modules are visible to one another. No overhead is incurred on compiled calls to
predicates in other modules. Each predicate in the Prolog system, whether built-in or
user dened, belongs to a module. By default, a predicate is generally only visible in the
module where it is dened (i.e. private predicate) except if this predicate has been declared
as public (see directive :- public below). Public predicates are visible in every modules. A
public predicate can be locally redened in any module. There is a particular module: the
main module corresponding to the module containing the main program1 (see directives
:- main below). At run-time only public predicates and private predicates dened in the
main module will be visible under the top level. wamcc also supports dynamic predicates
which are interpreted (see section I.3.8).
wamcc
The following directives are specially handled at compile-time:
:- public Pred1 /Arity1 , ..., Predn /Arityn .
This directive species that each Predi /Arityi is a public predicate.
:- dynamic Pred1 /Arity1 , ..., Predn /Arityn .
This directive species that each Predi /Arityi is a dynamic predicate (see section I.3.8 for dynamic code facilities).
:- main.
:- main(+Modules).
1
The main module will contain the C funtion main().
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
218
:- main(+Modules,+Stacks).
This directive species the current module is the main module. Modules is the list
of needed modules (omitted if there are no other modules). Stacks is a list of stack
parameters of the form stack(+Name,+EnvVarName,+Size). Name is the stack name
(see section I.4). EnvVarName is the name of the environment variable to consult at
run-time to read the size of the stack. If EnvVarName is the empty atom (i.e. '')
no environment variable will be consulted at run-time for this stack. Size is the
default stack size in Kbytes (if the variable EnvVarName is not dened at run-time).
If there is not any denition for a stack stack name the default environment variable
is stack nameSZ in upper case (see also section I.2.4).
Note that other directives are not executed at compile-time but they are compiled into
special code which will be executed at run-time2 . More precisely, at run-time, all directives
of each module dened in Modules are executed then the directives of the main module
are executed. When the main module is compiled, a directive is added to invoke the top
level (see top level/2 in section I.3.5). If several directives are dened in a same module,
they will be executed in the same order as they appear in the Prolog le.
Example:
x.pl
y.pl
z.pl
:- main([y,z]).
:- public odd/1.
:- public p/1.
:- public even/1.
odd(s(X)):- even(X).
p(X):- u(X).
even(0).
:- public q/1.
u(b).
even(s(X)):- odd(X).
q(X):- p(X).
:- write(r).
p(a).
:- write(q1).
:- write(q2).
s(X):- q(X).
:- p(X), write(X).
:- s(X), write(X).
The only exception concerns operator declarations op/3 which are both executed at compile-time and
run-time.
2
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
219
At run-time:
exec directive goal
1 of y
write(q1)
2 of y
write(q2)
1 of z
write(r)
r
1 of x
2 of x
3 of x
p(X), write(X)
s(X), write(X)
top level(true,true)
a
b
...
The order in which directives are executed is: directives of y.pl, directives of z.pl
and then directives of x.pl.
In the module x.pl the public predicate p/1 has been redened so the directive p(X),
will print a. However, the directive s(X), write(X) will print b since in
y.pl only the public declaration of p/1 in z.pl is visible.
write(X)
Under the top-level, the query
will succed with X=a. The query q(X)
will succeed with X=b, the query u(X) will fail since only private predicates dened
in x.pl can be called from the top-level. The query even(X) will generate all even
natural numbers through backtraking.
| ?- p(X)
I.2 From Prolog modules to Unix Executables
I.2.1 Compiling Prolog Modules
The wamcc compiler is entirely written in wamcc Prolog (and compiled with wamcc). It
allows the user to compile one or several Prolog Modules. The general syntax of wamcc is
as follows:
wamcc [option | filename]...
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
-c
-wam
-fast math
-no test stack
-no inline
-dbg
-dbg2
-v
-h
220
produce a .c le
produce a .wam le
do not test types in math expressions
do not test types in math expressions
do not include code to test stack overow
compile for prolog debugging
compile for prolog and wam debugging
verbose mode
display help
Remarks:
if wamcc is invoked without any arguments then a (classical) Prolog top level is called.
by default the compilation proceeds in C mode. When a Prolog Module prog.pl is
compiled in C mode, wamcc generates the following les:
a header le (variable declarations,...)
prog.c the C source le
prog.usr a user le. In this le the user can add his own C code to interface with
Prolog via pragma c/1 inline predicate. This le is generated if it does not exist
otherwise it is left unchanged.
prog.h
With the -wam options, wamcc generates a prog.wam le in a Prolog syntax.
the -fast math option makes it possible to generate faster code since no type checking is done for variables appearing in mathemetic expressions (they are assumed
to contain integers).
the -dbg and -dbg2 options produce additional information for debugging (see also
section I.4).
the -no inline option is useful when debugging since it allows the user to trace inline
predicates. An inline predicate, is a predicate which does not give rise to a classical
Prolog call and thus it is not visible by the debugger. The -no inline option allows
the user to trace calls to inline predicates as well.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
221
the no test stack is only useful for architecture which cannot test stack overows
by hardware (e.g. Sony Mips, NeXT stations). On these machines, tests are done by
software and are quite expensive. With this option, overows are not checked and
thus the program runs faster. However, overows are not detected.
if the -v option is not specied wamcc runs silently.
wamcc
returns 0 if the compilation has succeeded and 1 otherwise.
I.2.2 Generating Object Files
From the C les generated by wamcc it is possible to obtain an object le using the GNU
C compiler. A shell-script w gcc3 can also is provided t make this compilation. w gcc only
invokes gcc with some necessary appropriate options (like -Ipath...)4 . w gcc can be used
as simple as the C compiler. The following sequence generates a le prog.o from the Prolog
le prog.pl:
%wamcc prog -fast math
%w gcc -c -O2 prog.c
I.2.3 Linking Object Files
From one or several object les prog1 .o, ..., progn .o it is possible to generate an executable
simply by invoking w gcc with these les as follows:
%w gcc -o prog prog1
:o
... progn
:o
-lwamcc
The command will create the executable prog by linking all object les prog[1-n].o. A
library containing the run-time and the built-in predicates must be provided via the option
-llibrary. There are two libraries available libwamcc.a and libwamcc pp.a. The former
is the standard library while the later allows the user to obtaind prole information when
quiting the program.
3
4
the name of this shell script is w C compiler name.
so if wamcc is moved from one directory to another one, w gcc must be edited to update the pathnames.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
hex2pl
222
and pl2hex Utilities
At compile-time, each predicate gives rise to a C identier which is the hexadecimal representation of the predicate. At linking-time, if a symbol is multiply dened or not dened the
linker will emit a message involving the hexadecimal name of the predicate. Two utilities
are provided to allow the user to translate in both directions Prolog atoms and hexadecimal
representations:
%pl2hex
prolog name (Prolog to hexadecimal)
Example: pl2hex
%hex2pl
displays X617070656E64 3.
hexa name (hexadecimal to Prolog)
Example: hex2pl
X617070656E64 3
will display append/3.
I.2.4 Stack Overow Messages
When one stack overows, wamcc exits with the following message: \Fatal Error: stack name
stack overow (size:current size Kb, env. variable: env var name)" where stack name is
the name of the stack which has overowed, current size is its actual size in Kbytes and
env var name is the name of the environment variable which is consulted to dene the size
of this stack. You can then (re)dene this variable (e.g. with the Unix setenv command)
and reexecute the program (see also directive :- main in section I.1).
I.2.5 Makele Generator - bmf wamcc Utility
In order to simplify the overall compilation process, it is possible to dene makeles.
A simple program bmf wamcc (Build Make File) provides a way to dene automatically
makeles. The obtained makele can be customized if necessary. The general syntax of
bmf wamcc is as follows:
bmf wamcc [option | filename]...
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
223
choose file as main module (default: rst module)
use pflags for the wamcc compiler
use pflags for the w gcc compiler (default: -O2)
use pflags for the linker (default: -s)
verbose mode
display help
A filename is a module name (possibly suxed .pl), another object le (.o) or an archive
le (.a).
This command creates a makele main module.mk.
-o
-P
-C
-L
-v
-h
file
pflags
cflags
cflags
For instance, to create the executable x corresponding to the example given in section I.1:
%bmf wamcc x y z -v
This creates the makele x.mk. The following command then (re)creates the executable x:
%make -f x.mk
Each makele generated by bmf wamcc can (re)create a prole executable whose name is
executable name pp5 . For instance the following command will create the executable x pp:
%make -f x.mk x pp
I.3 Built-in Predicates
I.3.1 Input / Output
DEC-10 Prolog File Input/Output
The set of le manipulation predicates is inherited from DEC-10 Prolog. The le
represents the terminal.
see(+File)
The le File becomes the current input.
seeing(?File)
File
5 ... pp
is unied with the name of the current input.
stands for Prolog prole.
user
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
seen
224
Closes the current input and resets it to user.
tell(+File)
The le File becomes the current output.
telling(?File)
File
told
is unied with the name of the current output.
Closes the current output and resets it to user.
Characted Input/Output
nl
A new line is started on the current output.
get0(?N)
is the characted code of the next character read from the current input. On end of
le N is -1.
N
get(?N)
is the characted code of the next character that is not a layout characted read from
the current input.
N
skip(+N)
Skips just past the next character code
arithmetic expression.
put(+N)
The character code
expression.
tab(+N)
N
N
N
from the current input.
is output onto the current output.
N
N
may be an
may be an arithmetic
spaces are output onto the current output. N may be an arithmetic expression.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
225
Input and Output of Terms
read line(?X)
Reads characters from the current input until a NEWLINE character is read. The
NEWLINE character is discarded and the result is an atom. Fails if the end of the le
is encountered.
read word(?X)
Skips leading separator characters and reads characters from the current input until a
separator character is reached (but not read). Fails if the end of the le is encountered.
read integer(?X)
Skips leading separator characters and reads the next integer from the current input.
Fails if the end of the le is encountered.
read(?Term)
The next term delimited by a full-stop is read from the current input. When the end
of the le is reached, Term is unied with the term end of file.
read term(?Term,+Options)
Same as read/1 with a list of options. Options is a list of :
variables(?Vars)
Vars
is bound to a list of variables of Term.
variable names(?Names)
is bound to a list Name=Var pairs where each Name is an atom indicating
the name of a non-anonymous variable in the term and Var is the corresponding
variable.
Names
singletons(?Names)
is bound to a list Name=Var pairs, one for each non-anonymous variable
only appearing once in the term.
Name
syntax errors(+Val)
controls what action to take on syntax errors. Possible values are : dec10 (the
syntax error is reported and read is repeated), error (an exception is raised),
fail (the error is reported and the read fails), quiet (the read quietly fails).
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
226
write(?Term)
The term Term is written onto the current output according to the current operator
declaration.
write canonical(?Term)
Similar to write(Term) but the term is written according to the standard syntax.
The output can be parsed by read/1.
writeq(?Term)
Similar to write(Term) but the names of atoms ans functors are quoted where necessary.
write term(+Term,+Options)
Same as write/1 with a list of options (Bool is either false or true):
quoted(Bool)
If selected, functors are quoted where necessary to make the result acceptable
as input to read/1.
ignore ops(+Bool)
If selected, Term is written in standard parenthesized notation instead of using
operators.
numbervars(+Bool)
If selected, occurrences of '$VAR'(I) where I is an integer >= 0 are written as
(A + (I mod 26))(I/26). For I=0,... you get the variable names A,B,..., Z, A1,
B1, etc.
max depth(N)
Depth limit on printing. N is an integer. -1 (the default) means no limit.
format(+Format,+Arguments)
Print Arguments onto the current output according to format Format. Format is a
list of formatting characters. format/2 and format/3 is a Prolog interface to the C
stdio function printf(). It is due to Quintus/Sicstus Prolog.
Arguments is a list of items to be printed. If there is only one item it may be supplied
as an atom. If there are no items then an empty list should be supplied.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
227
The default action on a format character is to print it. The character ~and % introduce
a control sequence. To print a ~or a % repeat it.
The general format of a control sequence is ~NC. The character C determines the type
of the control sequence. N is an optional numeric argument. An alternative form of
N is *. * implies that the next argument in Arguments should be used as a numeric
argument in the control sequence.
The following control sequences are available.
The argument is an atom. The atom is printed without quoting.
~Nc The argument is a number that will be interpreted as a character code. N defaults
to one and is interpreted as the number of times to print the character.
~Nd The argument is an integer. N is interpreted as the number of digits after the
decimal point. If N is 0 or missing, no decimal point will be printed.
~ND The argument is an integer. Identical to ~Nd except that , will separate groups
of three digits to the left of the decimal point.
~Nr The argument is an integer. N is interpreted as a radix. N should be >= 2 and
<= 36. If N is missing the radix defaults to 8. The letters a-z will denote digits
larger than 9.
~NR The argument is an integer. Identical to ~Nr except that the letters A-Z will
denote digits larger than 9.
~Ns The argument is a list of character codes. Exactly N characters will be printed.
N defaults to the length of the string.
~i The argument, which may be of any type, is ignored.
~k The argument, which may be of any type, will be passed to write canonical/1.
~q The argument may be of any type. The argument will be passed to writeq/1.
~w The argument may be of any type. The argument will be passed to write/1.
~~ Takes no argument. Prints ~.
~Nn Takes no argument. Prints N newlines. N defaults to 1.
~? The argument is an atom and is considered as the current format (indirection).
Example:
~a
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
228
format("month: ~?, year: ~?",['~a',january,'~d',1994]).
%F
will print: month: january, year: 1994.
F is a C printf format for integers and atoms (i.e. C integer and C strings).
Example: format("%02d %3.3s %4d",[1,january,1994]).
will print: 01 jan 1994.
formata(+Format,+Arguments)
Like
format/2
format/2).
but
Format
is an atom and
Arguments
must be a list (faster than
Pretty-prints the clause Clause onto the current output (used by listing/1).
pp clause(+Head,?Body)
Like pp clause((Head
:- Body)).
I.3.2 Arithmetic
Arithmetic is performed by built-in predicates which take as argument arithmetic expressions and evaluate them. An arithmetic expression is a term built from the numbers,
variables and functors that represent arithmetic functions. When an arithmetic expression
is evaluated, each variable must be bound to an arithmetic expression. However, if you use
the option -fast math then the compiler assumes that each variable will be bound to an
integer and does not check its type.
The range of integers are [-2^28,+2^28-1]. Floats are not supported in this version.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
+(X)
X
-X
X+Y
X-Y
X*Y
X//Y
X mod Y
X/\Y
X\/Y
X^Y
\(X)
X<<Y
X>>Y
[X]
229
negative of X
sum of X and Y
dierence of X and Y
product of X and Y
integer quotient of X and Y
integer remainder after dividing X by Y
bitwise and of X and Y
bitwise or of X and Y
bitwise exclusive or of X and Y
bitwise not of X
X shifted left by Y places
X shifted right by Y places
a list of one number X evaluates to X
Arithmetic expressions are just Prolog terms. If you want one evaluated you must pass
it as an argument to one of the following built-in (where X and Y stand for arithmetic
expressions and Z for some term).
(inline predicate)
X is evaluated and the value is unied with Z.
Z is X
(inline predicate)
X is equal to Y.
X=:=Y
n (inline predicate)
X= =Y
X
X<Y
(inline predicate)
X is less than Y.
X=<Y
X>Y
is not equal to Y.
(inline predicate)
X is less than or equal to Y.
(inline predicate)
X is greater than Y.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
X>=Y
230
(inline predicate)
X is greater than or equal to Y.
I.3.3 Term Management
Term Comparison
The predicates make references to a standard total ordering which is as follows:
Variables in standard order (roughly oldest rst).
Integers in numeric order.
Atoms in alphabetic order.
Compound term, ordered rst by the arity, then by the name of the principal functor,
then by the arguments (in left-to-right order). Recall that lists are equivalent to
compound terms with principal ./2.
For the following predicates X and Y are terms.
(inline predicate)
Compares X and Y and unies Op with =, < or >.
compare(?Op,?X,?Y)
X==Y
n
(inline predicate)
X is literally equal to Y.
(inline predicate)
X is not literally equal to Y.
X ==Y
X@<Y
(inline predicate)
X is literally less than Y.
(inline predicate)
X is literally less than or equal to Y.
X@=<Y
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
X@>Y
231
(inline predicate)
X is literally greater than Y.
(inline predicate)
X is literally greater than or equal to Y.
X@>=Y
Some further predicates involving comparison of terms are:
sort(+L1,?L2)
The elements of the list L1 are sorted into the total orderer and any identical elements
are merged yielding the list L2 (complexity: O(N log N ) where N is the length of
L1).
keysort(+L1,?L2)
The list L1 must consist of items of the form Key-Value. These items are sorted into
order according to the value of Key yielding the list L2. No merging takes place and
this predicate is stable (if K-A occurs before K-B then K-A will take place before K-B
in the output). (complexity: O(N log N ) where N is the length of L1).
Constant Processing
There are 3 ways of representing character-string data:
Atoms (e.g. 'Hello
World').
Atoms are stored in the symbol table (a hash-table).
Lists of one-character atoms (e.g. [H,e,l,l,o,'
',w,o,r,l,d]).
Strings (e.g. \Hello World") where a string is a list of numeric codes
(e.g. [72,101,108,108,111,32,87,111,114,108,100]).
atom length(+Atom,?Length)
Length of Atom is Length.
atom concat(?Atom1,?Atom2,+Atom3)
atom concat(+Atom1,+Atom2,-Atom3)
Concatenes Atom1 and Atom2 to give Atom3.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
232
sub atom(+Atom,?Start,?Length,?Atom1)
The subatom of Atom beginning at the Startth character and Length characters long
is Atom1.
char code(+Char,?Code)
char code(?Char,+Code)
Unies the character Char with its the character code Code.
Interconverts the list of chars Chars with the list of corresponding character codes
Codes.
atom codes(+Atom,?Codes)
atom codes(?Atom,+Codes)
Interconverts Atom with the corresponding list of character codes Codes.
atom chars(+Atom,?Chars)
atom chars(?Atom,+Chars)
Interconverts Atom with the corresponding list of characters Chars.
number atom(+Number,?Atom)
number atom(?Number,+Atom)
Interconverts Atom with the corresponding number Number.
number codes(+Number,?Codes)
number codes(?Number,+Codes)
Interconverts Number with the corresponding list of character codes Codes.
number chars(+Number,?Chars)
number chars(?Number,+Chars)
Interconverts Number with the corresponding list of characters Chars.
name(+X,?Codes)
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
233
name(?X,+Codes)
If X is an atom, equivalent to atom codes(X,Codes). If X is a number, equivalent to
number codes(X,Codes). If X is uninstantiated, if Codes can be interpreted as a number X is unied with that number otherwise with the atom whose name corresponds
to Codes.
Term Processing
(inline predicate)
Unies Term1 and Term2.
?Term1=?Term2
functor(+Term,?Name,?Arity)
(inline predicate)
The principal functor of term Term has name Name and arity Arity, where Name is
either an atom or, provided Arity is 0, an integer. Initially, either Term must be
instantiated, or Name and Arity must be instantiated to, respectively, either an atom
and an integer in [0..255] or an atomic term and 0. In the case where Term is initially
uninstantiated, the result of the call is to instantiate Term to the most general term
having the principal functor indicated.
functor(?Term,+Name,+Arity)
(inline predicate)
Initially, ArgNo must be instantiated to a positive integer and Term to a compound
term. The result of the call is to unify Arg with the argument ArgNo of term Term.
The arguments are numbered from 1 upwards.
arg(+ArgNo,+Term,?Arg)
+Term =.. ?List
(inline predicate)
List is a list whose head is the atom corresponding to the principal functor of Term,
and whose tail is a list of the arguments of Term. If Term is uninstantiated, then List
must be instantiated either to a list of determinate length whose head is an atom, or
to a list of length 1 whose head is a number. Note that this predicate is not strictly
necessary, since its functionality can be provided by arg/3 and functor/3, and using
the latter two is usually more ecient.
?Term =.. +List
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
234
copy term(?Term,?CopyOfTerm)
is a renaming of Term, such that brand new variables have been substituted for all variables in Term.
CopyOfTerm
setarg(+ArgNo,+CompoundTerm,?NewArg)
Replaces destructively argument ArgNo in CompoundTerm with NewArg and undoes it
on backtracking. This should only used if there is no further use of the \old" value
of the replaced argument.
numbervars(?Term,+N,?M)
Unies each of the variables in term Term with a special term '$VAR'(i) where i
ranges from N to M-1 (see write/1 or writeq/1). This predicate is used by listing/1.
I.3.4 Test Predicates
The following test the type of the term X:
(inline predicate)
Tests whether X is currently uninstantiated (var is short for variable). An uninstantiated variable is one which has not been bound to anything, except possibly another
uninstantiated variable.
var(?X)
(inline predicate)
Tests whether X is currently instantiated. This is the opposite of var/1.
nonvar(?X)
(inline predicate)
Checks that X is currently instantiated to an atom (i.e. a non-variable term of arity
0, other than a number).
atom(?X)
(inline predicate)
Checks that X is currently instantiated to an integer.
integer(?X)
(inline predicate)
Checks that X is currently instantiated to a number (i.e. an integer).
number(?X)
(inline predicate)
Checks that X is currently instantiated to an atom or number.
atomic(?X)
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
235
(inline predicate)
Checks that X is currently instantiated to a term of arity > 0 i.e. a list or a structure.
compound(?X)
(inline predicate)
Checks that X is currently instantiated to a callable term (i.e. an atom or a compound
term).
callable(?X)
I.3.5 Control
+P , +Q
Prove P and if it succeeds, then prove Q.
+P ; +Q
Prove P or if it fails (or if the continuation fails), prove Q instead of P.
!
n+
The eect of the cut symbol is as follows. When rst encountered as a goal, cut
succeeds immediately. If backtracking should later return to the cut, the eect is to
fail the parent goal, i.e. that goal which matched the head of the clause containing
the cut, and caused the clause to be activated.
+P
If the goal P has a solution, fail, otherwise succeed. This is not real negation (\P is
false"), but a kind of pseudo-negation meaning \P is not provable".
+P -> +Q ; +R
Analogous to \if P then
solution to the goal P.
+P -> +Q
Equivalent to (P
else R" This form of if-then-else only explores the rst
otherwise
true
Q
These always succeed.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
236
false
fail
These always fail.
repeat
Generates an innite sequence of backtracking choices.
for(I,A,B)
Generates, on backtracking, values for I ranging from A to B.
call(+Term)
must be instantiated to a term (which would be acceptable as the body of
a clause). The goal call(Term) is then executed exactly as if that term appeared
textually in its place, except that any cut (!) occurring in Term only cuts alternatives
in the execution of Term.
Term
halt(+Status)
halt
Terminates the Prolog process with the status
halt(0).
Status. halt/0
is a shorthand for
halt or else(+Program,+Status)
halt or else(+Program)
Same as halt(Status) if there is a top level else same as call(Program).
abort
Stops the current goal and returns under the top level if exists or exits with the status
1.
catch(+Goal,?Catcher,+Recovery)
throw(?Ball)
calls Goal. If this succeeds or fails, so does the call to catch/3. If however,
during the execution of Goal, there is a call to throw(Ball) (i.e. an exception is
raised), then Ball is copied and the stack is unwound back to the call to catch/3,
whereupon the copy of Ball is unied with Catcher. If this unication succeeds,
catch/3
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
237
then catch/3 calls the goal Recovery (a handler) in order to determine the success
or failure of catch/3. Otherwise, the stack keeps unwinding, looking for an earlier
invocation of catch/3.
I.3.6 List Processing
The following predicates are inspired from the lists library of SICStus Prolog. The following predicates are available:
append(?Prefix,?Suffix,?Combined)
is true when Combined is the combined list of the elements in Prefix followed by
the elements in Suffix. It can be used to form Combined or it can be used to nd
Prefix and/or Suffix from a given Combined.
member(?Element,?List)
is true when Element is a member of List. It may be used to test for membership
in a list, but it can also be used to enumerate all the elements in List.
memberchk(+Element,+List)
is true when Element is a member of List, but memberchk/2 only succeeds once and
can therefore not be used to enumerate the elements in List.
reverse(?List,?Reversed)
is true when Reversed has the same elements as List but in a reversed order.
delete(+List,+Element,?Residue)
is true when Residue is the result of removing all identical occurrences of Element
in List.
is true when the result of removing an occurrence of Element in List is List2.
permutation(?List,?Perm)
is true when Perm is a permutation of List.
prefix(?Prefix,?List)
is true when Prefix is a prex of List.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
238
is true when Suffix is a sux of List.
sublist(?Sub,?List)
is true when Sub contains some of the elements of List.
last(?List,?Last)
is true when Last is the last element in List.
length(?List,?Length)
If List is instantiated to a list of determinate length, then Length will be unied
with this length. If List is of indeterminate length and Length is instantiated to an
integer, then List will be unied with a list of length Length. The list elements are
unique variables. If Length is unbound then Length will be unied with all possible
lengths of List.
nth(?N,?List,?Element)
nth/3
1.
is true when Element is the Nth element of List. The rst element is number
max list(+ListOfNumbers,?Max)
is true when Max is the largest of the elements in ListOfNumbers.
min list(+ListOfNumbers,?Min)
is true when Min is the smallest of the numbers in the list ListOfNumbers.
sum list(+ListOfNumbers,?Sum)
is true when Sum is the result of adding the ListOfNumbers together.
I.3.7 Operators
op(+Precedence,+Type,+Name)
Declares the atom Name to be an operator of the stated Type and Precedence. Name
may also be a list of atoms in which case all of them are declared to be operators. If
Precedence is 0 then the operator properties of Name (if any) are cancelled.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
239
I.3.8 Modication of the Program
allows for dynamic code, i.e. code which can be considered as data. This allows the
user to add and retract clauses dynamically and to consult programs which is very useful
when debugging since this avoid to recompile the code. A dynamic predicate is either a
predicate which has been declared with the directive :- dynamic or a predicate whose
rst clause has been dynamically created (asserted). In this version dynamic code is always
public (can be seen by any module). Note that a static predicate (i.e. compiled predicate)
cannot be redened by a dynamic predicate.
wamcc
For the predicates dened below, the argument Head must be instantiated to an atom or a
compound term. The argument Clause must be instantiated either to a term Head :- Body
or, if the body part is empty, to Head. An empty body part is represented as true.
asserta(+Clause)
The current instance of Clause is interpreted as a clause and is added to the current
interpreted program as the rst clause. The predicate concerned must be currently be
dynamic or undened. Any uninstantiated variables in the Clause will be replaced
by new private variables.
assertz(+Clause)
Like asserta/2, except that the new clause becomes the last clause for the predicate
concerned.
clause(+Head,?Body)
The clause Head :- Body exists in the current interpreted program. The predicate
concerned must currently be dynamic. clause/2 may be used in a non-determinate
fashion, i.e. it will successively nd clauses matching the argument through backtracking.
retract(+Clause)
The rst clause in the current interpreted program that matches Clause is erased. The
predicate concerned must currently be dynamic. retract/1 may be used in a nondeterminate fashion, i.e. it will successively retract clauses matching the argument
through backtracking.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
240
reinit predicate(+Name/+Arity)
Erase all clauses of the predicate specied by Name/Arity. The predicate denition
is retained.
abolish(+Name/+Arity)
Erase all clauses of the predicate specied by Name/Arity. The predicate denition
is also erased.
listing(+Name/+Arity)
Lists the interpreted predicate(s) specied by Name/Arity Any variables in the listed
clauses are internally bound to ground terms before printing.
consult(+Files)
Consults source les. Files is either the name of a le or a list of lenames. Note
that it is possible to call consult(user) and then enter a clauses directly on the
terminal (ending with ^D).
When a directive is read it is immediately executed. Any predicate dened in the
les erases any clauses for that predicate already present in the interpreter. Recall
that a static predicate cannot be redened by an interpreted predicate.
[File|Files]
shorthand for consult([File|Files]).
I.3.9 All Solutions
When there are many solutions to a problem, and when all those solutions are required to be
collected together, this can be achieved by repeatedly backtracking and gradually building
up a list of the solutions. The following built-in predicates are provided to automate this
process.
setof(?Template,+Goal,?Set)
Read this as \Set is the set of all instances of Template such that Goal is satised, where that set is non-empty". The term Goal species a goal or goals as in
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
241
call(Goal). Set
is a set of terms represented as a list of those terms, without duplicates, in the standard order for terms (see section I.3.3). If there are no instances
of Template such that Goal is satised then the predicate fails.
The variables appearing in the term Template should not appear anywhere else in
the clause except within the term Goal. Obviously, the set to be enumerated should
be nite, and should be enumerable by Prolog in nite time. It is possible for the
provable instances to contain variables, but in this case the list Set will only provide
an imperfect representation of what is in reality an innite set.
If there are uninstantiated variables in Goal which do not also appear in Template,
then a call to this built-in predicate may backtrack, generating alternative values for
Set corresponding to dierent instantiations of the free variables of Goal. (It is to
cater for such usage that the set Set is constrained to be non-empty.) Two instantiations are dierent i no renaming of variables can make them literally identical.
Variables occurring in Goal will not be treated as free if they are explicitly bound
within Goal by an existential quantier. An existential quantication is written Y^Q
meaning \there exists a Y such that Q is true", where Y is some Prolog variable.
bagof(?Template,+Goal,?Bag)
This is exactly the same as setof/3 except that the list (or alternative lists) returned
will not be ordered, and may contain duplicates. The eect of this relaxation is to
save a call to sort/2, which is invoked by setof/3 to return an ordered list.
findall(?Template,+Goal,?Bag)
is a list of instances of Template in all proofs of Goal found by Prolog. The
order of the list corresponds to the order in which the proofs are found. The list may
be empty and all variables are taken as being existentially quantied. This means
that each invocation of findall/3 succeeds exactly once, and that no variables in
Goal get bound. Avoiding the management of universally quantied variables can
save considerable time and space.
Bag
findall(?Template,+Goal,?Bag,?Remainder)
Same as
findall/3,
except that Bag is the list of solution instances appended to
Remainder, which is typically unbound.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
242
I.3.10 Global Variables
provides a simple and powerful way to assign and read global variables. There are
3 kinds of objects which can be associated to a global variable:
wamcc
a copy of a term,
a link to a term,
an array of objects.
The initial value of a global variable is the integer 0. A global variable is referenced by a
name (i.e. name = an atom) possibly indiced if it is an array (i.e. name = a compound
term). In the following, GVarName represents such a reference to a global variable and its
syntax is as follows:
GVarName ::=
atom
atom(Index,...,Index)
Index
integer
GVarName
::=
When a GVarName is used as an index, the value of this variable must be an integer. Indexes
range from 0 to Size-1 if the array has Size elements.
The space necessary for copies and arrays are allocated dynamically and recovered as soon
as possible. For instance, when an atom is associated to a global variable whose current
value is an array, the space for this array is recovered (unless if the assignment must be
undone when backtracking occurs, see below).
(inline predicate)
Associates a copy of the term Term to GVarName. This assignment is not undone when
backtracking occurs. See below about array (re)denitions.
g assign(+GVarName,+Term)
(inline predicate)
Same as g assign/2 but the assignment is undone when backtraking occurs. See
below about array (re)denitions.
g assignb(+GVarName,+Term)
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
243
(inline predicate)
Makes a link between GVarName to the term Term. This allows the user to give a name
to any Prolog term (in particular non-ground terms). Note that such an assignment
is always undone when backtracking occurs (since the term could no longer exists).
Note also that if Term is an atom or an integer, g link and g assignb have the same
behavior. Finally: g link is not expansive at all neither for the memory nor for the
execution time point of views. See below about array (re)denitions.
g link(+GVarName,+Term)
(inline predicate)
Unies Term with the associated value of GVarName. See below about array readings.
g read(+GVarName,?Term)
(inline predicate)
Unies Size with the dimension (an integer > 0) of the array stored by GVarName.
Fails if GVarName is not an array.
g array size(+GVarName,?Size)
The predicates g assign/2, g assignb/2 and g link/2 dene an array when Term is a
compound term with principal functor g array/1-2. Then an array is assigned to GVarName
(backtrackable assignment or not depending on the predicate used). There are 3 forms for
the term g array/1-2:
g array(+Size)
if Size is an integer > 0 then denes an array of Size elements which are all initialized with the integer 0 w.r.t to the predicate used (g assign/2, g assignb/2 or
g link/2).
g array(+Size,+Term)
As above but the elements are initialized with the term Term instead of 0. Note that
Term can contain other array denitions allowing thus for multi-dimensional arrays.
g array(+ListOfElements)
As above if ListOfElements is a list of length Size except that the elements of the
array are initialized w.r.t the elements of the list ListOfElements (which can contain
other array denitions).
The compound term with principal functor g array extend/1-2 can can be used similarly
to g array/1-2 except that is does not initialize existing elements of the (possibly) previous
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
244
array.
When an array is read, a term of the form g array([Elem0 ,...,ElemSize
1 ])
is returned.
Example: a simple counter:
| ?- [user].
inc(Var,Value):- g_read(Var,Value), X is Value+1, g_assign(Var,X).
^D
yes
| ?- inc(a,X).
X = 0
yes
| ?- inc(a,X).
X = 1
yes
Example: g assign does not undo its assignment at backtracking whereas g assignb undoes it.
| ?-
g_assign(x,1),
(
g_read(x,Old), g_assign(x,2)
;
g_read(x,Old), g_assign(x,3)
).
Old = 1 ? ;
Old = 2
yes
| ?-
% the value 2 has not been undone
g_assign(x,1),
(
g_read(x,Old), g_assignb(x,2)
;
g_read(x,Old), g_assignb(x,3)
).
Old = 1 ? ;
Old = 1
yes
% the value 2 has been undone
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
245
Example: g assign and g assignb create a copy of the term whereas g link does not.
g link can often avoid to pass big data structures (e.g. dictionnaries,...) as arguments of
many predicates.
| ?- g_assign(foo,f(X)), X=12, g_read(foo,Y).
X = 12
Y = f(_60)
yes
| ?- g_link(foo,f(X)), X=12, g_read(foo,Y).
X = 12
Y = f(12)
yes
Example: array denitions.
| ?- g_assign(w,g_array(3)), g_read(w,X).
X = g_array([0,0,0])
| ?- g_assign(w(0),16), g_assign(w(1),32), g_assign(w(2),64),
g_read(w,X).
X = g_array([16,32,64])
yes
| ?- g_assign(k,g_array([16,32,64])), g_read(k,X).
X = g_array([16,32,64])
yes
| ?- g_assign(k,g_array(3,null)), g_read(k,X).
X = g_array([null,null,null])
yes
Example: array extension.
| ?- g_assign(a,g_array([10,20,30])), g_read(a,X).
X = g_array([10,20,30])
% simpler
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
246
yes
| ?- g_assign(a,g_array_extend(5,null)), g_read(a,X).
X = g_array([10,20,30,null,null])
yes
| ?- g_assign(a,g_array([10,20,30])), g_read(a,X).
X = g_array([10,20,30])
yes
| ?- g_assign(a,g_array_extend([1,2,3,4,5,6])),
g_read(a,X).
X = g_array([10,20,30,4,5,6])
yes
Example: 2-D array denition.
| ?- g_assign(w,g_array(2,g_array(3))), g_read(w,X).
X = g_array([g_array([0,0,0]),g_array([0,0,0])])
yes
| ?- (
for(I,0,1), for(J,0,2), K is I*3+J, g_assign(w(I,J),K),
fail
;
g_read(w,X)
).
X = g_array([g_array([0,1,2]),g_array([3,4,5])])
yes
| ?- g_read(w(1),X).
X = g_array([3,4,5])
yes
Example: hybrid array.
| ?- g_assign(w,g_array([1,2,g_array([a,b,c]),g_array(2,z),5])),
g_read(w,X).
X = g_array([1,2,g_array([a,b,c]),g_array([z,z]),5])
yes
| ?- g_read(w(1),X), g_read(w(2,1),Y), g_read(w(3,1),Z).
X = 2
Y = b
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
247
Z = z
yes
| ?- g_read(w(1,2),X).
Error: Illegal array index <2> for <w>
I.3.11 Miscellaneous
(inline predicate)
Inserts at compile-time the C code Code in the resulting C le. The use of this
predicates requires a good knowledge of the underlying Prolog engine6 .
pragma c(+Code)
statistics
Displays on the terminal statistics relating to memory usage and run time.
statistics(?Key,?Value)
This allows a program to gather various execution statistics. For each of the possible
keys Key, Value is unied with a list of values, as follows:
stack name
runtime
systime
[Size used,Size free] in bytes
stack name : local, global, trail
[Since start,Since last] in ms
[Since start,Since last] in ms
cputime(?T)
similar to statistics(runtime,[T|
]).
version
Displays the introductory banner.
top level(+BannerBool,+CatchBool)
invokes a (sub) top level. BannerBool is true or false and indicates if the introductory banner must be displayed at the invocation. CatchBool indicates if the exceptions raised by throw/1 which are not captured must be captured by top level (which
simply write the Ball sent by throw/1 between curly brackets). If CatchBool is false
6
do not hesitate to contact the author for more low-level information.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
248
then the (sub) top level ends, the exception is still raised and should be captured by
an other handler. The global variable '$top level' counts the number of nested top
levels actually alive (can be used to test if a top level is active).
gensym(?X)
gensym(+Prefix,+X)
Generates an atom of the form Prefixk where k is the current value of the global
variable Prefix (so it must be an integer). This value is then incremented for the
next call to gensym. if Prefix is omitted then '$sym' is used.
compiler name(?X)
Unies X with the name of the compiler.
wam version(?X)
Unies X with the current version.
wam year(?X)
Unies X with the year of the current version.
argc(?X)
Unies X with the number of Unix arguments (of the command-line).
argv(+N,X)
Unies X with the Nth Unix argument (starting at 0). (see also Unix(argv(L))).
Unix(+Term)
Allows certain interactions with the operating system. Under Unix the possible forms
of Term are as follows:
access(+Path,+Mode)
Tests if Mode is the accessability of Path as in the C-function access(2).
argv(?Args)
Args
cd
is unied with a list of atoms of the program arguments.
Changes the current working directory to the home directory.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
249
cd(+Path)
Changes the current working directory to Path.
exit(+Status)
Terminates the Prolog process with the status Status. (Equivalent to halt/1).
getenv(+Name,?Value)
Unies Value with the value of the environment variable Name.
shell
Starts a new interactive Unix shell named in the Unix environment variable
SHELL. The control is returned to Prolog upon termination of the shell.
shell(+Command)
Passes
to a new Unix shell named in the Unix environment variable
SHELL for execution.
Command
shell(+Command,?Status)
Passes
to a new Unix shell named in the Unix environment variable
SHELL for execution. Unies Status with the returned status of Command.
Command
system(+Command)
Passes Command to a new Unix sh process for execution.
system(+Command,?Status)
Passes Command to a new Unix sh process for execution. Unies
the returned status of Command.
Status
with
I.4 Debugger
The debugger is based on the procedure box model as described in Chapter eight of Programming in Prolog by W.F. Clocksin and C.S. Mellish (Springer-Verlag, 1981) which is
recommended as an introduction. The proposed debug options are similar to those provided by SICStus or Quintus. The debugger can be used for interpreted code (i.e. dynamic
predicates) or for compiled code (i.e. static predicates) compiled with the -dbg option. The
wam debugger is only available for static code compiled with the -dbg2 option. The basic
built-in predicates to control the debugger are as follows
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
250
debug
Switches the debugger on (showing spy-points).
nodebug
Switches the debugger o.
debugging
Prints onto the terminal information about the current debugging state.
trace
Switches the debugger on (showing everything).
leash(+Mode)
Leashing Mode is set to Mode. Mode is a list whose elements can be call, exit, fail
or redo.
notrace
Equivalent to nodebug/0.
spy +Name/+Arity
Sets a spy-point on the predicate whose principal functor is Name and arity is Arity.
nospy +Name/+Arity
Removes the spy-point from the predicate whose principal functor is Name and arity
is Arity.
nospyall
Removes all spy-points that have been set.
During the debugging, the trace messages look like:
S I J Port: Goal ?
where S is a spy-point indicator and is + if there is a spy-point on the predicate Goal (or else
S is ' '). N is an invocation number. This unique number can be used to cross correlate the
trace messages for the various ports, since it is unique for every invocation. M is an indice
number which represents the number of direct ancestors this goal has. Port species the
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
251
particular port (call, exit, fail, redo). Goal is the current goal. The ? indicates that
you should type in one of the following debug commands7 :
creep
or RET
Single-steps to the very next port.
skip <n>
Skips over the execution of predicates called by the current goal. If you specify an
invocation number (less or greater than the current one) then the execution continues
until the goal whose indice number is n is reached.
leap
Resumes running your program, only stopping when a spy-point is reached.
abort
Aborts the current execution.
goals
or goalsb
Prints the list of ancestors to the current goal. goalsb also prints the remainding
choice-points.
leash <l>...
Sets the leashing mode to
(similar to leash/1).
nobebug
l1 ... lk
where each
li
is
or
redo
or notrace
Switches the debugger o.
=
Prints onto the terminal information about the current debugging state (similar to
debugging/0).
+ <pred/arity>
Sets a spy-point on the current goal or on the goal whose principal functor is pred
and arity arity (similar to spy/1).
7
only the rst character(s) of the commands are required, and <
x >
denotes an optional element.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
252
- <pred/arity>
Removes the spy-point from the current goal or from the goal whose principal functor
is pred and arity arity (similar to nospy/1).
< <n>
Sets the printdepth limit to n or resets it to 10 if n is not specied.
exact
In this mode all failures are traced.
noexact
In this mode failures occuring when unifying the head are not traced (like in SICStus/Quitus).
help
Displays a summarize of the options displayed above.
There are also some low-level (i.e. WAM level) commands (only available for static code
compiled with the -dbg2 option):
write adr <n>
Uses write/1 to print n Prolog terms starting at adr.
data adr <n>
Displays (dump) n words starting at adr.
modify adr <n>
Displays (dump) and makes it possible to modify n words starting at adr.
where sadr
Displays the real address corresponding to sadr.
deref adr
Displays the dereferenced word located at adr.
envir <sadr>
Diplays the current environment or the one located at sadr.
ANNEXE I. MANUEL D'UTILISATION DE WAMCC
253
backtrack <sadr>
Diplays the current choice point or the one located at sadr.
An address (adr) has the following syntax: bank name < [n] >. A stack address has the
following syntax: stack name < [n] >. bank name can be one of the following name and
n is an optional oset specier (integer):
bank name ::=
reg
x
y
stack name
stack name::=
local
global
trail
WAM general registers
WAM temporaries
current permanent variables
a stack
local stack
global stack
trail stack
User's Manual
July 1994
This manual only concerns the nite domain constraint facilities.
Refer to wamcc User's manual for information about the underlying
Prolog engine.
254
ANNEXE J. MANUEL D'UTILISATION DE CLP(FD)
255
J.1 Introduction
is based on the wamcc Prolog compiler and extends it with Finite Domain (FD)
constraints. It is recommended to read the wamcc User's Manual [21] which explains how
to use the underlying Prolog language (built-in predicates, compilation process,...). In this
manual some executable names have changed for clp(FD). The folowing table shows the
correspondance between old (i.e. wamcc) names and new ones (i.e. clp(FD)):
clp(FD)
Executable
Prolog compiler
Gcc compiler
Build Makele
Library
Prole library
wamcc
names
clp(FD)
names
wamcc
clp fd
w gcc
fd gcc
bmf wamcc
bmf clp fd
libwamcc.a
libclp fd.a
libwamcc pp.a
libclp fd pp.a
Some papers [24, 25, 26, 27, 28, 17] presents clp(FD) and its extensions. Basically, clp(FD)
deals with only one basic constraint X in r (see section J.3.1). X is a nite domain
variable and r denotes a range, which can be not only a constant range, e.g. 1::10 but also
an indexical range using:
min(Y ) which represents the minimal value of Y (in the current store),
max(Y ) which represents the maximal value of Y ,
val(Y ) which represents the denitive value of Y ,
dom(Y ) which represents the whole domain of Y .
From the basic X in r constraints, it is possible to dene high-level constraints, called user
constraints, as Prolog predicates. Each constraint species how the constrained variable
must be updated when the domains of other variables change. In the clp(FD) system,
basic user constraints are already dened as built-in predicates (see section J.3). CHIP-like
constraints such as equations, inequations and disequations can be used directly by the
programmer. A preprocessor will translate them at compile time. So, clp(FD) oers the
usual constraints over nite domains as proposed by CHIP together with the possibility to
dene new constraints in a declarative way.
ANNEXE J. MANUEL D'UTILISATION DE CLP(FD)
256
J.2 Finite Domain variables
A new type of data is introduced: FD variables which can take a value in its domain
(reduced step by step by X in r constraints). An FD variable is fully compatible with
Prolog integers and Prolog variables. Namely, each time a FD variable is expected in
a constraint (i.e. in X in r and other user constraints) it is possible to pass a Prolog
integer (treated as a singleton range) or a Prolog variable (bound to an initial range
0::infinity). Since domains are nite, infinity stands for the greatest integer (see also
fd infinity/1). Since Prolog variables and FD variables are fully compatible, no domain
declarations are needed. However, in some cases this can cause a failure due to overows
(e.g. infinity infinity). In particular intermediate variables do not need any domain
declaration as it is required in CHIP.
There are 2 representations for an FD variable:
interval representation: only the min and the max of the variable are maintained.
In this representation it is possible to store values included in 0::infinity.
sparse representation: an additional bit-vector is used to store the set of possible
values for a variable. In this representation it is possible to store values included
in 0::vector max. By default vector max is set to 127 and can be redened via an
environment variable VECTORMAX or via the built-in predicate fd vector max/1 (see
section J.3).
The initial representation for an FD variable X is always an interval representation and
is switched to a sparse representation when a \hole" appears in the domain (e.g. due to
union, complementation,...)1 . When this switching occurs some values can be lost since
vector max is less than infinity. We say that \X is extra constrained" since X is constrained by the solver to the domain 0::vector max. A ag extra cstr is associated to each
FD variable to indicate if some values have been lost and is updated by all operations.
An \extra constrained" FD variable is written followed by the @ symbol. When a failure
occurs on a variable extra constrained a message Warning: Vector too small - maybe
lost solutions is displayed.
As soon as a variable uses a sparse representation it will not switch back to an interval representation
even if there are no longer holes in its domain.
1
ANNEXE J. MANUEL D'UTILISATION DE CLP(FD)
257
Domain of X
X in 0..512
0..512
;
off
X in 0..3:10..512
0..3:10..127
128..512
on
X in 0..100
0..3:10..100
Lost values Extra Cstr Flag
;
off
In this example, when the constraint X in 0::3 : 10::512 is told some solutions are lost.
However, when constraint X in 0::100 is told, no longer values are lost.
Other example:
Constraint on X
Domain of X
X in 0..512
0..512
;
off
X in 0..3:10..512
0..3:10..127
128..512
on
;
Lost values Extra Cstr Flag
Warning ... on
In this example, the constraint X in 256::300 fails due to the lost of 128::512 so a message
is displayed onto the terminal. The solution would consist in dening:
X in 256..300
%setenv VECTORMAX 512
Finally, note that bit-vectors are not dynamic, i.e. all vectors must have the same size
(0::vector max). So the use of fd vector max/1 is limited to the initial denition of vector
sizes and must occur before any constraint.
J.3 Finite Domain built-in predicates / constraints
J.3.1 The constraint
X
in
r
?X in +R
enforces X to belong to one element of the range denoted by R. The syntax of X
is given by the following table:
in
r
ANNEXE J. MANUEL D'UTILISATION DE CLP(FD)
c ::= X
in
r
r ::= t1 ..t2
ftg
R
dom(Y )
r1 : r2
r1 & r2
-r
r + ct
r - ct
r * ct
r / ct
r mod ct
r1 + r2
r1 - r2
r1 * r2
r1 / r2
r1 mod r2
fr (a1 ,:::,ak )
(interval range)
(singleton range)
(range parameter)
(indexical domain)
(union)
(intersection)
(complementation)
(range by term addition)
(range by term subtraction)
(range by term multiplication)
(range by term division)
(range by term modulo)
(range by range addition)
(range by range subtraction)
(range by range multiplication)
(range by range division)
(range by range modulo)
(user range function)
a ::= r j t
(user function argument)
t ::=
258
Y
(indexical min)
Y
(indexical max)
Y
(delayed value)
ct j t t j t1-t2 j t1 *t2 j t1 /<t2 j t1 />t2
f a ::: ak ) (user term function)
min( )
max( )
val( )
1+ 2
(
,
t 1 ,
ct ::= C
nj
infinity
(term parameter)
j ct1 +ct2 j ct1 -ct2 j ct1*ct2 j ct1 /<ct2 j ct1 />ct2
J.3.2 Linear arithmetic constraints
A linear term is of the for A1 X1 + ::: + An Xn where each Ai must be an integer
and can be omitted if it is 1. Each X1 is a variable, an FD variable or an integer (i.e. a
constant). + denotes either the plus symbol + or the minus symbol . In the following
S and T are linear terms.
ANNEXE J. MANUEL D'UTILISATION DE CLP(FD)
S#=T
S
n
S# =T
is equal to T.
S
is not equal to T.
S
is less than T.
S#<T
S#<=T
S
is less than or equal to T.
S
is greater than T.
S#>T
S#>=T
S
is greater than or equal to T.
J.3.3 Other arithmetic constraints
'min(x,y)=z'(?X,?Y,?Z)
Z
is the minimum value between X and Y.
'max(x,y)=z'(?X,?Y,?Z)
Z
is the maximum value between X and Y.
'|x-y|=z'(?X,?Y,?Z)
Z
is the absolute value of X-Y.
'xx=y'(?X,?Y)
Y
is the square of X.
'xy=z'(?X,?Y,?Z)
Z
is equal to X*Y (i.e. non-linear equation).
259
ANNEXE J. MANUEL D'UTILISATION DE CLP(FD)
260
J.3.4 Domain Handling
domain(+Vars,+Lower,+Upper)
constraints each variable of the list Vars to belong to the domain Lower..Upper.
fd vector max(?N)
if N is a variable, unies N to the maximum value which can be stored in a bit-vector
representation. If N is an integer, dene the maximum value (such a denition can
only be done once before stating any constraint (see section J.2).
fd infinity(?N)
Unies N with the infinity (i.e. greatest) value.
fd var(?X)
Succeeds if X is bound to an FD variable.
fd min(?X,?N)
Unies N with the current minimum value of the FD variable X. Note that this is not
a constraint.
fd max(?X,?N)
Unies N with the current maximum value of the FD variable X.
fd dom(?X,?L)
Unies L with the current domain of the FD variable X. L is a list of integers.
fd size(?X,?N)
Unies N with the current size of the domain of the FD variable X.
fd extra cstr(?X,?F)
Unies F with the current extra constraint ag (i.e. 0/1) of the FD variable X (see
section J.2).
fd has vector(?X)
Succeeds if X is an FD variable (not an integer) which uses a bit-vector representation.
fd use vector(?X)
Enforces the FD variable X to use a bit-vector representation.
ANNEXE J. MANUEL D'UTILISATION DE CLP(FD)
261
J.3.5 Enumeration predicates
indomain(?X)
assignes a consistent value to the FD variable X from the minimum of
backtracking, all possible values can be enumerated).
X
(trough
labeling(+L)
assignes a value for each FD variable of the list L using indomain/1.
labelingff(+L)
assignes a value for each FD variable of the list L using the rst-fail heuristics.
deleteff(?X,+L,?Rest)
Unies X with the FD variable with the smallest domain among the FD variables in
the list L. Also unies Rest with the list of remainding FD variables except X.
J.3.6 Symbolic constraints
alldifferent(+L)
enforces the constraint X 6= Y, for each pair of variable X,Y in the list of FD variables
L.
the Ith element of the list of integers L must be equal to the value V. I and V are FD
variables.
atmost(+N,+L,+V)
at most N variables of the list of FD variables L are equal to the value V. N and V are
integers.
relation(+Tuples,+Vars)
enforces the list of FD variables Vars to verify the relation coded by Tuples. Tuples
is a list of tuples of the relation, each tuple is a list of integers. Example:
and(X,Y,Z):- relation([[0,0,0],[0,1,0],[1,0,0],[1,1,1]],[X,Y,Z]).
relationc(+CTuples,+Vars)
similar to
relation/2
but the tuples are given column by column (faster than
ANNEXE J. MANUEL D'UTILISATION DE CLP(FD)
relation/2).
262
Example:
and(X,Y,Z):- relationc([[0,0,1,1],[0,1,0,1],[0,0,0,1]],[X,Y,Z]).
J.3.7 Symbolic constraints
minof(+Goal,?Var)
uses a depth-rst branch and bound to nd the minimum optimal value of Var using
Goal as generator (e.g. labeling/1).
maxof(+Goal,?Var)
uses a depth-rst branch and bound to nd the maximum optimal value of Var using
Goal as generator (e.g. labeling/1).
J.4 Boolean built-in predicates / constraints
oers a set of boolean constraints based on Finite Domains. A boolean variable is
nothing more than a FD variable with an initial domain 0::1. So arc-consistency is also used
for booleans and thus the enumeration phase is required as for traditional FD constraints.
No declarations are needed for boolean variables. When a varialble is involved in a boolean
constraint it is automatically set to the initial domain 0::1.
clp(FD)
J.4.1 Basic boolean constraints
not(?X,?Y)
and(?X,?Y,?Z)
and0(?X,?Y)
true if 0 = X ^ Y (i.e. :X _ :Y ).
and0(?X,?Y,?Z)
true if 0 = X ^ Y ^ Z (i.e. :X _ :Y _ :Z ).
ANNEXE J. MANUEL D'UTILISATION DE CLP(FD)
or(?X,?Y,?Z)
or1(?X,?Y)
true if 1 = X _ Y (i.e. X _ Y ).
or1(?X,?Y,?Z)
true if 1 = X _ Y _ Z (i.e. X _ Y _ Z ).
xor(?X,?Y,?Z)
true if Z = X xor Y .
equiv(?X,?Y,?Z)
true if Z = X , Y .
equiv1(?X,?Y)
true if 1 = X , Y (i.e. X , Y ).
J.4.2 Symbolic boolean constraints
at least one(+L)
true if at least one boolean variable of the list L is equal to 1.
at most one(+L)
true if at most one boolean variable of the list L is equal to 1.
only one(+L)
true if only one boolean variable of the list L is equal to 1.
263
Bibliographie
[1] A. Aggoun and N. Beldiceanu. Time Stamps Techniques for the Trailed Data in CLP
Systems. In Actes du Seminaire 1990 - Programmation en Logique, Tregastel, France,
CNET 1990.
[2] A. Aggoun and N. Beldiceanu. Overview of the CHIP Compiler System. In 8th
International Conference on Logic Programming, Paris, France, MIT Press, 1991. Also
in Constraint Logic Programming: Selected Research, A. Colmerauer and F. Benhamou
(Eds.). MIT Press, 1993.
[3] H. At-Kaci. Warren's Abstract Machine, A Tutorial Reconstruction. Logic Programming Series, MIT Press, 1991.
[4] F. Benhamou. Boolean Algorithms in PrologIII. In Constraint Logic Programming:
Selected Research, A. Colmerauer and F. Benhamou (Eds.). MIT Press, 1993.
[5] H. Bennaceur and G. Plateau. FASTLI: An Exact Algorithm for the Constraint Satisfaction Problem: Application to Logical Inference. Research Report, LIPN, Universite
Paris-Nord, Paris, France, 1991.
[6] H. Bennaceur and G. Plateau. Logical Inference Problem in Variables 0/1. in IFORS
93 Conference, Lisboa, Portugal, 1993.
[7] BNR-Prolog User's Manual. Bell Northern Research. Ottawa, Canada, 1988.
[8] A. Bockmayr. Logic Programming with Pseudo-Boolean Constraints. Research Report
MPI-I-91-227, Max Planck Institut, Saarbrucken, Germany, 1991.
[9] M. Bonnard, S. Manchon, and P. Planchon. Bilan des etudes de la division AOC sur
la regulation du trac aerien, 1992.
264
BIBLIOGRAPHIE
265
[10] S. Manchon, D. Chemla, C. Gobier, and P. Kerlirzin. Dossier de specications du
Systeme Pretactique pour Optimiser la Regulation du Trac aerien: SPORT V4.3,
1992.
[11] M. Bruynooghe. An Interpreter for Predicate Logic Programs: Basic Principles. Research Report cw10, Katholieke Universiteit Leuven, Belgium, 1976.
[12] M. Bruynooghe. The Memory Management of Prolog Implemantations. in Workshop'80, pp12-20, 1980.
[13] R.E. Bryant. Graph Based Algorithms for Boolean Function Manipulation. IEEE
Transactions on computers, no. 35 (8), 1986, pp 677{691.
[14] W. Buttner and H. Simonis. Embedding Boolean Expressions into Logic Programming. Journal of Symbolic Computation, no. 4 (1987), pp 191-205.
[15] M. Carlsson. Design and Implementation of an Or-Parallel Prolog Engine. PhD
dissertation, SICS, Sweden, 1990.
[16] B. Carlson, M. Carlsson. Constraint Solving and Entailment Algorithms for cc(FD).
Research Report, SICS, Sweden, 1993.
[17] B. Carlsson, M. Carlsson, D. Diaz. Entailment of Finite Domain Constraints. In 11th
International Conference on Logic Programming, Santa Margherita, Italy, MIT Press,
1994.
[18] D. Chemla, D. Diaz, P. Kerlirzin and S. Manchon. Using clp(FD) to Support Air Trafc Flow Management. In 3rd International Conference on the Practical Application
of Prolog, Paris, France, 1995.
[19] T. Chikayama, T. Fujise and D. Sekita. A portable and Ecient Implementation of
KL1. in ICOT/NSF Workshop on Parallel Logic Programming and its Programming
Environments, CIS-TR-94-04, Department of Computer Information Science, Oregon,
1994.
[20] P. Codognet, F. Fages and T. Sola. A metalevel compiler for CLP(FD) and its combination with intelligent backtracking. In Constraint Logic Programming: Selected Research, A. Colmerauer and F. Benhamou (Eds.). MIT Press, 1993.
BIBLIOGRAPHIE
266
[21] D. Diaz.
wamcc
Prolog Compiler User's Manual. INRIA, Le Chesnay, France, 1994.
[22] D. Diaz.
clp(FD)
User's Manual. INRIA, Le Chesnay, France, 1994.
[23] P. Codognet and D. Diaz. wamcc: Compiling Prolog to C. In 12th International
Conference on Logic Programming, Tokyo, Japan, MIT Press, 1995.
[24] P. Codognet and D. Diaz. A Minimal Extension of the WAM for clp(FD). In 10th International Conference on Logic Programming, Budapest, Hungary, MIT Press, 1993.
[25] P. Codognet and D. Diaz. Compiling Constraint in clp(FD). To appear in Journal of
Logic Programming.
[26] P. Codognet and D. Diaz. Boolean Constraint Solving Using clp(FD). In International
Logic Programming Symposium, Vancouver, British Columbia, Canada, MIT Press,
1993.
[27] P. Codognet and D. Diaz. clp(B): Combining Simplicity and Eciency in Boolean
Constraint Solving. In Programming Language Implementation and Logic Programming Madrid, Spain, Springer-Verlag, 1994.
[28] P. Codognet and D. Diaz. A Simple and Ecient Boolean Solver for Constraint Logic
Programming. To appear in Journal of Automated Reasoning.
[29] P. Codognet and D. Diaz. Finite Domain Constraints in Constraint Logic Programming. In 14th European Conference on Operational Research, Jerusalem, Israel, 1995.
[30] D. Colin de Verdiere. Utilisation des techniques de recherche operationnelle pour les
etudes Air Trac Management, 1992.
[31] A. Colmerauer. An introduction to Prolog-III. Communications of the ACM, 33 (7),
July 1990.
[32] Vtor Santos Costa, D. H. D. Warren, and Rong Yang. The Andorra-I engine: A
parallel implementation of the basic Andorra model. In 8th International Conference
on Logic Programming, Paris, France, MIT Press, 1991.
[33] M. Dincbas, H. Simonis and P. Van Hentenryck. Solving the Car-Sequencing Problem
in Constraint Logic Programming. In ECAI-88, Munich, W. Germany, August 1988.
BIBLIOGRAPHIE
267
[34] M. Dincbas, H. Simonis and P. Van Hentenryck. Solving large combinatorial problems
in Logic Programming. Journal of Logic Programming, 8 (1,2), 1990.
[35] G. Dore and P. Codognet. A Prototype Compiler for Prolog with Boolean Constraints.
In GULP'93, Italian Conference on Logic Programming, Gizzeria Lido, Italy, 1993.
[36] G. Gallo, G. Urbani, Algorithms for Testing the Satisability of Propositional Formulae. Journal of Logic Programming, no. 7 (1989), pp 45-61.
[37] J.M. Garot. Airspace Management in Europe: issues and solutions. In IFORS 1993:
13th International Conference of Operational Research, Lisbon, Portugal, 1993.
[38] D. Gudeman. Representing Type Information in Dynamically Typed Languages. Technical Report, University of Arizona, Arizona, 1993.
[39] D. Gudeman, K. De Bosschere and S. Debray. jc: An Ecient and Portable Sequential
Implementation of Janus. In Joint International Conference and Symposium on Logic
Programming, Washington, MIT Press, 1992.
[40] R. M. Haralick and G. L. Elliot. Increasing tree search eciency for constraint satisfaction problems. Articial Intelligence 14 (1980), pp 263-313
[41] S. Haridi and S. Janson. Kernel Andorra Prolog and its computation model. In 7th
International Conference on Logic Programming, Jerusalem, Israel, MIT Press, 1990.
[42] B. Haussman. Turbo Erlang: Approaching the Speed of C. In Implementations of
Logic Programming Systems, Evan Tick (ed.), Kluwer 1994.
[43] J. N. Hooker and C. Fedjki. Branch-and-Cut Solution of Inference Problems in Propositional Logic. Research Report, Carnegie-Mellon University Pittsurh, Pennsylvania,
1987.
[44] J. Jaar and J-L. Lassez. Constraint Logic Programming. In Principles Of Programming Languages, Munich, Germany, January 1987.
[45] J. Jaar and S. Michaylov. A Methodology for Managing Hard Constraints in CLP
Systems. In proceedings of Sigplan PLDI, Toronto, Canada, ACM Press 1991.
[46] J. Jaar, S. Michaylov, P. J. Stuckey and R. Yap. An Abstract Machine for CLP(R).
In proceedings of Sigplan PLDI, San Francisco, ACM Press 1992.
BIBLIOGRAPHIE
268
[47] J. Jourdan. Modelisation of terminal zone aircraft sequencing in constraint logic
programming, 1992.
[48] J. Jourdan and T. Sola. The Versatility of Handling Disjunctions as Constraints In
Programming Language Implementation and Logic Programming, Talin, Estonia, 1993.
[49] A. K. Mackworth. Consistency in Networks of Relations. Articial Intelligence 8
(1977), pp 99-118.
[50] U. Martin and T. Nipkow. Boolean Unication { The story so far. Journal of Symbolic
Computation, no. 7 (1989), pp 191-205.
[51] J-L. Massat. Using Local Consistency Techniques to Solve Boolean Constraints. In
Constraint Logic Programming: Selected Research, A. Colmerauer and F. Benhamou
(Eds.). MIT Press, 1993.
[52] C.S. Mellish. An alternative to Structure-Sharing in Logic Programming edited by
K.L. Clark and S.A. Tarnlund, Academic Press, pp99-106, 1982.
[53] B. A. Nadel. Constraint Satisfaction Algorithms. Computational Intelligence 5 (1989),
pp 188-224.
[54] W.J. Older and F. Benhamou. Programming in clp(BNR). In Position Papers of 1st
PPCP, Newport, Rhode Island, 1993.
[55] L. M. Pereira and A. Porto. Intelligent backtracking and sidetracking in horn clause
programs. Technical Report CIUNL 2/79, Universitade Nova de Lisboa, 1979.
[56] A. Rauzy. L'Evaluation Semantique en Calcul Propositionnel. PhD thesis, Universite
Aix-Marseille II, Marseille, France, January 1989.
[57] A. Rauzy. Adia. Technical Report, LaBRI, Universite Bordeaux I, 1991.
[58] A. Rauzy. Using Enumerative Methods for Boolean Unication. In Constraint Logic
Programming: Selected Research, A. Colmerauer and F. Benhamou (Eds.). MIT Press,
1993.
[59] A. Rauzy. Some Practical Results on the SAT Problem. Draft, 1993.
BIBLIOGRAPHIE
269
[60] V.A. Saraswat. Concurrent Constraint Programming Languages. PhD thesis, Research
Report CMU-CS-89-108, Carnegie-Mellon University, 1989. Also (revised) MIT Press,
1993.
[61] V. A. Saraswat. Concurrent Constraint Programming, MIT Press, 1993.
[62] T. Solla. PhD thesis (forthcoming), THOMSON-CSF, France, 1994.
[63] V. Saraswat. The Category of Constraint Systems is Cartesian-Closed. In Logic In
Computer Science, IEEE Press 1992.
[64] D. S. Scott. Domains for Denotational Semantics. In ICALP'82, International Colloquium on Automata Languages and Programming, 1982.
[65] H. Simonis, M. Dincbas. Propositional Calculus Problems in CHIP. ECRC, Technical
Report TR-LP-48, 1990.
[66] T. E. Uribe and M. E. Stickel. Ordered Binary Decision Diagrams and the DavisPutnam Procedure. In CCL'94, Constraints in Computational Logics, Munich, Germany, Springer-Verlag, 1994.
[67] P. Van Hentenryck. Constraint Satisfaction in Logic Programming. Logic Programming Series, MIT Press, 1989.
[68] P. Van Hentenryck and Y. Deville. The Cardinality Operator: A new Logical Connective for Constraint Logic Programming. In 8th International Conference on Logic
Programming, Paris, France, MIT Press, 1991.
[69] P. Van Hentenryck, V. Saraswat and Y. Deville. Constraint processing in cc(FD).
Draft, 1991.
[70] P. Van Hentenryck, V. Saraswat and Y. Deville. Design, Implementation and Evaluation of the Constraint language cc(FD). Draft, 1993.
[71] P. Van Hentenryck, Y. Deville and C-M. Teng. A generic arc-consistency algorithm
and its specializations. Articial Intelligence 57 (1992), pp 291-321.
[72] P. Van Hentenryck, H. Simonis and M. Dincbas. Constraint Satisfaction Using Constraint Logic Programming. Articial Intelligence no 58, pp 113-159, 1992.
BIBLIOGRAPHIE
270
[73] P. Van Roy. Can Logic Programming run as fast as Imperative Programming ? Report
No UCB/CSD90/600, Berkeley, California, 1990.
[74] P. Van Roy and A. Despain. High-Performance Logic Programming with the Aquarius
Prolog Compiler. IEEE Computer, pp 54-67, 1992.
[75] D. H. D. Warren. An Abstract Prolog Instruction Set. Technical Report 309, SRI
International, Oct. 1983.
[76] D. H. D. Warren. The Andorra Principle. Internal Report, Gigalips Group, 1987.
Leonard de Vinci.
Georges Duhamel.
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertising

Languages

Only pages of the document in English were displayed