19.01.2015 Views

Constraint Logic Programming Using ECLiPSe

Constraint Logic Programming Using ECLiPSe

Constraint Logic Programming Using ECLiPSe

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Solutions to selected exercises 319<br />

).<br />

no_overlap(B, X1, Y1, S1, X2, Y2, S2) :-<br />

B #=<<br />

(X1+S1 #=< X2 or X2+S2 #=< X1 or Y1+S1 #=< Y2 or Y2+S2 #=< Y1).<br />

capacity(Bs, Cs, Sizes, Size,Waste) :-<br />

( for(Pos,1,Size),<br />

foreach(W,Ws),<br />

param(Bs,Cs,Size,Sizes)<br />

do<br />

( foreach(C,Cs),<br />

foreach(B,Bs),<br />

foreach(S,Sizes),<br />

param(Pos),<br />

fromto(Sum,S*Bool*B+Sum1,Sum1,0)<br />

do<br />

::(C, Pos-S+1..Pos, Bool)<br />

),<br />

W #= eval(Size)-Sum,<br />

W #>= 0<br />

),<br />

Waste #= sum(Ws).<br />

Here ::/3 is the reified form of the variable declaration built-in ::/2 (see Subsection<br />

9.4.4). We have then for example:<br />

[eclipse 3]: squares(1, Bs, Xs, Ys, Min).<br />

Found a solution with cost 100<br />

[...]<br />

Found a solution with cost 45<br />

Bs = [0, 0, 1, 1, 1, 1, 1]<br />

Xs = [1, 1, 1, 1, 6, 9, 1]<br />

Ys = [1, 1, 1, 6, 1, 1, 10]<br />

Min = 45<br />

Yes (6.58s cpu)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!