1% BEGIN LICENSE BLOCK
2% Version: CMPL 1.1
3%
4% The contents of this file are subject to the Cisco-style Mozilla Public
5% License Version 1.1 (the "License"); you may not use this file except
6% in compliance with the License.  You may obtain a copy of the License
7% at www.eclipse-clp.org/license.
8%
9% Software distributed under the License is distributed on an "AS IS"
10% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11% the License for the specific language governing rights and limitations
12% under the License.
13%
14% The Original Code is  The ECLiPSe Constraint Logic Programming System.
15% The Initial Developer of the Original Code is  Cisco Systems, Inc.
16% Portions created by the Initial Developer are
17% Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
18%
19% Contributor(s):
20%
21% END LICENSE BLOCK
22:- use_module(fd).
23
24t :-
25
26  ilog_test.
27
28/* Instanciation */
29t1(V) :-
30
31  V ::  1..10,
32  ( V = 1 ; V = 2 ; V = 3 ; true).
33
34/* Unification */
35t2(V1, V2) :-
36
37  V1 :: 1..10,
38  V2 :: 5..15,
39  V1 = V2.
40
41/* Backtrack */
42t3(V1, V2) :-
43
44  V1 :: 1..10,
45  V2 :: 5..15,
46  V1 = 5, ( V2 = 10 ; true).
47
48t4(V) :-
49
50  V :: 1..10,
51  V = 15.
52
53t5(X) :-
54  suspend(writeln(hello), 2, X->inst),
55
56  X:: 1..10,
57  writeln(X),
58  X = 5.
59
60t6 :-   2 #= 3.
61t7 :-  2 #= 2.
62
63t8(X) :-  X :: 1..10, X #= 2.
64
65t9(X) :-  X :: 1..10, suspend(writeln(hello), 2, X->inst), X #= 2.
66
67t10(X) :-  X :: 1..10, X #< 6.
68
69t11(X, Y) :-
70   X :: 1..10, Y :: 1..10,
71  (true ; X + Y #= 7, (true ; X #> 3, ( true ; Y #> 2 ) ) ).
72
73t12(X, Y) :-
74	 X :: 1..10, Y :: 1..10, element(X, [2,9,7], Y).
75
76t13(L) :-
77  length(L, 12), L :: 1..10, L=[O|_], O = 3.
78
79t14(L) :-
80  length(L, 12), L :: 1 .. 10, alldistinct(L), L=[X1, X2, X3 | _], X1 = 1, X2 #< 3, X3 #> 9.
81
82t15(X1, X2) :-
83   [X1,X2] :: 1..4, X1 - X2 ## 1, X2 = 3.
84
85t16(X1, X2) :-
86   [X1,X2] :: 1..4, X1 ## 1 + X2, X2 = 3.
87
88t17(L) :-  length(L, 4), L :: 0..1, sum(L) #= 1, L = [_X1,X2,X3,_X4], X3 = 0, X2 = 1.
89
90t18(X) :-  X :: 1..10, min_max(indomain(X), 10-X).
91
92t19(X) :-  X::1..10, #\+ (X##1).
93
94t20([X1,X2,X3]) :-
95   [X1, X2, X3] :: 1 .. 10, atmost(2, [X1, X2, X3], 1), X1=1, X3=1.
96
97t21(X, V) :-  X :: 1..10, X ## 2, element(X, [1,10, 5], V).
98
99
100t22 :-  X::1..10, suspend(writeln(hello), 3, X->ilog_range), X #< 5.
101
102t23 :-  [X,Y]::1..10, suspend(writeln(hello), 3, X->ilog_range), X #< Y.
103
104
105t24 :-
106  [X,Y,Z,T] :: 1..10, element(X, [Y,3, Z, 12], T), T = 5, Z #> 7.
107
108t25 :-
109   [X,Y,Z] :: 1..10,
110  suspend(writeln(hello), 3, X->ilog_range),
111  element(I, [X, 3], Y), Y #<= Z, Z #< 8, I = 1.
112
113t26 :-
114   X::2..10, element(X, [1], Y).
115
116
117puzzle1(Board) :-
118        Board = [NW,N,NE,W,E,SW,S,SE],
119
120        Board :: 0..12,
121        sum(Board) #= 12,
122        NW + N + NE #= 5,
123        NE + E + SE #= 5,
124        NW + W + SW #= 5,
125        SW + S + SE #= 5,
126
127        labeling(Board),
128
129        printf("%3d%3d%3d\n", [NW,N,NE]),
130        printf("%3d   %3d\n", [ W,   E]),
131        printf("%3d%3d%3d\n", [SW,S,SE]).
132
133
134puzzle2(Coins) :-
135        Coins = [NRound,NSquare,NTriang],
136        Coins :: 0..11,
137        NRound*15 + NSquare*16 + NTriang*17 #= 121,
138        NCoins #= sum(Coins),
139
140        min_max(labeling(Coins), NCoins),
141
142        printf("%d round, %d square, %d triangular\n", Coins).
143
144transit(2,_, 1) :- !.
145transit(0,_, 2) :- !.
146transit(_, _, 0) :- !.
147
148path :-
149   path(t(N0-C0, N1-C1, N2-0), transit, 1, value).
150
151bug1 :- X :: 1..10, findall(X, true, L), L=[Y], Y #= 1.
152