:- use_module(library(clpfd)).
:- ensure_loaded(['../../interpreter/prolog/r4cp']).
:- init_interpreter.


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

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

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

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

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

s3_search(_A_) :- 
	make_shape_box_search([4,8,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(_C_) :- 
	s2(_A_),
	s3(_B_),
	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(o2,0,4), O2_4),
	make_object([_A_,_B_], [O2,O2_2,O2_3], O2_4, 300, _C_).

o2_search(_C_) :- 
	s2_search(_A_),
	s3_search(_B_),
	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(o2,0,4), O2_4),
	make_object_search([_A_,_B_], [O2,O2_2,O2_3], O2_4, 300, _C_).

o3(_C_) :- 
	s2(_A_),
	s3(_B_),
	rcp_var(from(o3,0,1), O3),
	rcp_var(from(o3,0,2), O3_2),
	rcp_var(from(o3,0,3), O3_3),
	rcp_var(from(o3,0,4), O3_4),
	make_object([_A_,_B_], [O3,O3_2,O3_3], O3_4, 100, _C_).

o3_search(_C_) :- 
	s2_search(_A_),
	s3_search(_B_),
	rcp_var(from(o3,0,1), O3),
	rcp_var(from(o3,0,2), O3_2),
	rcp_var(from(o3,0,3), O3_3),
	rcp_var(from(o3,0,4), O3_4),
	make_object_search([_A_,_B_], [O3,O3_2,O3_3], O3_4, 100, _C_).

o4(_C_) :- 
	s2(_A_),
	s3(_B_),
	rcp_var(from(o4,0,1), O4),
	rcp_var(from(o4,0,2), O4_2),
	rcp_var(from(o4,0,3), O4_3),
	rcp_var(from(o4,0,4), O4_4),
	make_object([_A_,_B_], [O4,O4_2,O4_3], O4_4, 600, _C_).

o4_search(_C_) :- 
	s2_search(_A_),
	s3_search(_B_),
	rcp_var(from(o4,0,1), O4),
	rcp_var(from(o4,0,2), O4_2),
	rcp_var(from(o4,0,3), O4_3),
	rcp_var(from(o4,0,4), O4_4),
	make_object_search([_A_,_B_], [O4,O4_2,O4_3], O4_4, 600, _C_).

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

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

bin(_A_) :- 
	o1(_A_).

bin_search(_A_) :- 
	o1_search(_A_).

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

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

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

sum_foldr_1_search([], _, 0) :- 
	!.
sum_foldr_1_search([X_97|Tail], [L], _B_) :- 
	sum_foldr_1_search(Tail, [L], _A_),
	fd_aeq(X_97+_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_98|Tail], [L], _B_) :- 
	product_foldr_1(Tail, [L], _A_),
	fd_aeq(X_98*_A_, _B_).

product_foldr_1_search([], _, 1) :- 
	!.
product_foldr_1_search([X_98|Tail], [L], _B_) :- 
	product_foldr_1_search(Tail, [L], _A_),
	fd_aeq(X_98*_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_99|Tail], [L], _B_) :- 
	maximum_foldr_1(Tail, [L], _A_),
	fd_aeq(max(X_99,_A_), _B_).

maximum_foldr_1_search([], _, _A_) :- 
	!.
maximum_foldr_1_search([X_99|Tail], [L], _B_) :- 
	maximum_foldr_1_search(Tail, [L], _A_),
	fd_aeq(max(X_99,_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_100|Tail], [L], _B_) :- 
	minimum_foldr_1(Tail, [L], _A_),
	fd_aeq(min(X_100,_A_), _B_).

minimum_foldr_1_search([], _, _A_) :- 
	!.
minimum_foldr_1_search([X_100|Tail], [L], _B_) :- 
	minimum_foldr_1_search(Tail, [L], _A_),
	fd_aeq(min(X_100,_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_101|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_101|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_102|Tail], [S], [_B_|_C_]) :- 
	shape_volume_foldr_1(Tail, [S], _C_),
	rcp_att(box, SB_102, _A_),
	box_volume(_A_, _B_).

shape_volume_foldr_1_search([], _, []) :- 
	!.
shape_volume_foldr_1_search([SB_102|Tail], [S], [_B_|_C_]) :- 
	shape_volume_foldr_1_search(Tail, [S], _C_),
	rcp_att(box, SB_102, _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_103|Tail], [D,S], [_A_|_B_]) :- 
	shape_origin_foldr_1(Tail, [D,S], _B_),
	sbox_offset(SB_103, D, _A_).

shape_origin_foldr_1_search([], _, []) :- 
	!.
shape_origin_foldr_1_search([SB_103|Tail], [D,S], [_A_|_B_]) :- 
	shape_origin_foldr_1_search(Tail, [D,S], _B_),
	sbox_offset_search(SB_103, 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_104|Tail], [D,S], [_A_|_B_]) :- 
	shape_end_foldr_1(Tail, [D,S], _B_),
	sbox_end(SB_104, D, _A_).

shape_end_foldr_1_search([], _, []) :- 
	!.
shape_end_foldr_1_search([SB_104|Tail], [D,S], [_A_|_B_]) :- 
	shape_end_foldr_1_search(Tail, [D,S], _B_),
	sbox_end_search(SB_104, 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_105|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_105),
	fd_eq(_A_, _C_, _D_),
	shape_end(S_105, D, _E_),
	fd_aeq(_D_*_E_, _F_).

end_foldr_1_search([], _, []) :- 
	!.
end_foldr_1_search([S_105|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_105),
	shape_end_search(S_105, 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_106|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_106),
	fd_eq(_A_, _C_, _D_),
	shape_size(S_106, D, _E_),
	fd_aeq(_D_*_E_, _F_).

size_foldr_1_search([], _, []) :- 
	!.
size_foldr_1_search([S_106|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_106),
	shape_size_search(S_106, 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_107|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_107),
	fd_eq(_A_, _C_, _D_),
	shape_volume(S_107, _E_),
	fd_aeq(_D_*_E_, _F_).

volume_foldr_1_search([], _, []) :- 
	!.
volume_foldr_1_search([S_107|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_107),
	shape_volume_search(S_107, _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_).

w(O, _A_) :- 
	size(O, 1, _A_).

w_search(O, _A_) :- 
	size_search(O, 1, _A_).

h(O, _A_) :- 
	size(O, 2, _A_).

h_search(O, _A_) :- 
	size_search(O, 2, _A_).

l(O, _A_) :- 
	size(O, 3, _A_).

l_search(O, _A_) :- 
	size_search(O, 3, _A_).

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_108|Tail], I_or, [Ds,O1,O2], _D_) :- 
	precedes(O1, O2, D_108, _A_),
	preceded_by(O1, O2, D_108, _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_108|Tail], I_or, [Ds,O1,O2], _C_) :- 
	(
	rcp_fol_call(I_or)
	;
	(
	precedes_search(O1, O2, D_108, _A_),
	rcp_fol_call(_A_)
	;
	preceded_by_search(O1, O2, D_108, _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_109|Tail], I_and, [Ds,O1,O2], _F_) :- 
	precedes(O1, O2, D_109, _A_),
	fd_not(_A_, _B_),
	preceded_by(O1, O2, D_109, _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_109|Tail], I_and, [Ds,O1,O2], _E_) :- 
	rcp_fol_call(I_and),
	precedes_search(O1, O2, D_109, _A_),
	fd_not(_A_, _B_),
	rcp_fol_call(_B_),
	preceded_by_search(O1, O2, D_109, _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_110|Tail], I_or, [Ds,O1,O2], _D_) :- 
	meets(O1, O2, D_110, _A_),
	met_by(O1, O2, D_110, _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_110|Tail], I_or, [Ds,O1,O2], _C_) :- 
	(
	rcp_fol_call(I_or)
	;
	(
	meets_search(O1, O2, D_110, _A_),
	rcp_fol_call(_A_)
	;
	met_by_search(O1, O2, D_110, _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_111|Tail], I_and, [Ds,O1,O2], _B_) :- 
	equals(O1, O2, D_111, _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_111|Tail], I_and, [Ds,O1,O2], _B_) :- 
	equals_search(O1, O2, D_111, _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_112|Tail], I_and, [Ds,O1,O2], _F_) :- 
	started_by(O1, O2, D_112, _A_),
	contains(O1, O2, D_112, _B_),
	fd_or(_A_, _B_, _C_),
	finished_by(O1, O2, D_112, _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_112|Tail], I_and, [Ds,O1,O2], _D_) :- 
	rcp_fol_call(I_and),
	(
	(
	started_by_search(O1, O2, D_112, _A_),
	rcp_fol_call(_A_)
	;
	contains_search(O1, O2, D_112, _B_),
	rcp_fol_call(_B_)
	)
	;
	finished_by_search(O1, O2, D_112, _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_113|Tail], I_or, [Ds,O1,O2], _C_) :- 
	contains(O1, O2, D_113, _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_113|Tail], I_or, [Ds,O1,O2], _C_) :- 
	contains_search(O1, O2, D_113, _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_114|Tail], I_and, [Ds,O1,O2], _F_) :- 
	starts(O1, O2, D_114, _A_),
	during(O1, O2, D_114, _B_),
	fd_or(_A_, _B_, _C_),
	finishes(O1, O2, D_114, _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_114|Tail], I_and, [Ds,O1,O2], _D_) :- 
	rcp_fol_call(I_and),
	(
	(
	starts_search(O1, O2, D_114, _A_),
	rcp_fol_call(_A_)
	;
	during_search(O1, O2, D_114, _B_),
	rcp_fol_call(_B_)
	)
	;
	finishes_search(O1, O2, D_114, _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_115|Tail], I_or, [Ds,O1,O2], _C_) :- 
	during(O1, O2, D_115, _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_115|Tail], I_or, [Ds,O1,O2], _C_) :- 
	during_search(O1, O2, D_115, _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_116|Tail], I_and, [Ds,O1,O2], _B_) :- 
	contains(O1, O2, D_116, _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_116|Tail], I_and, [Ds,O1,O2], _B_) :- 
	contains_search(O1, O2, D_116, _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_117|Tail], I_and, [Ds,O1,O2], _B_) :- 
	during(O1, O2, D_117, _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_117|Tail], I_and, [Ds,O1,O2], _B_) :- 
	during_search(O1, O2, D_117, _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_118|Tail], I_and, [Ds,O1,O2], _B_) :- 
	overlaps_sym(O1, O2, D_118, _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_118|Tail], I_and, [Ds,O1,O2], _B_) :- 
	overlaps_sym_search(O1, O2, D_118, _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_119|Tail], I_and, [Ds,O1,O2], _B_) :- 
	contains_touch(O1, O2, D_119, _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_119|Tail], I_and, [Ds,O1,O2], _B_) :- 
	contains_touch_search(O1, O2, D_119, _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_125|Tail], I_and, [Items,Length,O1_120,O2_123], _C_) :- 
	oversize(O1_120, O2_123, D_125, _A_),
	fd_leq(_A_, Length, _B_),
	fd_and(I_and, _B_, _D_),
	stack_oversize_foldl_3(Tail, _D_, [Items,Length,O1_120,O2_123], _C_).

stack_oversize_foldl_3_search([], I_and, _, I_and) :- 
	!.
stack_oversize_foldl_3_search([D_125|Tail], I_and, [Items,Length,O1_120,O2_123], _B_) :- 
	oversize_search(O1_120, O2_123, D_125, _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_120,O2_123], _B_).

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

stack_oversize_foldl_2_search([], I_and, _, I_and) :- 
	!.
stack_oversize_foldl_2_search([O2_123|Tail], I_and, [Items,Length,O1_120], _J_) :- 
	rcp_att(uid, O1_120, _B_),
	rcp_att(uid, O2_123, _C_),
	rcp_att(uid, O1_120, _F_),
	rcp_att(uid, O2_123, _G_),
	(
	overlap_search(O1_120, O2_123, [1,2], _A_),
	rcp_fol_call(_A_),
	fd_neq(_B_, _C_),
	stack_oversize_foldl_3_search([1,2], 1, [Items,Length,O1_120,O2_123], _H_),
	fd_equiv(_H_, _I_, 1)
	;
	(
	overlap_search(O1_120, O2_123, [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_120], _J_).

stack_oversize_foldl_1([], I_and, _, I_and) :- 
	!.
stack_oversize_foldl_1([O1_120|Tail], I_and, [Items,Length], _B_) :- 
	stack_oversize_foldl_2(Items, 1, [Items,Length,O1_120], _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_120|Tail], I_and, [Items,Length], _B_) :- 
	stack_oversize_foldl_2_search(Items, 1, [Items,Length,O1_120], _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_128|Tail], I_or, [Items,O1_126], _F_) :- 
	rcp_att(uid, O1_126, _A_),
	rcp_att(uid, O2_128, _B_),
	fd_neq(_A_, _B_, _C_),
	on_top(O1_126, O2_128, _D_),
	fd_and(_C_, _D_, _E_),
	fd_or(I_or, _E_, _G_),
	gravity_foldl_2(Tail, _G_, [Items,O1_126], _F_).

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

gravity_foldl_1([], I_and, _, I_and) :- 
	!.
gravity_foldl_1([O1_126|Tail], I_and, [Items], _E_) :- 
	origin(O1_126, 3, _A_),
	fd_eq(_A_, 0, _B_),
	gravity_foldl_2(Items, 0, [Items,O1_126], _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_126|Tail], I_and, [Items], _C_) :- 
	origin_search(O1_126, 3, _A_),
	rcp_fol_call(I_and),
	(
	fd_eq(_A_, 0)
	;
	gravity_foldl_2_search(Items, 0, [Items,O1_126], _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_131|Tail], I_and, [Items,O1_129], _H_) :- 
	rcp_att(uid, O1_129, _A_),
	rcp_att(uid, O2_131, _B_),
	fd_neq(_A_, _B_, _C_),
	above(O1_129, O2_131, _D_),
	fd_and(_C_, _D_, _E_),
	lighter(O1_129, O2_131, _F_),
	fd_implies(_E_, _F_, _G_),
	fd_and(I_and, _G_, _I_),
	weight_stacking_foldl_2(Tail, _I_, [Items,O1_129], _H_).

weight_stacking_foldl_2_search([], I_and, _, I_and) :- 
	!.
weight_stacking_foldl_2_search([O2_131|Tail], I_and, [Items,O1_129], _J_) :- 
	rcp_att(uid, O1_129, _A_),
	rcp_att(uid, O2_131, _B_),
	rcp_att(uid, O1_129, _D_),
	rcp_att(uid, O2_131, _E_),
	(
	fd_neq(_A_, _B_),
	above_search(O1_129, O2_131, _C_),
	rcp_fol_call(_C_),
	lighter_search(O1_129, O2_131, _H_),
	fd_equiv(_H_, _I_, 1)
	;
	(
	fd_eq(_D_, _E_)
	;
	above_search(O1_129, O2_131, _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_129], _J_).

weight_stacking_foldl_1([], I_and, _, I_and) :- 
	!.
weight_stacking_foldl_1([O1_129|Tail], I_and, [Items], _B_) :- 
	weight_stacking_foldl_2(Items, 1, [Items,O1_129], _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_129|Tail], I_and, [Items], _B_) :- 
	weight_stacking_foldl_2_search(Items, 1, [Items,O1_129], _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_132|Tail], [Bin,D,Items,Ratio], [_F_|_G_]) :- 
	weight_balancing_foldr_1(Tail, [Bin,D,Items,Ratio], _G_),
	rcp_att(weight, Il_132, _A_),
	end(Il_132, 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_132|Tail], [Bin,D,Items,Ratio], [_E_|_F_]) :- 
	weight_balancing_foldr_1_search(Tail, [Bin,D,Items,Ratio], _F_),
	rcp_att(weight, Il_132, _A_),
	end_search(Il_132, 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_136|Tail], [Bin,D,Items,Ratio], [_F_|_G_]) :- 
	weight_balancing_foldr_2(Tail, [Bin,D,Items,Ratio], _G_),
	rcp_att(weight, Ir_136, _A_),
	origin(Ir_136, 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_136|Tail], [Bin,D,Items,Ratio], [_E_|_F_]) :- 
	weight_balancing_foldr_2_search(Tail, [Bin,D,Items,Ratio], _F_),
	rcp_att(weight, Ir_136, _A_),
	origin_search(Ir_136, 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_133=_B_,
	weight_balancing_foldr_2(Items, [Bin,D,Items,Ratio], _C_),
	sum(_C_, _D_),
	R_137=_D_,
	fd_aeq(max(L_133,R_137), _E_),
	fd_aeq(100*_E_, _F_),
	fd_aeq(100+Ratio, _G_),
	fd_aeq(min(L_133,R_137), _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_133=_B_,
	weight_balancing_foldr_2_search(Items, [Bin,D,Items,Ratio], _C_),
	sum_search(_C_, _D_),
	R_137=_D_,
	fd_aeq(max(L_133,R_137), _E_),
	fd_aeq(100*_E_, _F_),
	fd_aeq(100+Ratio, _G_),
	fd_aeq(min(L_133,R_137), _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_138|Tail], I_and, [Items], _B_) :- 
	object_shape_domain(I_138, _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_138|Tail], I_and, [Items], _B_) :- 
	object_shape_domain_search(I_138, _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_141|Tail], I_and, [Dims,Items,O1_139], _G_) :- 
	rcp_att(uid, O1_139, _A_),
	rcp_att(uid, O2_141, _B_),
	fd_lt(_A_, _B_, _C_),
	overlap(O1_139, O2_141, 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_139], _G_).

non_overlapping_binary_foldl_2_search([], I_and, _, I_and) :- 
	!.
non_overlapping_binary_foldl_2_search([O2_141|Tail], I_and, [Dims,Items,O1_139], _H_) :- 
	rcp_att(uid, O1_139, _A_),
	rcp_att(uid, O2_141, _B_),
	rcp_att(uid, O1_139, _C_),
	rcp_att(uid, O2_141, _D_),
	(
	fd_lt(_A_, _B_),
	overlap_search(O1_139, O2_141, 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_139], _H_).

non_overlapping_binary_foldl_1([], I_and, _, I_and) :- 
	!.
non_overlapping_binary_foldl_1([O1_139|Tail], I_and, [Dims,Items], _B_) :- 
	non_overlapping_binary_foldl_2(Items, 1, [Dims,Items,O1_139], _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_139|Tail], I_and, [Dims,Items], _B_) :- 
	non_overlapping_binary_foldl_2_search(Items, 1, [Dims,Items,O1_139], _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_).

non_overlapping(Items, Dims, _A_) :- 
	geost(Items, Dims, _A_).

non_overlapping_search(Items, Dims, _A_) :- 
	geost_search(Items, Dims, _A_).

geost_constraint_foldr_2([], _, []) :- 
	!.
geost_constraint_foldr_2([S_144|Tail], [Dims,I_142,Items], [_A_|_B_]) :- 
	geost_constraint_foldr_2(Tail, [Dims,I_142,Items], _B_),
	rcp_att(uid, S_144, _A_).

geost_constraint_foldr_2_search([], _, []) :- 
	!.
geost_constraint_foldr_2_search([S_144|Tail], [Dims,I_142,Items], [_A_|_B_]) :- 
	geost_constraint_foldr_2_search(Tail, [Dims,I_142,Items], _B_),
	rcp_att(uid, S_144, _A_).

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

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

geost_constraint_foldr_5([], _, []) :- 
	!.
geost_constraint_foldr_5([SB_150|Tail], [Dims,I_145,Items,S_148], [[_A_,_B_,_D_]|_E_]) :- 
	geost_constraint_foldr_5(Tail, [Dims,I_145,Items,S_148], _E_),
	rcp_att(uid, S_148, _A_),
	rcp_att(offset, SB_150, _B_),
	rcp_att(box, SB_150, _C_),
	rcp_att(size, _C_, _D_).

geost_constraint_foldr_5_search([], _, []) :- 
	!.
geost_constraint_foldr_5_search([SB_150|Tail], [Dims,I_145,Items,S_148], [[_A_,_B_,_D_]|_E_]) :- 
	geost_constraint_foldr_5_search(Tail, [Dims,I_145,Items,S_148], _E_),
	rcp_att(uid, S_148, _A_),
	rcp_att(offset, SB_150, _B_),
	rcp_att(box, SB_150, _C_),
	rcp_att(size, _C_, _D_).

geost_constraint_foldr_4([], _, []) :- 
	!.
geost_constraint_foldr_4([S_148|Tail], [Dims,I_145,Items], [_B_|_C_]) :- 
	geost_constraint_foldr_4(Tail, [Dims,I_145,Items], _C_),
	rcp_att(sboxes, S_148, _A_),
	geost_constraint_foldr_5(_A_, [Dims,I_145,Items,S_148], _B_).

geost_constraint_foldr_4_search([], _, []) :- 
	!.
geost_constraint_foldr_4_search([S_148|Tail], [Dims,I_145,Items], [_B_|_C_]) :- 
	geost_constraint_foldr_4_search(Tail, [Dims,I_145,Items], _C_),
	rcp_att(sboxes, S_148, _A_),
	geost_constraint_foldr_5_search(_A_, [Dims,I_145,Items,S_148], _B_).

geost_constraint_foldr_3([], _, []) :- 
	!.
geost_constraint_foldr_3([I_145|Tail], [Dims,Items], [_B_|_C_]) :- 
	geost_constraint_foldr_3(Tail, [Dims,Items], _C_),
	rcp_att(shapes, I_145, _A_),
	geost_constraint_foldr_4(_A_, [Dims,I_145,Items], _B_).

geost_constraint_foldr_3_search([], _, []) :- 
	!.
geost_constraint_foldr_3_search([I_145|Tail], [Dims,Items], [_B_|_C_]) :- 
	geost_constraint_foldr_3_search(Tail, [Dims,Items], _C_),
	rcp_att(shapes, I_145, _A_),
	geost_constraint_foldr_4_search(_A_, [Dims,I_145,Items], _B_).

geost(Items, Dims, _D_) :- 
	geost_constraint_foldr_1(Items, [Dims,Items], _A_),
	geost_constraint_foldr_3(Items, [Dims,Items], _B_),
	length(Dims, _C_),
	geost_constraint(_A_, _B_, _C_, _D_).

geost_search(Items, Dims, _D_) :- 
	geost_constraint_foldr_1_search(Items, [Dims,Items], _A_),
	geost_constraint_foldr_3_search(Items, [Dims,Items], _B_),
	length(Dims, _C_),
	geost_constraint(_A_, _B_, _C_, _D_).

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

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

containmentAE_foldl_1([], I_and, _, I_and) :- 
	!.
containmentAE_foldl_1([I_151|Tail], I_and, [Bins,Dims,Items], _B_) :- 
	containmentAE_foldl_2(Bins, 0, [Bins,Dims,I_151,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_151|Tail], I_and, [Bins,Dims,Items], _B_) :- 
	containmentAE_foldl_2_search(Bins, 0, [Bins,Dims,I_151,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_156|Tail], I_and, [B_154,Bins,Dims,Items], _B_) :- 
	contains_touch_rcc(B_154, I_156, Dims, _A_),
	fd_and(I_and, _A_, _C_),
	containmentEA_foldl_2(Tail, _C_, [B_154,Bins,Dims,Items], _B_).

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

containmentEA_foldl_1([], I_or, _, I_or) :- 
	!.
containmentEA_foldl_1([B_154|Tail], I_or, [Bins,Dims,Items], _B_) :- 
	containmentEA_foldl_2(Items, 1, [B_154,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_154|Tail], I_or, [Bins,Dims,Items], _B_) :- 
	containmentEA_foldl_2_search(Items, 1, [B_154,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).

items_domain_foldl_1([], I_and, _, I_and) :- 
	!.
items_domain_foldl_1([I_157|Tail], I_and, [Bin,Items], _J_) :- 
	x(I_157, _A_),
	variables(_A_, _B_),
	w(Bin, _C_),
	y(I_157, _D_),
	variables(_D_, _E_),
	h(Bin, _F_),
	z(I_157, _G_),
	variables(_G_, _H_),
	l(Bin, _I_),
	domain(_H_, 0, _I_),
	domain(_B_, 0, _C_),
	domain(_E_, 0, _F_),
	items_domain_foldl_1(Tail, I_and, [Bin,Items], _J_).

items_domain_foldl_1_search([], I_and, _, I_and) :- 
	!.
items_domain_foldl_1_search([I_157|Tail], I_and, [Bin,Items], _J_) :- 
	x_search(I_157, _A_),
	variables(_A_, _B_),
	w_search(Bin, _C_),
	y_search(I_157, _D_),
	variables(_D_, _E_),
	h_search(Bin, _F_),
	z_search(I_157, _G_),
	variables(_G_, _H_),
	l_search(Bin, _I_),
	rcp_fol_call(I_and),
	domain(_B_, 0, _C_),
	domain(_E_, 0, _F_),
	domain(_H_, 0, _I_),
	items_domain_foldl_1_search(Tail, _K_, [Bin,Items], _J_).

items_domain(Items, Bin, _A_) :- 
	items_domain_foldl_1(Items, 1, [Bin,Items], _A_).

items_domain_search(Items, Bin, _A_) :- 
	items_domain_foldl_1_search(Items, 1, [Bin,Items], _A_).

solve([O2,O2_2,O2_3,O2_4,O3,O4,O4_4,O3_2,O4_2,O3_3,O3_4,O4_3]) :- 
	R_158#<=>O2_4#=1,
	R_159#<=>O2_4#=2,
	R_160#<=>O2_4#=1,
	R_161#<=>O2_4#=2,
	R_162#<=>O2_4#=1,
	R_163#<=>O2_4#=2,
	R_164#<=>O3_4#=1,
	R_165#<=>O3_4#=2,
	R_166#<=>O3_4#=1,
	R_167#<=>O3_4#=2,
	R_168#<=>O3_4#=1,
	R_169#<=>O3_4#=2,
	R_170#<=>O4_4#=1,
	R_171#<=>O4_4#=2,
	R_172#<=>O4_4#=1,
	R_173#<=>O4_4#=2,
	R_174#<=>O4_4#=1,
	R_175#<=>O4_4#=2,
	S_178 in{6}\/{3},
	element(O2_4, [3,6], S_178),
	S_177 in{6}\/{3},
	element(O3_4, [3,6], S_177),
	S_176 in{6}\/{3},
	element(O4_4, [3,6], S_176),
	R_181#<=>O2_4#=1,
	R_182#<=>O2_4#=2,
	R_183#<=>O3_4#=1,
	R_184#<=>O3_4#=2,
	R_185#<=>O2_4#=1,
	R_186#<=>O2_4#=2,
	R_187#<=>O3_4#=1,
	R_188#<=>O3_4#=2,
	R_189#<=>O3_4#=1,
	R_190#<=>O3_4#=2,
	R_191#<=>O2_4#=1,
	R_192#<=>O2_4#=2,
	R_193#<=>O4_4#=1,
	R_194#<=>O4_4#=2,
	R_195#<=>O2_4#=1,
	R_196#<=>O2_4#=2,
	R_197#<=>O4_4#=1,
	R_198#<=>O4_4#=2,
	R_199#<=>O4_4#=1,
	R_200#<=>O4_4#=2,
	R_201#<=>O3_4#=1,
	R_202#<=>O3_4#=2,
	R_203#<=>O2_4#=1,
	R_204#<=>O2_4#=2,
	R_205#<=>O3_4#=1,
	R_206#<=>O3_4#=2,
	R_207#<=>O2_4#=1,
	R_208#<=>O2_4#=2,
	R_209#<=>O2_4#=1,
	R_210#<=>O2_4#=2,
	R_211#<=>O3_4#=1,
	R_212#<=>O3_4#=2,
	R_213#<=>O4_4#=1,
	R_214#<=>O4_4#=2,
	R_215#<=>O3_4#=1,
	R_216#<=>O3_4#=2,
	R_217#<=>O4_4#=1,
	R_218#<=>O4_4#=2,
	R_219#<=>O4_4#=1,
	R_220#<=>O4_4#=2,
	R_221#<=>O4_4#=1,
	R_222#<=>O4_4#=2,
	R_223#<=>O2_4#=1,
	R_224#<=>O2_4#=2,
	R_225#<=>O4_4#=1,
	R_226#<=>O4_4#=2,
	R_227#<=>O2_4#=1,
	R_228#<=>O2_4#=2,
	R_229#<=>O2_4#=1,
	R_230#<=>O2_4#=2,
	R_231#<=>O4_4#=1,
	R_232#<=>O4_4#=2,
	R_233#<=>O3_4#=1,
	R_234#<=>O3_4#=2,
	R_235#<=>O4_4#=1,
	R_236#<=>O4_4#=2,
	R_237#<=>O3_4#=1,
	R_238#<=>O3_4#=2,
	R_239#<=>O3_4#=1,
	R_240#<=>O3_4#=2,
	R_241#<=>O2_4#=1,
	R_242#<=>O2_4#=2,
	R_243#<=>O3_4#=1,
	R_244#<=>O3_4#=2,
	R_245#<=>O2_4#=1,
	R_246#<=>O2_4#=2,
	R_247#<=>O3_4#=1,
	R_248#<=>O3_4#=2,
	R_249#<=>O3_4#=1,
	R_250#<=>O3_4#=2,
	R_251#<=>O3_4#=1,
	R_252#<=>O3_4#=2,
	R_253#<=>O4_4#=1,
	R_254#<=>O4_4#=2,
	rcp_var(from(o2,0,1), O2),
	R_255#<=>O2_4#=1,
	R_256#<=>O2_4#=2,
	R_257#<=>O4_4#=1,
	R_258#<=>O4_4#=2,
	rcp_var(from(o2,0,2), O2_2),
	R_259#<=>O2_4#=1,
	R_260#<=>O2_4#=2,
	R_261#<=>O2_4#=1,
	R_262#<=>O2_4#=2,
	rcp_var(from(o2,0,3), O2_3),
	R_263#<=>O2_4#=1,
	rcp_var(from(o2,0,4), O2_4),
	R_264#<=>O2_4#=2,
	R_265#<=>O4_4#=1,
	R_266#<=>O4_4#=2,
	rcp_var(from(o3,0,1), O3),
	R_267#<=>O3_4#=1,
	R_268#<=>O3_4#=2,
	rcp_var(from(o4,0,1), O4),
	R_269#<=>O4_4#=1,
	rcp_var(from(o4,0,4), O4_4),
	R_270#<=>O4_4#=2,
	rcp_var(from(o3,0,2), O3_2),
	R_271#<=>O3_4#=1,
	R_272#<=>O3_4#=2,
	rcp_var(from(o4,0,2), O4_2),
	R_273#<=>O3_4#=1,
	R_274#<=>O3_4#=2,
	rcp_var(from(o3,0,3), O3_3),
	R_275#<=>O3_4#=1,
	rcp_var(from(o3,0,4), O3_4),
	R_276#<=>O3_4#=2,
	rcp_var(from(o4,0,3), O4_3),
	domain([O2], 0, 8),
	domain([O2_2], 0, 8),
	domain([O2_3], 0, 4),
	domain([O3], 0, 8),
	domain([O3_2], 0, 8),
	domain([O3_3], 0, 4),
	domain([O4], 0, 8),
	domain([O4_2], 0, 8),
	domain([O4_3], 0, 4),
	O2_4 in 1..2,
	O3_4 in 1..2,
	O4_4 in 1..2,
	0#=<O2,
	O2+(R_158*8+R_159*4)#=<8,
	0#=<O2_2,
	O2_2+(R_160*4+R_161*8)#=<8,
	0#=<O2_3,
	O2_3+(R_162*2+R_163*2)#=<4,
	0#=<O3,
	O3+(R_164*8+R_165*4)#=<8,
	0#=<O3_2,
	O3_2+(R_166*4+R_167*8)#=<8,
	0#=<O3_3,
	O3_3+(R_168*2+R_169*2)#=<4,
	0#=<O4,
	O4+(R_170*8+R_171*4)#=<8,
	0#=<O4_2,
	O4_2+(R_172*4+R_173*8)#=<8,
	0#=<O4_3,
	O4_3+(R_174*2+R_175*2)#=<4,
	geost([object(7,S_178,[O2,O2_2,O2_3],[]),object(8,S_177,[O3,O3_2,O3_3],[]),object(9,S_176,[O4,O4_2,O4_3],[])], [sbox(3,[0,0,0],[8,4,2]),sbox(6,[0,0,0],[4,8,2])], [non_overlapping(objects([7,8,9]),[1,2,3])]),
	labeling([], [O4_4,O4_3,O4,O4_2,O2_4,O2_3,O2,O2_2,O3_4,O3_3,O3,O3_2]),
	O2_3#=0#\/(O2+(R_181*8+R_182*4)#>O3#/\O3+(R_183*8+R_184*4)#>O2#/\(O2_2+(R_185*4+R_186*8)#>O3_2#/\O3_2+(R_187*4+R_188*8)#>O2_2)#/\O3_3+(R_189*2+R_190*2)#=O2_3#\/O2+(R_191*8+R_192*4)#>O4#/\O4+(R_193*8+R_194*4)#>O2#/\(O2_2+(R_195*4+R_196*8)#>O4_2#/\O4_2+(R_197*4+R_198*8)#>O2_2)#/\O4_3+(R_199*2+R_200*2)#=O2_3),
	O3_3#=0#\/(O3+(R_201*8+R_202*4)#>O2#/\O2+(R_203*8+R_204*4)#>O3#/\(O3_2+(R_205*4+R_206*8)#>O2_2#/\O2_2+(R_207*4+R_208*8)#>O3_2)#/\O2_3+(R_209*2+R_210*2)#=O3_3#\/O3+(R_211*8+R_212*4)#>O4#/\O4+(R_213*8+R_214*4)#>O3#/\(O3_2+(R_215*4+R_216*8)#>O4_2#/\O4_2+(R_217*4+R_218*8)#>O3_2)#/\O4_3+(R_219*2+R_220*2)#=O3_3),
	O4_3#=0#\/(O4+(R_221*8+R_222*4)#>O2#/\O2+(R_223*8+R_224*4)#>O4#/\(O4_2+(R_225*4+R_226*8)#>O2_2#/\O2_2+(R_227*4+R_228*8)#>O4_2)#/\O2_3+(R_229*2+R_230*2)#=O4_3#\/O4+(R_231*8+R_232*4)#>O3#/\O3+(R_233*8+R_234*4)#>O4#/\(O4_2+(R_235*4+R_236*8)#>O3_2#/\O3_2+(R_237*4+R_238*8)#>O4_2)#/\O3_3+(R_239*2+R_240*2)#=O4_3),
	O2+(R_241*8+R_242*4)#=<O3#\/O3+(R_243*8+R_244*4)#=<O2#\/(O2_2+(R_245*4+R_246*8)#=<O3_2#\/O3_2+(R_247*4+R_248*8)#=<O2_2)#\/O3_3+(R_249*2+R_250*2)#>=O2_3,
	O3_3+(R_251*2+R_252*2)#\=O2_3,
	O4+(R_253*8+R_254*4)#=<O2#\/O2+(R_255*8+R_256*4)#=<O4#\/(O4_2+(R_257*4+R_258*8)#=<O2_2#\/O2_2+(R_259*4+R_260*8)#=<O4_2)#\/O2_3+(R_261*2+R_262*2)#>=O4_3,
	O2_3+(R_263*2+R_264*2)#\=O4_3,
	O4+(R_265*8+R_266*4)#=<O3#\/O3+(R_267*8+R_268*4)#=<O4#\/(O4_2+(R_269*4+R_270*8)#=<O3_2#\/O3_2+(R_271*4+R_272*8)#=<O4_2)#\/O3_3+(R_273*2+R_274*2)#>=O4_3,
	O3_3+(R_275*2+R_276*2)#\=O4_3.
