<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">:- use_module(library(clpfd)).
:- ensure_loaded(['../../interpreter/prolog/r4cp']).
:- init_interpreter.


s1(_A_) :- 
	make_shape_box([5,4,4], _A_).

s1_search(_A_) :- 
	make_shape_box_search([5,4,4], _A_).

s2(_A_) :- 
	make_shape_box([4,5,2], _A_).

s2_search(_A_) :- 
	make_shape_box_search([4,5,2], _A_).

s3(_A_) :- 
	make_shape_box([5,4,2], _A_).

s3_search(_A_) :- 
	make_shape_box_search([5,4,2], _A_).

o1(_B_) :- 
	s1(_A_),
	make_object_shape(_A_, [0,0,0], _B_).

o1_search(_B_) :- 
	s1_search(_A_),
	make_object_shape_search(_A_, [0,0,0], _B_).

o2(_B_) :- 
	s2(_A_),
	rcp_var(from(o2,0,1), O2),
	rcp_var(from(o2,0,2), O2_2),
	rcp_var(from(o2,0,3), O2_3),
	make_object_shape(_A_, [O2,O2_2,O2_3], 2, _B_).

o2_search(_B_) :- 
	s2_search(_A_),
	rcp_var(from(o2,0,1), O2),
	rcp_var(from(o2,0,2), O2_2),
	rcp_var(from(o2,0,3), O2_3),
	make_object_shape_search(_A_, [O2,O2_2,O2_3], 2, _B_).

o3(_B_) :- 
	s3(_A_),
	rcp_var(from(o3,0,1), O3),
	rcp_var(from(o3,0,2), O3_2),
	rcp_var(from(o3,0,3), O3_3),
	make_object_shape(_A_, [O3,O3_2,O3_3], 5, _B_).

o3_search(_B_) :- 
	s3_search(_A_),
	rcp_var(from(o3,0,1), O3),
	rcp_var(from(o3,0,2), O3_2),
	rcp_var(from(o3,0,3), O3_3),
	make_object_shape_search(_A_, [O3,O3_2,O3_3], 5, _B_).

dimensions(_A_) :- 
	_A_=[1,2,3].

dimensions_search(_A_) :- 
	_A_=[1,2,3].

bins(_B_) :- 
	o1(_A_),
	_B_=[_A_].

bins_search(_B_) :- 
	o1_search(_A_),
	_B_=[_A_].

items(_C_) :- 
	o2(_A_),
	o3(_B_),
	_C_=[_A_,_B_].

items_search(_C_) :- 
	o2_search(_A_),
	o3_search(_B_),
	_C_=[_A_,_B_].

sum_foldr_1([], _, 0) :- 
	!.
sum_foldr_1([X_47|Tail], [L], _B_) :- 
	sum_foldr_1(Tail, [L], _A_),
	fd_aeq(X_47+_A_, _B_).

sum_foldr_1_search([], _, 0) :- 
	!.
sum_foldr_1_search([X_47|Tail], [L], _B_) :- 
	sum_foldr_1_search(Tail, [L], _A_),
	fd_aeq(X_47+_A_, _B_).

sum(L, _A_) :- 
	sum_foldr_1(L, [L], _A_).

sum_search(L, _A_) :- 
	sum_foldr_1_search(L, [L], _A_).

product_foldr_1([], _, 1) :- 
	!.
product_foldr_1([X_48|Tail], [L], _B_) :- 
	product_foldr_1(Tail, [L], _A_),
	fd_aeq(X_48*_A_, _B_).

product_foldr_1_search([], _, 1) :- 
	!.
product_foldr_1_search([X_48|Tail], [L], _B_) :- 
	product_foldr_1_search(Tail, [L], _A_),
	fd_aeq(X_48*_A_, _B_).

product(L, _A_) :- 
	product_foldr_1(L, [L], _A_).

product_search(L, _A_) :- 
	product_foldr_1_search(L, [L], _A_).

maximum_foldr_1([], _, _A_) :- 
	!.
maximum_foldr_1([X_49|Tail], [L], _B_) :- 
	maximum_foldr_1(Tail, [L], _A_),
	fd_aeq(max(X_49,_A_), _B_).

maximum_foldr_1_search([], _, _A_) :- 
	!.
maximum_foldr_1_search([X_49|Tail], [L], _B_) :- 
	maximum_foldr_1_search(Tail, [L], _A_),
	fd_aeq(max(X_49,_A_), _B_).

maximum(L, _A_) :- 
	maximum_foldr_1(L, [L], _A_).

maximum_search(L, _A_) :- 
	maximum_foldr_1_search(L, [L], _A_).

minimum_foldr_1([], _, _A_) :- 
	!.
minimum_foldr_1([X_50|Tail], [L], _B_) :- 
	minimum_foldr_1(Tail, [L], _A_),
	fd_aeq(min(X_50,_A_), _B_).

minimum_foldr_1_search([], _, _A_) :- 
	!.
minimum_foldr_1_search([X_50|Tail], [L], _B_) :- 
	minimum_foldr_1_search(Tail, [L], _A_),
	fd_aeq(min(X_50,_A_), _B_).

minimum(L, _A_) :- 
	minimum_foldr_1(L, [L], _A_).

minimum_search(L, _A_) :- 
	minimum_foldr_1_search(L, [L], _A_).

oversize(O1, O2, D, _O_) :- 
	origin(O1, D, _A_),
	origin(O2, D, _B_),
	fd_aeq(max(_A_,_B_), _C_),
	origin(O1, D, _D_),
	origin(O2, D, _E_),
	fd_aeq(min(_D_,_E_), _F_),
	fd_aeq(_C_-_F_, _G_),
	end(O1, D, _H_),
	end(O2, D, _I_),
	fd_aeq(max(_H_,_I_), _J_),
	end(O1, D, _K_),
	end(O2, D, _L_),
	fd_aeq(min(_K_,_L_), _M_),
	fd_aeq(_J_-_M_, _N_),
	fd_aeq(max(_G_,_N_), _O_).

oversize_search(O1, O2, D, _O_) :- 
	origin_search(O1, D, _A_),
	origin_search(O2, D, _B_),
	fd_aeq(max(_A_,_B_), _C_),
	origin_search(O1, D, _D_),
	origin_search(O2, D, _E_),
	fd_aeq(min(_D_,_E_), _F_),
	fd_aeq(_C_-_F_, _G_),
	end_search(O1, D, _H_),
	end_search(O2, D, _I_),
	fd_aeq(max(_H_,_I_), _J_),
	end_search(O1, D, _K_),
	end_search(O2, D, _L_),
	fd_aeq(min(_K_,_L_), _M_),
	fd_aeq(_J_-_M_, _N_),
	fd_aeq(max(_G_,_N_), _O_).

make_box(L, _A_) :- 
	rcp_rec([size=L], _A_).

make_box_search(L, _A_) :- 
	rcp_rec([size=L], _A_).

box_volume(B, _B_) :- 
	rcp_att(size, B, _A_),
	product(_A_, _B_).

box_volume_search(B, _B_) :- 
	rcp_att(size, B, _A_),
	product_search(_A_, _B_).

make_sbox(B, O, _A_) :- 
	rcp_rec([box=B,offset=O], _A_).

make_sbox_search(B, O, _A_) :- 
	rcp_rec([box=B,offset=O], _A_).

sbox_size(SB, D, _C_) :- 
	rcp_att(box, SB, _A_),
	rcp_att(size, _A_, _B_),
	nth1(D, _B_, _C_).

sbox_size_search(SB, D, _C_) :- 
	rcp_att(box, SB, _A_),
	rcp_att(size, _A_, _B_),
	nth1(D, _B_, _C_).

sbox_offset(SB, D, _B_) :- 
	rcp_att(offset, SB, _A_),
	nth1(D, _A_, _B_).

sbox_offset_search(SB, D, _B_) :- 
	rcp_att(offset, SB, _A_),
	nth1(D, _A_, _B_).

sbox_end(SB, D, _C_) :- 
	sbox_offset(SB, D, _A_),
	sbox_size(SB, D, _B_),
	fd_aeq(_A_+_B_, _C_).

sbox_end_search(SB, D, _C_) :- 
	sbox_offset_search(SB, D, _A_),
	sbox_size_search(SB, D, _B_),
	fd_aeq(_A_+_B_, _C_).

make_shape(SBs, _A_) :- 
	rcp_rec([sboxes=SBs], _A_).

make_shape_search(SBs, _A_) :- 
	rcp_rec([sboxes=SBs], _A_).

make_shape_box_foldr_1([], _, []) :- 
	!.
make_shape_box_foldr_1([_free_var_51|Tail], [L], [0|_A_]) :- 
	make_shape_box_foldr_1(Tail, [L], _A_).

make_shape_box_foldr_1_search([], _, []) :- 
	!.
make_shape_box_foldr_1_search([_free_var_51|Tail], [L], [0|_A_]) :- 
	make_shape_box_foldr_1_search(Tail, [L], _A_).

make_shape_box(L, _D_) :- 
	make_box(L, _A_),
	make_shape_box_foldr_1(L, [L], _B_),
	make_sbox(_A_, _B_, _C_),
	make_shape([_C_], _D_).

make_shape_box_search(L, _D_) :- 
	make_box_search(L, _A_),
	make_shape_box_foldr_1_search(L, [L], _B_),
	make_sbox_search(_A_, _B_, _C_),
	make_shape_search([_C_], _D_).

shape_volume_foldr_1([], _, []) :- 
	!.
shape_volume_foldr_1([SB_52|Tail], [S], [_B_|_C_]) :- 
	shape_volume_foldr_1(Tail, [S], _C_),
	rcp_att(box, SB_52, _A_),
	box_volume(_A_, _B_).

shape_volume_foldr_1_search([], _, []) :- 
	!.
shape_volume_foldr_1_search([SB_52|Tail], [S], [_B_|_C_]) :- 
	shape_volume_foldr_1_search(Tail, [S], _C_),
	rcp_att(box, SB_52, _A_),
	box_volume_search(_A_, _B_).

shape_volume(S, _C_) :- 
	rcp_att(sboxes, S, _A_),
	shape_volume_foldr_1(_A_, [S], _B_),
	sum(_B_, _C_).

shape_volume_search(S, _C_) :- 
	rcp_att(sboxes, S, _A_),
	shape_volume_foldr_1_search(_A_, [S], _B_),
	sum_search(_B_, _C_).

shape_origin_foldr_1([], _, []) :- 
	!.
shape_origin_foldr_1([SB_53|Tail], [D,S], [_A_|_B_]) :- 
	shape_origin_foldr_1(Tail, [D,S], _B_),
	sbox_offset(SB_53, D, _A_).

shape_origin_foldr_1_search([], _, []) :- 
	!.
shape_origin_foldr_1_search([SB_53|Tail], [D,S], [_A_|_B_]) :- 
	shape_origin_foldr_1_search(Tail, [D,S], _B_),
	sbox_offset_search(SB_53, D, _A_).

shape_origin(S, D, _C_) :- 
	rcp_att(sboxes, S, _A_),
	shape_origin_foldr_1(_A_, [D,S], _B_),
	minimum(_B_, _C_).

shape_origin_search(S, D, _C_) :- 
	rcp_att(sboxes, S, _A_),
	shape_origin_foldr_1_search(_A_, [D,S], _B_),
	minimum_search(_B_, _C_).

shape_end_foldr_1([], _, []) :- 
	!.
shape_end_foldr_1([SB_54|Tail], [D,S], [_A_|_B_]) :- 
	shape_end_foldr_1(Tail, [D,S], _B_),
	sbox_end(SB_54, D, _A_).

shape_end_foldr_1_search([], _, []) :- 
	!.
shape_end_foldr_1_search([SB_54|Tail], [D,S], [_A_|_B_]) :- 
	shape_end_foldr_1_search(Tail, [D,S], _B_),
	sbox_end_search(SB_54, D, _A_).

shape_end(S, D, _C_) :- 
	rcp_att(sboxes, S, _A_),
	shape_end_foldr_1(_A_, [D,S], _B_),
	maximum(_B_, _C_).

shape_end_search(S, D, _C_) :- 
	rcp_att(sboxes, S, _A_),
	shape_end_foldr_1_search(_A_, [D,S], _B_),
	maximum_search(_B_, _C_).

shape_size(S, D, _C_) :- 
	shape_end(S, D, _A_),
	shape_origin(S, D, _B_),
	fd_aeq(_A_-_B_, _C_).

shape_size_search(S, D, _C_) :- 
	shape_end_search(S, D, _A_),
	shape_origin_search(S, D, _B_),
	fd_aeq(_A_-_B_, _C_).

make_object(SL, OL, _A_) :- 
	rcp_var(from(make_object(SL,OL),0,0), Make_object_SL_OL),
	rcp_rec([shapes=SL,shape_index=Make_object_SL_OL,origin=OL], _A_).

make_object_search(SL, OL, _A_) :- 
	rcp_var(from(make_object(SL,OL),0,0), Make_object_SL_OL),
	rcp_rec([shapes=SL,shape_index=Make_object_SL_OL,origin=OL], _A_).

make_object(SL, OL, S, W, _A_) :- 
	rcp_rec([shapes=SL,shape_index=S,origin=OL,weight=W], _A_).

make_object_search(SL, OL, S, W, _A_) :- 
	rcp_rec([shapes=SL,shape_index=S,origin=OL,weight=W], _A_).

make_object_shape(S, L, _A_) :- 
	rcp_rec([shapes=[S],shape_index=1,origin=L], _A_).

make_object_shape_search(S, L, _A_) :- 
	rcp_rec([shapes=[S],shape_index=1,origin=L], _A_).

make_object_shape(S, L, W, _A_) :- 
	rcp_rec([shapes=[S],shape_index=1,origin=L,weight=W], _A_).

make_object_shape_search(S, L, W, _A_) :- 
	rcp_rec([shapes=[S],shape_index=1,origin=L,weight=W], _A_).

origin(O, D, _B_) :- 
	rcp_att(origin, O, _A_),
	nth1(D, _A_, _B_).

origin_search(O, D, _B_) :- 
	rcp_att(origin, O, _A_),
	nth1(D, _A_, _B_).

x(O, _A_) :- 
	origin(O, 1, _A_).

x_search(O, _A_) :- 
	origin_search(O, 1, _A_).

y(O, _A_) :- 
	origin(O, 2, _A_).

y_search(O, _A_) :- 
	origin_search(O, 2, _A_).

z(O, _A_) :- 
	origin(O, 3, _A_).

z_search(O, _A_) :- 
	origin_search(O, 3, _A_).

end_foldr_1([], _, []) :- 
	!.
end_foldr_1([S_55|Tail], [D,O], [_F_|_G_]) :- 
	end_foldr_1(Tail, [D,O], _G_),
	rcp_att(shape_index, O, _A_),
	rcp_att(shapes, O, _B_),
	nth1(_C_, _B_, S_55),
	fd_eq(_A_, _C_, _D_),
	shape_end(S_55, D, _E_),
	fd_aeq(_D_*_E_, _F_).

end_foldr_1_search([], _, []) :- 
	!.
end_foldr_1_search([S_55|Tail], [D,O], [_E_|_F_]) :- 
	end_foldr_1_search(Tail, [D,O], _F_),
	rcp_att(shape_index, O, _A_),
	rcp_att(shapes, O, _B_),
	nth1(_C_, _B_, S_55),
	shape_end_search(S_55, D, _D_),
	fd_aeq(fd_eq(_A_,_C_)*_D_, _E_).

end(O, D, _E_) :- 
	origin(O, D, _A_),
	rcp_att(shapes, O, _B_),
	end_foldr_1(_B_, [D,O], _C_),
	sum(_C_, _D_),
	fd_aeq(_A_+_D_, _E_).

end_search(O, D, _E_) :- 
	origin_search(O, D, _A_),
	rcp_att(shapes, O, _B_),
	end_foldr_1_search(_B_, [D,O], _C_),
	sum_search(_C_, _D_),
	fd_aeq(_A_+_D_, _E_).

size_foldr_1([], _, []) :- 
	!.
size_foldr_1([S_56|Tail], [D,O], [_F_|_G_]) :- 
	size_foldr_1(Tail, [D,O], _G_),
	rcp_att(shape_index, O, _A_),
	rcp_att(shapes, O, _B_),
	nth1(_C_, _B_, S_56),
	fd_eq(_A_, _C_, _D_),
	shape_size(S_56, D, _E_),
	fd_aeq(_D_*_E_, _F_).

size_foldr_1_search([], _, []) :- 
	!.
size_foldr_1_search([S_56|Tail], [D,O], [_E_|_F_]) :- 
	size_foldr_1_search(Tail, [D,O], _F_),
	rcp_att(shape_index, O, _A_),
	rcp_att(shapes, O, _B_),
	nth1(_C_, _B_, S_56),
	shape_size_search(S_56, D, _D_),
	fd_aeq(fd_eq(_A_,_C_)*_D_, _E_).

size(O, D, _C_) :- 
	rcp_att(shapes, O, _A_),
	size_foldr_1(_A_, [D,O], _B_),
	sum(_B_, _C_).

size_search(O, D, _C_) :- 
	rcp_att(shapes, O, _A_),
	size_foldr_1_search(_A_, [D,O], _B_),
	sum_search(_B_, _C_).

volume_foldr_1([], _, []) :- 
	!.
volume_foldr_1([S_57|Tail], [O], [_F_|_G_]) :- 
	volume_foldr_1(Tail, [O], _G_),
	rcp_att(shape_index, O, _A_),
	rcp_att(shapes, O, _B_),
	nth1(_C_, _B_, S_57),
	fd_eq(_A_, _C_, _D_),
	shape_volume(S_57, _E_),
	fd_aeq(_D_*_E_, _F_).

volume_foldr_1_search([], _, []) :- 
	!.
volume_foldr_1_search([S_57|Tail], [O], [_E_|_F_]) :- 
	volume_foldr_1_search(Tail, [O], _F_),
	rcp_att(shape_index, O, _A_),
	rcp_att(shapes, O, _B_),
	nth1(_C_, _B_, S_57),
	shape_volume_search(S_57, _D_),
	fd_aeq(fd_eq(_A_,_C_)*_D_, _E_).

volume(O, _C_) :- 
	rcp_att(shapes, O, _A_),
	volume_foldr_1(_A_, [O], _B_),
	sum(_B_, _C_).

volume_search(O, _C_) :- 
	rcp_att(shapes, O, _A_),
	volume_foldr_1_search(_A_, [O], _B_),
	sum_search(_B_, _C_).

distance(O1, O2, D, _H_) :- 
	origin(O1, D, _A_),
	origin(O2, D, _B_),
	fd_aeq(max(_A_,_B_), _C_),
	end(O1, D, _D_),
	end(O2, D, _E_),
	fd_aeq(min(_D_,_E_), _F_),
	fd_aeq(_C_-_F_, _G_),
	fd_aeq(max(0,_G_), _H_).

distance_search(O1, O2, D, _H_) :- 
	origin_search(O1, D, _A_),
	origin_search(O2, D, _B_),
	fd_aeq(max(_A_,_B_), _C_),
	end_search(O1, D, _D_),
	end_search(O2, D, _E_),
	fd_aeq(min(_D_,_E_), _F_),
	fd_aeq(_C_-_F_, _G_),
	fd_aeq(max(0,_G_), _H_).

precedes(A, B, D, _C_) :- 
	end(A, D, _A_),
	origin(B, D, _B_),
	fd_lt(_A_, _B_, _C_).

precedes_search(A, B, D, _C_) :- 
	end_search(A, D, _A_),
	origin_search(B, D, _B_),
	fd_lt(_A_, _B_),
	fd_aeq(_C_, 1).

meets(A, B, D, _C_) :- 
	end(A, D, _A_),
	origin(B, D, _B_),
	fd_eq(_A_, _B_, _C_).

meets_search(A, B, D, _C_) :- 
	end_search(A, D, _A_),
	origin_search(B, D, _B_),
	fd_eq(_A_, _B_),
	fd_aeq(_C_, 1).

overlaps(A, B, D, _K_) :- 
	origin(A, D, _A_),
	origin(B, D, _B_),
	fd_lt(_A_, _B_, _C_),
	end(A, D, _D_),
	end(B, D, _E_),
	fd_lt(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_),
	origin(B, D, _H_),
	end(A, D, _I_),
	fd_lt(_H_, _I_, _J_),
	fd_and(_G_, _J_, _K_).

overlaps_search(A, B, D, _G_) :- 
	origin_search(A, D, _A_),
	origin_search(B, D, _B_),
	end_search(A, D, _C_),
	end_search(B, D, _D_),
	origin_search(B, D, _E_),
	end_search(A, D, _F_),
	fd_lt(_A_, _B_),
	fd_lt(_C_, _D_),
	fd_lt(_E_, _F_),
	fd_aeq(_G_, 1).

contains(A, B, D, _G_) :- 
	origin(A, D, _A_),
	origin(B, D, _B_),
	fd_lt(_A_, _B_, _C_),
	end(B, D, _D_),
	end(A, D, _E_),
	fd_lt(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_).

contains_search(A, B, D, _E_) :- 
	origin_search(A, D, _A_),
	origin_search(B, D, _B_),
	end_search(B, D, _C_),
	end_search(A, D, _D_),
	fd_lt(_A_, _B_),
	fd_lt(_C_, _D_),
	fd_aeq(_E_, 1).

starts(A, B, D, _G_) :- 
	origin(A, D, _A_),
	origin(B, D, _B_),
	fd_eq(_A_, _B_, _C_),
	end(A, D, _D_),
	end(B, D, _E_),
	fd_lt(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_).

starts_search(A, B, D, _E_) :- 
	origin_search(A, D, _A_),
	origin_search(B, D, _B_),
	end_search(A, D, _C_),
	end_search(B, D, _D_),
	fd_eq(_A_, _B_),
	fd_lt(_C_, _D_),
	fd_aeq(_E_, 1).

finishes(A, B, D, _G_) :- 
	origin(B, D, _A_),
	origin(A, D, _B_),
	fd_lt(_A_, _B_, _C_),
	end(A, D, _D_),
	end(B, D, _E_),
	fd_eq(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_).

finishes_search(A, B, D, _E_) :- 
	origin_search(B, D, _A_),
	origin_search(A, D, _B_),
	end_search(A, D, _C_),
	end_search(B, D, _D_),
	fd_lt(_A_, _B_),
	fd_eq(_C_, _D_),
	fd_aeq(_E_, 1).

equals(A, B, D, _G_) :- 
	origin(A, D, _A_),
	origin(B, D, _B_),
	fd_eq(_A_, _B_, _C_),
	end(A, D, _D_),
	end(B, D, _E_),
	fd_eq(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_).

equals_search(A, B, D, _E_) :- 
	origin_search(A, D, _A_),
	origin_search(B, D, _B_),
	end_search(A, D, _C_),
	end_search(B, D, _D_),
	fd_eq(_A_, _B_),
	fd_eq(_C_, _D_),
	fd_aeq(_E_, 1).

started_by(A, B, D, _G_) :- 
	origin(A, D, _A_),
	origin(B, D, _B_),
	fd_eq(_A_, _B_, _C_),
	end(B, D, _D_),
	end(A, D, _E_),
	fd_lt(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_).

started_by_search(A, B, D, _E_) :- 
	origin_search(A, D, _A_),
	origin_search(B, D, _B_),
	end_search(B, D, _C_),
	end_search(A, D, _D_),
	fd_eq(_A_, _B_),
	fd_lt(_C_, _D_),
	fd_aeq(_E_, 1).

finished_by(A, B, D, _G_) :- 
	origin(B, D, _A_),
	origin(A, D, _B_),
	fd_gt(_A_, _B_, _C_),
	end(A, D, _D_),
	end(B, D, _E_),
	fd_eq(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_).

finished_by_search(A, B, D, _E_) :- 
	origin_search(B, D, _A_),
	origin_search(A, D, _B_),
	end_search(A, D, _C_),
	end_search(B, D, _D_),
	fd_gt(_A_, _B_),
	fd_eq(_C_, _D_),
	fd_aeq(_E_, 1).

during(A, B, D, _G_) :- 
	origin(B, D, _A_),
	origin(A, D, _B_),
	fd_lt(_A_, _B_, _C_),
	end(A, D, _D_),
	end(B, D, _E_),
	fd_lt(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_).

during_search(A, B, D, _E_) :- 
	origin_search(B, D, _A_),
	origin_search(A, D, _B_),
	end_search(A, D, _C_),
	end_search(B, D, _D_),
	fd_lt(_A_, _B_),
	fd_lt(_C_, _D_),
	fd_aeq(_E_, 1).

overlapped_by(A, B, D, _K_) :- 
	origin(B, D, _A_),
	origin(A, D, _B_),
	fd_lt(_A_, _B_, _C_),
	origin(A, D, _D_),
	end(B, D, _E_),
	fd_lt(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_),
	end(A, D, _H_),
	end(B, D, _I_),
	fd_gt(_H_, _I_, _J_),
	fd_and(_G_, _J_, _K_).

overlapped_by_search(A, B, D, _G_) :- 
	origin_search(B, D, _A_),
	origin_search(A, D, _B_),
	origin_search(A, D, _C_),
	end_search(B, D, _D_),
	end_search(A, D, _E_),
	end_search(B, D, _F_),
	fd_lt(_A_, _B_),
	fd_lt(_C_, _D_),
	fd_gt(_E_, _F_),
	fd_aeq(_G_, 1).

met_by(A, B, D, _C_) :- 
	end(B, D, _A_),
	origin(A, D, _B_),
	fd_eq(_A_, _B_, _C_).

met_by_search(A, B, D, _C_) :- 
	end_search(B, D, _A_),
	origin_search(A, D, _B_),
	fd_eq(_A_, _B_),
	fd_aeq(_C_, 1).

preceded_by(A, B, D, _C_) :- 
	end(B, D, _A_),
	origin(A, D, _B_),
	fd_lt(_A_, _B_, _C_).

preceded_by_search(A, B, D, _C_) :- 
	end_search(B, D, _A_),
	origin_search(A, D, _B_),
	fd_lt(_A_, _B_),
	fd_aeq(_C_, 1).

contains_touch(A, B, D, _G_) :- 
	origin(A, D, _A_),
	origin(B, D, _B_),
	fd_leq(_A_, _B_, _C_),
	end(B, D, _D_),
	end(A, D, _E_),
	fd_leq(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_).

contains_touch_search(A, B, D, _E_) :- 
	origin_search(A, D, _A_),
	origin_search(B, D, _B_),
	end_search(B, D, _C_),
	end_search(A, D, _D_),
	fd_leq(_A_, _B_),
	fd_leq(_C_, _D_),
	fd_aeq(_E_, 1).

overlaps_sym(A, B, D, _G_) :- 
	end(A, D, _A_),
	origin(B, D, _B_),
	fd_gt(_A_, _B_, _C_),
	end(B, D, _D_),
	origin(A, D, _E_),
	fd_gt(_D_, _E_, _F_),
	fd_and(_C_, _F_, _G_).

overlaps_sym_search(A, B, D, _E_) :- 
	end_search(A, D, _A_),
	origin_search(B, D, _B_),
	end_search(B, D, _C_),
	origin_search(A, D, _D_),
	fd_gt(_A_, _B_),
	fd_gt(_C_, _D_),
	fd_aeq(_E_, 1).

disjoint_foldl_1([], I_or, _, I_or) :- 
	!.
disjoint_foldl_1([D_58|Tail], I_or, [Ds,O1,O2], _D_) :- 
	precedes(O1, O2, D_58, _A_),
	preceded_by(O1, O2, D_58, _B_),
	fd_or(_A_, _B_, _C_),
	fd_or(I_or, _C_, _E_),
	disjoint_foldl_1(Tail, _E_, [Ds,O1,O2], _D_).

disjoint_foldl_1_search([], I_or, _, I_or) :- 
	!.
disjoint_foldl_1_search([D_58|Tail], I_or, [Ds,O1,O2], _C_) :- 
	(
	rcp_fol_call(I_or)
	;
	(
	precedes_search(O1, O2, D_58, _A_),
	rcp_fol_call(_A_)
	;
	preceded_by_search(O1, O2, D_58, _B_),
	rcp_fol_call(_B_)
	)
	),
	disjoint_foldl_1_search(Tail, _D_, [Ds,O1,O2], _C_).

disjoint(O1, O2, Ds, _A_) :- 
	disjoint_foldl_1(Ds, 0, [Ds,O1,O2], _A_).

disjoint_search(O1, O2, Ds, _A_) :- 
	disjoint_foldl_1_search(Ds, 0, [Ds,O1,O2], _A_).

meet_foldl_1([], I_and, _, I_and) :- 
	!.
meet_foldl_1([D_59|Tail], I_and, [Ds,O1,O2], _F_) :- 
	precedes(O1, O2, D_59, _A_),
	fd_not(_A_, _B_),
	preceded_by(O1, O2, D_59, _C_),
	fd_not(_C_, _D_),
	fd_and(_B_, _D_, _E_),
	fd_and(I_and, _E_, _G_),
	meet_foldl_1(Tail, _G_, [Ds,O1,O2], _F_).

meet_foldl_1_search([], I_and, _, I_and) :- 
	!.
meet_foldl_1_search([D_59|Tail], I_and, [Ds,O1,O2], _E_) :- 
	rcp_fol_call(I_and),
	precedes_search(O1, O2, D_59, _A_),
	fd_not(_A_, _B_),
	rcp_fol_call(_B_),
	preceded_by_search(O1, O2, D_59, _C_),
	fd_not(_C_, _D_),
	rcp_fol_call(_D_),
	meet_foldl_1_search(Tail, _F_, [Ds,O1,O2], _E_).

meet_foldl_2([], I_or, _, I_or) :- 
	!.
meet_foldl_2([D_60|Tail], I_or, [Ds,O1,O2], _D_) :- 
	meets(O1, O2, D_60, _A_),
	met_by(O1, O2, D_60, _B_),
	fd_or(_A_, _B_, _C_),
	fd_or(I_or, _C_, _E_),
	meet_foldl_2(Tail, _E_, [Ds,O1,O2], _D_).

meet_foldl_2_search([], I_or, _, I_or) :- 
	!.
meet_foldl_2_search([D_60|Tail], I_or, [Ds,O1,O2], _C_) :- 
	(
	rcp_fol_call(I_or)
	;
	(
	meets_search(O1, O2, D_60, _A_),
	rcp_fol_call(_A_)
	;
	met_by_search(O1, O2, D_60, _B_),
	rcp_fol_call(_B_)
	)
	),
	meet_foldl_2_search(Tail, _D_, [Ds,O1,O2], _C_).

meet(O1, O2, Ds, _C_) :- 
	meet_foldl_1(Ds, 1, [Ds,O1,O2], _A_),
	meet_foldl_2(Ds, 0, [Ds,O1,O2], _B_),
	fd_and(_A_, _B_, _C_).

meet_search(O1, O2, Ds, _C_) :- 
	meet_foldl_1_search(Ds, 1, [Ds,O1,O2], _A_),
	rcp_fol_call(_A_),
	meet_foldl_2_search(Ds, 0, [Ds,O1,O2], _B_),
	rcp_fol_call(_B_),
	fd_aeq(_C_, 1).

equal_foldl_1([], I_and, _, I_and) :- 
	!.
equal_foldl_1([D_61|Tail], I_and, [Ds,O1,O2], _B_) :- 
	equals(O1, O2, D_61, _A_),
	fd_and(I_and, _A_, _C_),
	equal_foldl_1(Tail, _C_, [Ds,O1,O2], _B_).

equal_foldl_1_search([], I_and, _, I_and) :- 
	!.
equal_foldl_1_search([D_61|Tail], I_and, [Ds,O1,O2], _B_) :- 
	equals_search(O1, O2, D_61, _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	equal_foldl_1_search(Tail, _C_, [Ds,O1,O2], _B_).

equal(O1, O2, Ds, _A_) :- 
	equal_foldl_1(Ds, 1, [Ds,O1,O2], _A_).

equal_search(O1, O2, Ds, _A_) :- 
	equal_foldl_1_search(Ds, 1, [Ds,O1,O2], _A_).

covers_foldl_1([], I_and, _, I_and) :- 
	!.
covers_foldl_1([D_62|Tail], I_and, [Ds,O1,O2], _F_) :- 
	started_by(O1, O2, D_62, _A_),
	contains(O1, O2, D_62, _B_),
	fd_or(_A_, _B_, _C_),
	finished_by(O1, O2, D_62, _D_),
	fd_or(_C_, _D_, _E_),
	fd_and(I_and, _E_, _G_),
	covers_foldl_1(Tail, _G_, [Ds,O1,O2], _F_).

covers_foldl_1_search([], I_and, _, I_and) :- 
	!.
covers_foldl_1_search([D_62|Tail], I_and, [Ds,O1,O2], _D_) :- 
	rcp_fol_call(I_and),
	(
	(
	started_by_search(O1, O2, D_62, _A_),
	rcp_fol_call(_A_)
	;
	contains_search(O1, O2, D_62, _B_),
	rcp_fol_call(_B_)
	)
	;
	finished_by_search(O1, O2, D_62, _C_),
	rcp_fol_call(_C_)
	),
	covers_foldl_1_search(Tail, _E_, [Ds,O1,O2], _D_).

covers_foldl_2([], I_or, _, I_or) :- 
	!.
covers_foldl_2([D_63|Tail], I_or, [Ds,O1,O2], _C_) :- 
	contains(O1, O2, D_63, _A_),
	fd_not(_A_, _B_),
	fd_or(I_or, _B_, _D_),
	covers_foldl_2(Tail, _D_, [Ds,O1,O2], _C_).

covers_foldl_2_search([], I_or, _, I_or) :- 
	!.
covers_foldl_2_search([D_63|Tail], I_or, [Ds,O1,O2], _C_) :- 
	contains_search(O1, O2, D_63, _A_),
	fd_not(_A_, _B_),
	(
	rcp_fol_call(I_or)
	;
	rcp_fol_call(_B_)
	),
	covers_foldl_2_search(Tail, _D_, [Ds,O1,O2], _C_).

covers(O1, O2, Ds, _C_) :- 
	covers_foldl_1(Ds, 1, [Ds,O1,O2], _A_),
	covers_foldl_2(Ds, 0, [Ds,O1,O2], _B_),
	fd_and(_A_, _B_, _C_).

covers_search(O1, O2, Ds, _C_) :- 
	covers_foldl_1_search(Ds, 1, [Ds,O1,O2], _A_),
	rcp_fol_call(_A_),
	covers_foldl_2_search(Ds, 0, [Ds,O1,O2], _B_),
	rcp_fol_call(_B_),
	fd_aeq(_C_, 1).

covered_by_foldl_1([], I_and, _, I_and) :- 
	!.
covered_by_foldl_1([D_64|Tail], I_and, [Ds,O1,O2], _F_) :- 
	starts(O1, O2, D_64, _A_),
	during(O1, O2, D_64, _B_),
	fd_or(_A_, _B_, _C_),
	finishes(O1, O2, D_64, _D_),
	fd_or(_C_, _D_, _E_),
	fd_and(I_and, _E_, _G_),
	covered_by_foldl_1(Tail, _G_, [Ds,O1,O2], _F_).

covered_by_foldl_1_search([], I_and, _, I_and) :- 
	!.
covered_by_foldl_1_search([D_64|Tail], I_and, [Ds,O1,O2], _D_) :- 
	rcp_fol_call(I_and),
	(
	(
	starts_search(O1, O2, D_64, _A_),
	rcp_fol_call(_A_)
	;
	during_search(O1, O2, D_64, _B_),
	rcp_fol_call(_B_)
	)
	;
	finishes_search(O1, O2, D_64, _C_),
	rcp_fol_call(_C_)
	),
	covered_by_foldl_1_search(Tail, _E_, [Ds,O1,O2], _D_).

covered_by_foldl_2([], I_or, _, I_or) :- 
	!.
covered_by_foldl_2([D_65|Tail], I_or, [Ds,O1,O2], _C_) :- 
	during(O1, O2, D_65, _A_),
	fd_not(_A_, _B_),
	fd_or(I_or, _B_, _D_),
	covered_by_foldl_2(Tail, _D_, [Ds,O1,O2], _C_).

covered_by_foldl_2_search([], I_or, _, I_or) :- 
	!.
covered_by_foldl_2_search([D_65|Tail], I_or, [Ds,O1,O2], _C_) :- 
	during_search(O1, O2, D_65, _A_),
	fd_not(_A_, _B_),
	(
	rcp_fol_call(I_or)
	;
	rcp_fol_call(_B_)
	),
	covered_by_foldl_2_search(Tail, _D_, [Ds,O1,O2], _C_).

covered_by(O1, O2, Ds, _C_) :- 
	covered_by_foldl_1(Ds, 1, [Ds,O1,O2], _A_),
	covered_by_foldl_2(Ds, 0, [Ds,O1,O2], _B_),
	fd_and(_A_, _B_, _C_).

covered_by_search(O1, O2, Ds, _C_) :- 
	covered_by_foldl_1_search(Ds, 1, [Ds,O1,O2], _A_),
	rcp_fol_call(_A_),
	covered_by_foldl_2_search(Ds, 0, [Ds,O1,O2], _B_),
	rcp_fol_call(_B_),
	fd_aeq(_C_, 1).

contains_rcc_foldl_1([], I_and, _, I_and) :- 
	!.
contains_rcc_foldl_1([D_66|Tail], I_and, [Ds,O1,O2], _B_) :- 
	contains(O1, O2, D_66, _A_),
	fd_and(I_and, _A_, _C_),
	contains_rcc_foldl_1(Tail, _C_, [Ds,O1,O2], _B_).

contains_rcc_foldl_1_search([], I_and, _, I_and) :- 
	!.
contains_rcc_foldl_1_search([D_66|Tail], I_and, [Ds,O1,O2], _B_) :- 
	contains_search(O1, O2, D_66, _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	contains_rcc_foldl_1_search(Tail, _C_, [Ds,O1,O2], _B_).

contains_rcc(O1, O2, Ds, _A_) :- 
	contains_rcc_foldl_1(Ds, 1, [Ds,O1,O2], _A_).

contains_rcc_search(O1, O2, Ds, _A_) :- 
	contains_rcc_foldl_1_search(Ds, 1, [Ds,O1,O2], _A_).

inside_foldl_1([], I_and, _, I_and) :- 
	!.
inside_foldl_1([D_67|Tail], I_and, [Ds,O1,O2], _B_) :- 
	during(O1, O2, D_67, _A_),
	fd_and(I_and, _A_, _C_),
	inside_foldl_1(Tail, _C_, [Ds,O1,O2], _B_).

inside_foldl_1_search([], I_and, _, I_and) :- 
	!.
inside_foldl_1_search([D_67|Tail], I_and, [Ds,O1,O2], _B_) :- 
	during_search(O1, O2, D_67, _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	inside_foldl_1_search(Tail, _C_, [Ds,O1,O2], _B_).

inside(O1, O2, Ds, _A_) :- 
	inside_foldl_1(Ds, 1, [Ds,O1,O2], _A_).

inside_search(O1, O2, Ds, _A_) :- 
	inside_foldl_1_search(Ds, 1, [Ds,O1,O2], _A_).

overlap_foldl_1([], I_and, _, I_and) :- 
	!.
overlap_foldl_1([D_68|Tail], I_and, [Ds,O1,O2], _B_) :- 
	overlaps_sym(O1, O2, D_68, _A_),
	fd_and(I_and, _A_, _C_),
	overlap_foldl_1(Tail, _C_, [Ds,O1,O2], _B_).

overlap_foldl_1_search([], I_and, _, I_and) :- 
	!.
overlap_foldl_1_search([D_68|Tail], I_and, [Ds,O1,O2], _B_) :- 
	overlaps_sym_search(O1, O2, D_68, _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	overlap_foldl_1_search(Tail, _C_, [Ds,O1,O2], _B_).

overlap(O1, O2, Ds, _A_) :- 
	overlap_foldl_1(Ds, 1, [Ds,O1,O2], _A_).

overlap_search(O1, O2, Ds, _A_) :- 
	overlap_foldl_1_search(Ds, 1, [Ds,O1,O2], _A_).

contains_touch_rcc_foldl_1([], I_and, _, I_and) :- 
	!.
contains_touch_rcc_foldl_1([D_69|Tail], I_and, [Ds,O1,O2], _B_) :- 
	contains_touch(O1, O2, D_69, _A_),
	fd_and(I_and, _A_, _C_),
	contains_touch_rcc_foldl_1(Tail, _C_, [Ds,O1,O2], _B_).

contains_touch_rcc_foldl_1_search([], I_and, _, I_and) :- 
	!.
contains_touch_rcc_foldl_1_search([D_69|Tail], I_and, [Ds,O1,O2], _B_) :- 
	contains_touch_search(O1, O2, D_69, _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	contains_touch_rcc_foldl_1_search(Tail, _C_, [Ds,O1,O2], _B_).

contains_touch_rcc(O1, O2, Ds, _A_) :- 
	contains_touch_rcc_foldl_1(Ds, 1, [Ds,O1,O2], _A_).

contains_touch_rcc_search(O1, O2, Ds, _A_) :- 
	contains_touch_rcc_foldl_1_search(Ds, 1, [Ds,O1,O2], _A_).

above(O1, O2, _E_) :- 
	overlap(O1, O2, [1,2], _A_),
	preceded_by(O1, O2, 3, _B_),
	fd_and(_A_, _B_, _C_),
	met_by(O1, O2, 3, _D_),
	fd_or(_C_, _D_, _E_).

above_search(O1, O2, _D_) :- 
	(
	overlap_search(O1, O2, [1,2], _A_),
	rcp_fol_call(_A_),
	preceded_by_search(O1, O2, 3, _B_),
	rcp_fol_call(_B_)
	;
	met_by_search(O1, O2, 3, _C_),
	rcp_fol_call(_C_)
	),
	fd_aeq(_D_, 1).

on_top(O1, O2, _C_) :- 
	overlap(O1, O2, [1,2], _A_),
	met_by(O1, O2, 3, _B_),
	fd_and(_A_, _B_, _C_).

on_top_search(O1, O2, _C_) :- 
	overlap_search(O1, O2, [1,2], _A_),
	rcp_fol_call(_A_),
	met_by_search(O1, O2, 3, _B_),
	rcp_fol_call(_B_),
	fd_aeq(_C_, 1).

stack_oversize_foldl_3([], I_and, _, I_and) :- 
	!.
stack_oversize_foldl_3([D_75|Tail], I_and, [Items,Length,O1_70,O2_73], _C_) :- 
	oversize(O1_70, O2_73, D_75, _A_),
	fd_leq(_A_, Length, _B_),
	fd_and(I_and, _B_, _D_),
	stack_oversize_foldl_3(Tail, _D_, [Items,Length,O1_70,O2_73], _C_).

stack_oversize_foldl_3_search([], I_and, _, I_and) :- 
	!.
stack_oversize_foldl_3_search([D_75|Tail], I_and, [Items,Length,O1_70,O2_73], _B_) :- 
	oversize_search(O1_70, O2_73, D_75, _A_),
	rcp_fol_call(I_and),
	fd_leq_search(_A_, Length, _C_),
	rcp_fol_call(_C_),
	stack_oversize_foldl_3_search(Tail, _D_, [Items,Length,O1_70,O2_73], _B_).

stack_oversize_foldl_2([], I_and, _, I_and) :- 
	!.
stack_oversize_foldl_2([O2_73|Tail], I_and, [Items,Length,O1_70], _H_) :- 
	overlap(O1_70, O2_73, [1,2], _A_),
	rcp_att(uid, O1_70, _B_),
	rcp_att(uid, O2_73, _C_),
	fd_neq(_B_, _C_, _D_),
	fd_and(_A_, _D_, _E_),
	stack_oversize_foldl_3([1,2], 1, [Items,Length,O1_70,O2_73], _F_),
	fd_implies(_E_, _F_, _G_),
	fd_and(I_and, _G_, _I_),
	stack_oversize_foldl_2(Tail, _I_, [Items,Length,O1_70], _H_).

stack_oversize_foldl_2_search([], I_and, _, I_and) :- 
	!.
stack_oversize_foldl_2_search([O2_73|Tail], I_and, [Items,Length,O1_70], _J_) :- 
	rcp_att(uid, O1_70, _B_),
	rcp_att(uid, O2_73, _C_),
	rcp_att(uid, O1_70, _F_),
	rcp_att(uid, O2_73, _G_),
	(
	overlap_search(O1_70, O2_73, [1,2], _A_),
	rcp_fol_call(_A_),
	fd_neq(_B_, _C_),
	stack_oversize_foldl_3_search([1,2], 1, [Items,Length,O1_70,O2_73], _H_),
	fd_equiv(_H_, _I_, 1)
	;
	(
	overlap_search(O1_70, O2_73, [1,2], _D_),
	fd_not(_D_, _E_),
	rcp_fol_call(_E_)
	;
	fd_eq(_F_, _G_)
	),
	fd_aeq(_I_, 1)
	),
	rcp_fol_call(I_and),
	rcp_fol_call(_I_),
	stack_oversize_foldl_2_search(Tail, _K_, [Items,Length,O1_70], _J_).

stack_oversize_foldl_1([], I_and, _, I_and) :- 
	!.
stack_oversize_foldl_1([O1_70|Tail], I_and, [Items,Length], _B_) :- 
	stack_oversize_foldl_2(Items, 1, [Items,Length,O1_70], _A_),
	fd_and(I_and, _A_, _C_),
	stack_oversize_foldl_1(Tail, _C_, [Items,Length], _B_).

stack_oversize_foldl_1_search([], I_and, _, I_and) :- 
	!.
stack_oversize_foldl_1_search([O1_70|Tail], I_and, [Items,Length], _B_) :- 
	stack_oversize_foldl_2_search(Items, 1, [Items,Length,O1_70], _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	stack_oversize_foldl_1_search(Tail, _C_, [Items,Length], _B_).

stack_oversize(Items, Length, _A_) :- 
	stack_oversize_foldl_1(Items, 1, [Items,Length], _A_).

stack_oversize_search(Items, Length, _A_) :- 
	stack_oversize_foldl_1_search(Items, 1, [Items,Length], _A_).

lighter(O1, O2, _C_) :- 
	rcp_att(weight, O1, _A_),
	rcp_att(weight, O2, _B_),
	fd_leq(_A_, _B_, _C_).

lighter_search(O1, O2, _C_) :- 
	rcp_att(weight, O1, _A_),
	rcp_att(weight, O2, _B_),
	fd_leq(_A_, _B_),
	fd_aeq(_C_, 1).

heavier(O1, O2, _C_) :- 
	rcp_att(weight, O1, _A_),
	rcp_att(weight, O2, _B_),
	fd_geq(_A_, _B_, _C_).

heavier_search(O1, O2, _C_) :- 
	rcp_att(weight, O1, _A_),
	rcp_att(weight, O2, _B_),
	fd_geq(_A_, _B_),
	fd_aeq(_C_, 1).

gravity_foldl_2([], I_or, _, I_or) :- 
	!.
gravity_foldl_2([O2_78|Tail], I_or, [Items,O1_76], _F_) :- 
	rcp_att(uid, O1_76, _A_),
	rcp_att(uid, O2_78, _B_),
	fd_neq(_A_, _B_, _C_),
	on_top(O1_76, O2_78, _D_),
	fd_and(_C_, _D_, _E_),
	fd_or(I_or, _E_, _G_),
	gravity_foldl_2(Tail, _G_, [Items,O1_76], _F_).

gravity_foldl_2_search([], I_or, _, I_or) :- 
	!.
gravity_foldl_2_search([O2_78|Tail], I_or, [Items,O1_76], _D_) :- 
	rcp_att(uid, O1_76, _A_),
	rcp_att(uid, O2_78, _B_),
	(
	rcp_fol_call(I_or)
	;
	fd_neq(_A_, _B_),
	on_top_search(O1_76, O2_78, _C_),
	rcp_fol_call(_C_)
	),
	gravity_foldl_2_search(Tail, _E_, [Items,O1_76], _D_).

gravity_foldl_1([], I_and, _, I_and) :- 
	!.
gravity_foldl_1([O1_76|Tail], I_and, [Items], _E_) :- 
	origin(O1_76, 3, _A_),
	fd_eq(_A_, 0, _B_),
	gravity_foldl_2(Items, 0, [Items,O1_76], _C_),
	fd_or(_B_, _C_, _D_),
	fd_and(I_and, _D_, _F_),
	gravity_foldl_1(Tail, _F_, [Items], _E_).

gravity_foldl_1_search([], I_and, _, I_and) :- 
	!.
gravity_foldl_1_search([O1_76|Tail], I_and, [Items], _C_) :- 
	origin_search(O1_76, 3, _A_),
	rcp_fol_call(I_and),
	(
	fd_eq(_A_, 0)
	;
	gravity_foldl_2_search(Items, 0, [Items,O1_76], _B_),
	rcp_fol_call(_B_)
	),
	gravity_foldl_1_search(Tail, _D_, [Items], _C_).

gravity(Items, _A_) :- 
	gravity_foldl_1(Items, 1, [Items], _A_).

gravity_search(Items, _A_) :- 
	gravity_foldl_1_search(Items, 1, [Items], _A_).

weight_stacking_foldl_2([], I_and, _, I_and) :- 
	!.
weight_stacking_foldl_2([O2_81|Tail], I_and, [Items,O1_79], _H_) :- 
	rcp_att(uid, O1_79, _A_),
	rcp_att(uid, O2_81, _B_),
	fd_neq(_A_, _B_, _C_),
	above(O1_79, O2_81, _D_),
	fd_and(_C_, _D_, _E_),
	lighter(O1_79, O2_81, _F_),
	fd_implies(_E_, _F_, _G_),
	fd_and(I_and, _G_, _I_),
	weight_stacking_foldl_2(Tail, _I_, [Items,O1_79], _H_).

weight_stacking_foldl_2_search([], I_and, _, I_and) :- 
	!.
weight_stacking_foldl_2_search([O2_81|Tail], I_and, [Items,O1_79], _J_) :- 
	rcp_att(uid, O1_79, _A_),
	rcp_att(uid, O2_81, _B_),
	rcp_att(uid, O1_79, _D_),
	rcp_att(uid, O2_81, _E_),
	(
	fd_neq(_A_, _B_),
	above_search(O1_79, O2_81, _C_),
	rcp_fol_call(_C_),
	lighter_search(O1_79, O2_81, _H_),
	fd_equiv(_H_, _I_, 1)
	;
	(
	fd_eq(_D_, _E_)
	;
	above_search(O1_79, O2_81, _F_),
	fd_not(_F_, _G_),
	rcp_fol_call(_G_)
	),
	fd_aeq(_I_, 1)
	),
	rcp_fol_call(I_and),
	rcp_fol_call(_I_),
	weight_stacking_foldl_2_search(Tail, _K_, [Items,O1_79], _J_).

weight_stacking_foldl_1([], I_and, _, I_and) :- 
	!.
weight_stacking_foldl_1([O1_79|Tail], I_and, [Items], _B_) :- 
	weight_stacking_foldl_2(Items, 1, [Items,O1_79], _A_),
	fd_and(I_and, _A_, _C_),
	weight_stacking_foldl_1(Tail, _C_, [Items], _B_).

weight_stacking_foldl_1_search([], I_and, _, I_and) :- 
	!.
weight_stacking_foldl_1_search([O1_79|Tail], I_and, [Items], _B_) :- 
	weight_stacking_foldl_2_search(Items, 1, [Items,O1_79], _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	weight_stacking_foldl_1_search(Tail, _C_, [Items], _B_).

weight_stacking(Items, _A_) :- 
	weight_stacking_foldl_1(Items, 1, [Items], _A_).

weight_stacking_search(Items, _A_) :- 
	weight_stacking_foldl_1_search(Items, 1, [Items], _A_).

weight_balancing_foldr_1([], _, []) :- 
	!.
weight_balancing_foldr_1([Il_82|Tail], [Bin,D,Items,Ratio], [_F_|_G_]) :- 
	weight_balancing_foldr_1(Tail, [Bin,D,Items,Ratio], _G_),
	rcp_att(weight, Il_82, _A_),
	end(Il_82, D, _B_),
	end(Bin, D, _C_),
	fd_aeq(_C_/2, _D_),
	fd_leq(_B_, _D_, _E_),
	fd_aeq(_A_*_E_, _F_).

weight_balancing_foldr_1_search([], _, []) :- 
	!.
weight_balancing_foldr_1_search([Il_82|Tail], [Bin,D,Items,Ratio], [_E_|_F_]) :- 
	weight_balancing_foldr_1_search(Tail, [Bin,D,Items,Ratio], _F_),
	rcp_att(weight, Il_82, _A_),
	end_search(Il_82, D, _B_),
	end_search(Bin, D, _C_),
	fd_aeq(_C_/2, _D_),
	fd_aeq(_A_*fd_leq(_B_,_D_), _E_).

weight_balancing_foldr_2([], _, []) :- 
	!.
weight_balancing_foldr_2([Ir_86|Tail], [Bin,D,Items,Ratio], [_F_|_G_]) :- 
	weight_balancing_foldr_2(Tail, [Bin,D,Items,Ratio], _G_),
	rcp_att(weight, Ir_86, _A_),
	origin(Ir_86, D, _B_),
	end(Bin, D, _C_),
	fd_aeq(_C_/2, _D_),
	fd_geq(_B_, _D_, _E_),
	fd_aeq(_A_*_E_, _F_).

weight_balancing_foldr_2_search([], _, []) :- 
	!.
weight_balancing_foldr_2_search([Ir_86|Tail], [Bin,D,Items,Ratio], [_E_|_F_]) :- 
	weight_balancing_foldr_2_search(Tail, [Bin,D,Items,Ratio], _F_),
	rcp_att(weight, Ir_86, _A_),
	origin_search(Ir_86, D, _B_),
	end_search(Bin, D, _C_),
	fd_aeq(_C_/2, _D_),
	fd_aeq(_A_*fd_geq(_B_,_D_), _E_).

weight_balancing(Items, Bin, D, Ratio, _J_) :- 
	weight_balancing_foldr_1(Items, [Bin,D,Items,Ratio], _A_),
	sum(_A_, _B_),
	L_83=_B_,
	weight_balancing_foldr_2(Items, [Bin,D,Items,Ratio], _C_),
	sum(_C_, _D_),
	R_87=_D_,
	fd_aeq(max(L_83,R_87), _E_),
	fd_aeq(100*_E_, _F_),
	fd_aeq(100+Ratio, _G_),
	fd_aeq(min(L_83,R_87), _H_),
	fd_aeq(_G_*_H_, _I_),
	fd_leq(_F_, _I_, _J_).

weight_balancing_search(Items, Bin, D, Ratio, _J_) :- 
	weight_balancing_foldr_1_search(Items, [Bin,D,Items,Ratio], _A_),
	sum_search(_A_, _B_),
	L_83=_B_,
	weight_balancing_foldr_2_search(Items, [Bin,D,Items,Ratio], _C_),
	sum_search(_C_, _D_),
	R_87=_D_,
	fd_aeq(max(L_83,R_87), _E_),
	fd_aeq(100*_E_, _F_),
	fd_aeq(100+Ratio, _G_),
	fd_aeq(min(L_83,R_87), _H_),
	fd_aeq(_G_*_H_, _I_),
	fd_leq(_F_, _I_),
	fd_aeq(_J_, 1).

object_shape_domain(O, _E_) :- 
	rcp_att(shape_index, O, _A_),
	rcp_att(shapes, O, _B_),
	length(_B_, _C_),
	rcp_range([1.._C_], _D_),
	_A_ in _D_,
	fd_aeq(_E_, 1).

object_shape_domain_search(O, _E_) :- 
	rcp_att(shape_index, O, _A_),
	rcp_att(shapes, O, _B_),
	length(_B_, _C_),
	rcp_range([1.._C_], _D_),
	_A_ in _D_,
	fd_aeq(_E_, 1).

object_shape_domains_foldl_1([], I_and, _, I_and) :- 
	!.
object_shape_domains_foldl_1([I_88|Tail], I_and, [Items], _B_) :- 
	object_shape_domain(I_88, _A_),
	fd_and(I_and, _A_, _C_),
	object_shape_domains_foldl_1(Tail, _C_, [Items], _B_).

object_shape_domains_foldl_1_search([], I_and, _, I_and) :- 
	!.
object_shape_domains_foldl_1_search([I_88|Tail], I_and, [Items], _B_) :- 
	object_shape_domain_search(I_88, _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	object_shape_domains_foldl_1_search(Tail, _C_, [Items], _B_).

object_shape_domains(Items, _A_) :- 
	object_shape_domains_foldl_1(Items, 1, [Items], _A_).

object_shape_domains_search(Items, _A_) :- 
	object_shape_domains_foldl_1_search(Items, 1, [Items], _A_).

non_overlapping_binary_foldl_2([], I_and, _, I_and) :- 
	!.
non_overlapping_binary_foldl_2([O2_91|Tail], I_and, [Dims,Items,O1_89], _G_) :- 
	rcp_att(uid, O1_89, _A_),
	rcp_att(uid, O2_91, _B_),
	fd_lt(_A_, _B_, _C_),
	overlap(O1_89, O2_91, Dims, _D_),
	fd_not(_D_, _E_),
	fd_implies(_C_, _E_, _F_),
	fd_and(I_and, _F_, _H_),
	non_overlapping_binary_foldl_2(Tail, _H_, [Dims,Items,O1_89], _G_).

non_overlapping_binary_foldl_2_search([], I_and, _, I_and) :- 
	!.
non_overlapping_binary_foldl_2_search([O2_91|Tail], I_and, [Dims,Items,O1_89], _H_) :- 
	rcp_att(uid, O1_89, _A_),
	rcp_att(uid, O2_91, _B_),
	rcp_att(uid, O1_89, _C_),
	rcp_att(uid, O2_91, _D_),
	(
	fd_lt(_A_, _B_),
	overlap_search(O1_89, O2_91, Dims, _E_),
	fd_not(_E_, _F_),
	fd_equiv(_F_, _G_, 1)
	;
	fd_geq(_C_, _D_),
	fd_aeq(_G_, 1)
	),
	rcp_fol_call(I_and),
	rcp_fol_call(_G_),
	non_overlapping_binary_foldl_2_search(Tail, _I_, [Dims,Items,O1_89], _H_).

non_overlapping_binary_foldl_1([], I_and, _, I_and) :- 
	!.
non_overlapping_binary_foldl_1([O1_89|Tail], I_and, [Dims,Items], _B_) :- 
	non_overlapping_binary_foldl_2(Items, 1, [Dims,Items,O1_89], _A_),
	fd_and(I_and, _A_, _C_),
	non_overlapping_binary_foldl_1(Tail, _C_, [Dims,Items], _B_).

non_overlapping_binary_foldl_1_search([], I_and, _, I_and) :- 
	!.
non_overlapping_binary_foldl_1_search([O1_89|Tail], I_and, [Dims,Items], _B_) :- 
	non_overlapping_binary_foldl_2_search(Items, 1, [Dims,Items,O1_89], _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	non_overlapping_binary_foldl_1_search(Tail, _C_, [Dims,Items], _B_).

non_overlapping_binary(Items, Dims, _A_) :- 
	non_overlapping_binary_foldl_1(Items, 1, [Dims,Items], _A_).

non_overlapping_binary_search(Items, Dims, _A_) :- 
	non_overlapping_binary_foldl_1_search(Items, 1, [Dims,Items], _A_).

geost_foldr_2([], _, []) :- 
	!.
geost_foldr_2([S_94|Tail], [Dims,I_92,Items], [_A_|_B_]) :- 
	geost_foldr_2(Tail, [Dims,I_92,Items], _B_),
	rcp_att(uid, S_94, _A_).

geost_foldr_2_search([], _, []) :- 
	!.
geost_foldr_2_search([S_94|Tail], [Dims,I_92,Items], [_A_|_B_]) :- 
	geost_foldr_2_search(Tail, [Dims,I_92,Items], _B_),
	rcp_att(uid, S_94, _A_).

geost_foldr_1([], _, []) :- 
	!.
geost_foldr_1([I_92|Tail], [Dims,Items], [[_A_,_B_,_D_,_E_]|_F_]) :- 
	geost_foldr_1(Tail, [Dims,Items], _F_),
	rcp_att(uid, I_92, _A_),
	rcp_att(shape_index, I_92, _B_),
	rcp_att(shapes, I_92, _C_),
	geost_foldr_2(_C_, [Dims,I_92,Items], _D_),
	rcp_att(origin, I_92, _E_).

geost_foldr_1_search([], _, []) :- 
	!.
geost_foldr_1_search([I_92|Tail], [Dims,Items], [[_A_,_B_,_D_,_E_]|_F_]) :- 
	geost_foldr_1_search(Tail, [Dims,Items], _F_),
	rcp_att(uid, I_92, _A_),
	rcp_att(shape_index, I_92, _B_),
	rcp_att(shapes, I_92, _C_),
	geost_foldr_2_search(_C_, [Dims,I_92,Items], _D_),
	rcp_att(origin, I_92, _E_).

geost_foldr_5([], _, []) :- 
	!.
geost_foldr_5([SB_100|Tail], [Dims,I_95,Items,S_98], [[_A_,_B_,_D_]|_E_]) :- 
	geost_foldr_5(Tail, [Dims,I_95,Items,S_98], _E_),
	rcp_att(uid, S_98, _A_),
	rcp_att(offset, SB_100, _B_),
	rcp_att(box, SB_100, _C_),
	rcp_att(size, _C_, _D_).

geost_foldr_5_search([], _, []) :- 
	!.
geost_foldr_5_search([SB_100|Tail], [Dims,I_95,Items,S_98], [[_A_,_B_,_D_]|_E_]) :- 
	geost_foldr_5_search(Tail, [Dims,I_95,Items,S_98], _E_),
	rcp_att(uid, S_98, _A_),
	rcp_att(offset, SB_100, _B_),
	rcp_att(box, SB_100, _C_),
	rcp_att(size, _C_, _D_).

geost_foldr_4([], _, []) :- 
	!.
geost_foldr_4([S_98|Tail], [Dims,I_95,Items], [_B_|_C_]) :- 
	geost_foldr_4(Tail, [Dims,I_95,Items], _C_),
	rcp_att(sboxes, S_98, _A_),
	geost_foldr_5(_A_, [Dims,I_95,Items,S_98], _B_).

geost_foldr_4_search([], _, []) :- 
	!.
geost_foldr_4_search([S_98|Tail], [Dims,I_95,Items], [_B_|_C_]) :- 
	geost_foldr_4_search(Tail, [Dims,I_95,Items], _C_),
	rcp_att(sboxes, S_98, _A_),
	geost_foldr_5_search(_A_, [Dims,I_95,Items,S_98], _B_).

geost_foldr_3([], _, []) :- 
	!.
geost_foldr_3([I_95|Tail], [Dims,Items], [_B_|_C_]) :- 
	geost_foldr_3(Tail, [Dims,Items], _C_),
	rcp_att(shapes, I_95, _A_),
	geost_foldr_4(_A_, [Dims,I_95,Items], _B_).

geost_foldr_3_search([], _, []) :- 
	!.
geost_foldr_3_search([I_95|Tail], [Dims,Items], [_B_|_C_]) :- 
	geost_foldr_3_search(Tail, [Dims,Items], _C_),
	rcp_att(shapes, I_95, _A_),
	geost_foldr_4_search(_A_, [Dims,I_95,Items], _B_).

non_overlapping(Items, Dims, _D_) :- 
	geost_foldr_1(Items, [Dims,Items], _A_),
	geost_foldr_3(Items, [Dims,Items], _B_),
	length(Dims, _C_),
	geost(_A_, _B_, _C_, [non_overlapping], _D_).

non_overlapping_search(Items, Dims, _D_) :- 
	geost_foldr_1_search(Items, [Dims,Items], _A_),
	geost_foldr_3_search(Items, [Dims,Items], _B_),
	length(Dims, _C_),
	geost(_A_, _B_, _C_, [non_overlapping], _D_).

containmentAE_foldl_2([], I_or, _, I_or) :- 
	!.
containmentAE_foldl_2([B_103|Tail], I_or, [Bins,Dims,I_101,Items], _B_) :- 
	contains_touch_rcc(B_103, I_101, Dims, _A_),
	fd_or(I_or, _A_, _C_),
	containmentAE_foldl_2(Tail, _C_, [Bins,Dims,I_101,Items], _B_).

containmentAE_foldl_2_search([], I_or, _, I_or) :- 
	!.
containmentAE_foldl_2_search([B_103|Tail], I_or, [Bins,Dims,I_101,Items], _B_) :- 
	contains_touch_rcc_search(B_103, I_101, Dims, _A_),
	(
	rcp_fol_call(I_or)
	;
	rcp_fol_call(_A_)
	),
	containmentAE_foldl_2_search(Tail, _C_, [Bins,Dims,I_101,Items], _B_).

containmentAE_foldl_1([], I_and, _, I_and) :- 
	!.
containmentAE_foldl_1([I_101|Tail], I_and, [Bins,Dims,Items], _B_) :- 
	containmentAE_foldl_2(Bins, 0, [Bins,Dims,I_101,Items], _A_),
	fd_and(I_and, _A_, _C_),
	containmentAE_foldl_1(Tail, _C_, [Bins,Dims,Items], _B_).

containmentAE_foldl_1_search([], I_and, _, I_and) :- 
	!.
containmentAE_foldl_1_search([I_101|Tail], I_and, [Bins,Dims,Items], _B_) :- 
	containmentAE_foldl_2_search(Bins, 0, [Bins,Dims,I_101,Items], _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	containmentAE_foldl_1_search(Tail, _C_, [Bins,Dims,Items], _B_).

containmentAE(Items, Bins, Dims, _A_) :- 
	containmentAE_foldl_1(Items, 1, [Bins,Dims,Items], _A_).

containmentAE_search(Items, Bins, Dims, _A_) :- 
	containmentAE_foldl_1_search(Items, 1, [Bins,Dims,Items], _A_).

bin_packing_binary(Items, Bins, Dims, _C_) :- 
	containmentAE(Items, Bins, Dims, _A_),
	non_overlapping_binary(Items, Dims, _B_),
	fd_and(_A_, _B_, _C_),
	variables(Items, _D_),
	rcp_labeling(_D_).

bin_packing_binary_search(Items, Bins, Dims, _D_) :- 
	variables(Items, _C_),
	containmentAE_search(Items, Bins, Dims, _A_),
	rcp_fol_call(_A_),
	non_overlapping_binary_search(Items, Dims, _B_),
	rcp_fol_call(_B_),
	rcp_labeling(_C_),
	fd_aeq(_D_, 1).

bin_packing(Items, Bins, Dims, _C_) :- 
	containmentAE(Items, Bins, Dims, _A_),
	non_overlapping(Items, Dims, _B_),
	fd_and(_A_, _B_, _C_),
	variables(Items, _D_),
	rcp_labeling(_D_).

bin_packing_search(Items, Bins, Dims, _D_) :- 
	variables(Items, _C_),
	containmentAE_search(Items, Bins, Dims, _A_),
	rcp_fol_call(_A_),
	non_overlapping_search(Items, Dims, _B_),
	rcp_fol_call(_B_),
	rcp_labeling(_C_),
	fd_aeq(_D_, 1).

containmentEA_foldl_2([], I_and, _, I_and) :- 
	!.
containmentEA_foldl_2([I_106|Tail], I_and, [B_104,Bins,Dims,Items], _B_) :- 
	contains_touch_rcc(B_104, I_106, Dims, _A_),
	fd_and(I_and, _A_, _C_),
	containmentEA_foldl_2(Tail, _C_, [B_104,Bins,Dims,Items], _B_).

containmentEA_foldl_2_search([], I_and, _, I_and) :- 
	!.
containmentEA_foldl_2_search([I_106|Tail], I_and, [B_104,Bins,Dims,Items], _B_) :- 
	contains_touch_rcc_search(B_104, I_106, Dims, _A_),
	rcp_fol_call(I_and),
	rcp_fol_call(_A_),
	containmentEA_foldl_2_search(Tail, _C_, [B_104,Bins,Dims,Items], _B_).

containmentEA_foldl_1([], I_or, _, I_or) :- 
	!.
containmentEA_foldl_1([B_104|Tail], I_or, [Bins,Dims,Items], _B_) :- 
	containmentEA_foldl_2(Items, 1, [B_104,Bins,Dims,Items], _A_),
	fd_or(I_or, _A_, _C_),
	containmentEA_foldl_1(Tail, _C_, [Bins,Dims,Items], _B_).

containmentEA_foldl_1_search([], I_or, _, I_or) :- 
	!.
containmentEA_foldl_1_search([B_104|Tail], I_or, [Bins,Dims,Items], _B_) :- 
	containmentEA_foldl_2_search(Items, 1, [B_104,Bins,Dims,Items], _A_),
	(
	rcp_fol_call(I_or)
	;
	rcp_fol_call(_A_)
	),
	containmentEA_foldl_1_search(Tail, _C_, [Bins,Dims,Items], _B_).

containmentEA(Items, Bins, Dims, _A_) :- 
	containmentEA_foldl_1(Bins, 0, [Bins,Dims,Items], _A_).

containmentEA_search(Items, Bins, Dims, _A_) :- 
	containmentEA_foldl_1_search(Bins, 0, [Bins,Dims,Items], _A_).

bin_design(Bin, Items, Dims, _C_) :- 
	containmentEA(Items, [Bin], Dims, _A_),
	non_overlapping(Items, Dims, _B_),
	fd_and(_A_, _B_, _C_),
	volume(Bin, _E_),
	minimize(((variables(Items,_D_),rcp_labeling(_D_)),rcp_labeling([_E_])), _E_),
	true.

bin_design_search(Bin, Items, Dims, _E_) :- 
	volume(Bin, _D_),
	minimize(((variables(Items,_C_),rcp_labeling(_C_)),rcp_labeling([_D_])), _D_),
	containmentEA_search(Items, [Bin], Dims, _A_),
	rcp_fol_call(_A_),
	non_overlapping_search(Items, Dims, _B_),
	rcp_fol_call(_B_),
	fd_aeq(_E_, 1).

solve([O2,O2_2,O2_3,O3,O3_2,O3_3]) :- 
	rcp_var(from(o2,0,1), O2),
	rcp_var(from(o2,0,2), O2_2),
	rcp_var(from(o2,0,3), O2_3),
	rcp_var(from(o3,0,1), O3),
	rcp_var(from(o3,0,2), O3_2),
	rcp_var(from(o3,0,3), O3_3),
	0#=&lt;O2,
	O2+4#=&lt;5,
	0#=&lt;O2_2,
	O2_2+5#=&lt;4,
	0#=&lt;O2_3,
	O2_3+2#=&lt;4,
	0#=&lt;O3,
	O3+5#=&lt;5,
	0#=&lt;O3_2,
	O3_2+4#=&lt;4,
	0#=&lt;O3_3,
	O3_3+2#=&lt;4,
	geost([object(4,3,[O2,O2_2,O2_3],[]),object(8,7,[O3,O3_2,O3_3],[])], [sbox(3,[0,0,0],[4,5,2]),sbox(7,[0,0,0],[5,4,2])], [non_overlapping(objects([4,8]),[1,2,3])]),
	labeling([], [O3_3,O3,O3_2,O2_3,O2,O2_2]).
</pre></body></html>