%%%[(1,[(a,1),(b,1)])]
%%% 'ASP_to_CHR'([p(1),p(2),p(3),(a(_39524):-p(_39524),not(b(_39524))),(b(_39524):-p(_39524),not(a(_39524)))],'test_37',all_answer_sets,'no_data')
:- use_module(library(chr)).
:- chr_constraint success/0, failure/0, supported_1/1, exclusion_1/1, supported_2/1, exclusion_2/1, launcher/0, next_it/1, cfc/1, clean_result/0, a/1, out_a/1, b/1, out_b/1, p/1.
success <=> true.
failure <=> fail.
a(X_0) # passive \ a(X_0) <=> true.
b(X_0) # passive \ b(X_0) <=> true.

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


%% b(_39524):-p(_39524),not(a(_39524))
supported_1 @ p(X_0)==>
   true | 
   supported_1(X_0).
unuseful_1 @ b(X_0) \ supported_1(X_0)<=>
   success.
propagate_1 @ out_a(X_0) \ supported_1(X_0)<=>
   b(X_0).
blocked_1 @ a(X_0) \ supported_1(X_0)<=>
   success.
exclusion_1 @ out_a(X_0),exclusion_1(X_0)<=>
   failure.
clean_exclusion_1 @ a(X_0) \ exclusion_1(X_0)<=>
   success.

%% a(_39524):-p(_39524),not(b(_39524))
supported_2 @ p(X_0)==>
   true | 
   supported_2(X_0).
unuseful_2 @ a(X_0) \ supported_2(X_0)<=>
   success.
propagate_2 @ out_b(X_0) \ supported_2(X_0)<=>
   a(X_0).
blocked_2 @ b(X_0) \ supported_2(X_0)<=>
   success.
exclusion_2 @ out_b(X_0),exclusion_2(X_0)<=>
   failure.
clean_exclusion_2 @ b(X_0) \ exclusion_2(X_0)<=>
   success.
choice_1 @ next_it(X_1),supported_1(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_1(X_0),next_it(X_2).
choice_2 @ next_it(X_1),supported_2(X_0) # passive <=>
   X_2 is X_1*2, out_b(X_0),a(X_0),next_it(X_2) ; X_2 is X_1*2+1, exclusion_2(X_0),next_it(X_2).




next_it(_Profondeur), exclusion_1(X1)# passive <=> fail.
next_it(_Profondeur), exclusion_2(X1)# passive <=> fail.

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

launcher <=> p(1), p(2), p(3), 
   next_it(0).

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




