Download
run(Nr,LX,LY):-
gen_data(Nr,LX,LY,LW,LH,Max),
gen_rect(LX,LY,LW,LH,Lrect),
Max1 is Max + 1,
diffn(Lrect,unused,unused,[Max1,Max1]),
cumulative(LX,LW,LH,unused,unused,Max,Max1,[Max,0,1]),
cumulative(LY,LH,LW,unused,unused,Max,Max1,[Max,0,1]),
labeling(LX),
labeling(LY).
gen_data(Nr,LX,LY,Sizes,Sizes,MaxPlace) :-
data(Nr,NbSquare,MaxPlace,SizeSquares),
length(LX,NbSquare),
length(LY,NbSquare),
LX :: 1..MaxPlace,
LY :: 1..MaxPlace,
reverse(SizeSquares,Sizes).
gen_rect([],[],[],[],[]).
gen_rect([X|Rx],[Y|Ry],[W|Rw],[H|Rh],[[X,Y,W,H]|R]) :-
gen_rect(Rx,Ry,Rw,Rh,R).
labeling([]).
labeling([X|Y]) :-
lmindomain([X|Y], M),
fix_min([X|Y], M, R),
labeling(R).
fix_min([V|R], M, R) :-
V = M,
inc_choice.
fix_min([V|R], M, [V|S]) :-
V #> M,
fix_min(R, M, S).
lmindomain([H|T], M) :-
domain_info(H, Min, _, _, _, _),
lmindomain(T, Min, M).
lmindomain([], M, M).
lmindomain([X|Y], M, Mend) :-
domain_info(X, Min, _, _, _, _),
M1 is min(M,Min),
lmindomain(Y, M1, Mend).
inc_choice.
inc_choice:-
incval(choice,_),
fail.