%%%[(1,[(n,1),(c,1)]),(2,[(a,1),(b,1)])]
%%% 'ASP_to_CHR'([n(1),(n(_40320):-n(_40342),_40320 is _40342+1,_40320=<2),(a(_40342):-_40320 is _40342+1,n(_40342),not(b(_40342)),not(b(_40320))),(b(_40342):-n(_40342),not(a(_40342))),(c(_40342):-_40320 is _40342+1,n(_40342),not(b(_40320)))],'test_30',all_answer_sets,'no_data')
:- use_module(library(chr)).
:- chr_constraint success/0, failure/0, supported_1/2, exclusion_1/2, supported_2/2, supported_3/1, exclusion_3/1, supported_4/2, exclusion_4/2, launcher/0, next_it/1, cfc/1, clean_result/0, c/1, a/1, out_a/1, b/1, out_b/1, n/1.
success <=> true.
failure <=> fail.
c(X_0) # passive \ c(X_0) <=> true.
a(X_0) # passive \ a(X_0) <=> true.
b(X_0) # passive \ b(X_0) <=> true.
n(X_0) # passive \ n(X_0) <=> true.

a(X_0),out_a(X_0) <=> fail.
b(X_0),out_b(X_0) <=> fail.


%% c(_40342):-_40320 is _40342+1,n(_40342),not(b(_40320))
supported_1 @ n(X_0)==>
   X_1 is X_0+1,true | 
   supported_1(X_0,X_1).
unuseful_1 @ c(X_0) \ supported_1(X_0,X_1)<=>
   success.
propagate_1 @ out_b(X_0) \ supported_1(X_1,X_0)<=>
   c(X_1).
blocked_1 @ b(X_0) \ supported_1(X_1,X_0)<=>
   success.
exclusion_1 @ out_b(X_1),exclusion_1(X_0,X_1)<=>
   failure.
clean_exclusion_1 @ b(X_0) \ exclusion_1(X_1,X_0)<=>
   success.

%% n(_40320):-n(_40342),_40320 is _40342+1,_40320=<2
propagate_2 @ n(X_0)==>
   X_1 is X_0+1,X_1=< 2 | 
   n(X_1).

%% b(_40342):-n(_40342),not(a(_40342))
supported_3 @ n(X_0)==>
   true | 
   supported_3(X_0).
unuseful_3 @ b(X_0) \ supported_3(X_0)<=>
   success.
propagate_3 @ out_a(X_0) \ supported_3(X_0)<=>
   b(X_0).
blocked_3 @ a(X_0) \ supported_3(X_0)<=>
   success.
exclusion_3 @ out_a(X_0),exclusion_3(X_0)<=>
   failure.
clean_exclusion_3 @ a(X_0) \ exclusion_3(X_0)<=>
   success.

%% a(_40342):-_40320 is _40342+1,n(_40342),not(b(_40342)),not(b(_40320))
supported_4 @ n(X_0)==>
   X_1 is X_0+1,true | 
   supported_4(X_0,X_1).
unuseful_4 @ a(X_0) \ supported_4(X_0,X_1)<=>
   success.
propagate_4 @ out_b(X_1),out_b(X_0) \ supported_4(X_0,X_1)<=>
   a(X_0).
blocked_4 @ b(X_0) \ supported_4(X_0,X_1)<=>
   success.
blocked_4 @ b(X_0) \ supported_4(X_1,X_0)<=>
   success.
exclusion_4 @ out_b(X_1),out_b(X_0),exclusion_4(X_0,X_1)<=>
   failure.
clean_exclusion_4 @ b(X_0) \ exclusion_4(X_0,X_1)<=>
   success.
clean_exclusion_4 @ b(X_0) \ exclusion_4(X_1,X_0)<=>
   success.
choice_1 @ next_it(X_2),supported_1(X_0,X_1) # passive <=>
   X_3 is X_2*2, out_b(X_1),c(X_0),next_it(X_3) ; X_3 is X_2*2+1, exclusion_1(X_0,X_1),next_it(X_3).
choice_3 @ next_it(X_1),supported_3(X_0) # passive <=>
   X_2 is X_1*2, out_a(X_0),b(X_0),next_it(X_2) ; X_2 is X_1*2+1, exclusion_3(X_0),next_it(X_2).
choice_4 @ next_it(X_2),supported_4(X_0,X_1) # passive <=>
   X_3 is X_2*2, out_b(X_0),out_b(X_1),a(X_0),next_it(X_3) ; X_3 is X_2*2+1, exclusion_4(X_0,X_1),next_it(X_3).




next_it(_Profondeur), exclusion_1(X2,X1)# passive <=> fail.
next_it(_Profondeur), exclusion_3(X1)# passive <=> fail.
next_it(_Profondeur), exclusion_4(X2,X1)# passive <=> fail.

success @ next_it(_Profondeur) <=> clean_result, chr_show_store(user),  write("--"), nl, fail.

launcher <=> n(1), 
   next_it(0).

clean_result, out_a(X_0) # passive <=> clean_result.
clean_result, out_b(X_0) # passive <=> clean_result.
clean_result <=> true.




