%%%[(1,[(green,1),(red,1)])]
%%% 'ASP_to_CHR'([v(1),v(2),v(3),green(4),edge(1,3),edge(3,4),(red(_40154):-v(_40154),not(green(_40154))),(green(_40154):-v(_40154),not(red(_40154))),(bot:-edge(_40154,_40176),red(_40154),red(_40176)),(bot:-edge(_40154,_40176),green(_40154),green(_40176))],'test_26',all_answer_sets,'no_data')
:- use_module(library(chr)).
:- chr_constraint success/0, failure/0, supported_1/2, supported_2/2, supported_3/1, exclusion_3/1, supported_4/1, exclusion_4/1, launcher/0, next_it/1, cfc/1, clean_result/0, red_1/1, red/1, out_red/1, edge/2, green_1/1, green/1, out_green/1, v/1.
success <=> true.
failure <=> fail.
red_1(X_0) # passive \ red_1(X_0) <=> true.
red(X_0) # passive \ red(X_0) <=> true.
green_1(X_0) # passive \ green_1(X_0) <=> true.
green(X_0) # passive \ green(X_0) <=> true.

red(X_0),out_red(X_0) <=> fail.
green(X_0),out_green(X_0) <=> fail.


%% bot:-edge(_40154,_40176),red(_40154),red(_40176)
apply_guarded_constraint_1 @ red(X_1),red_1(X_0),edge(X_0,X_1)==>
   true | 
   failure.

%% bot:-edge(_40154,_40176),green(_40154),green(_40176)
apply_guarded_constraint_2 @ green(X_1),green_1(X_0),edge(X_0,X_1)==>
   true | 
   failure.

%% green(_40154):-v(_40154),not(red(_40154))
supported_3 @ v(X_0)==>
   true | 
   supported_3(X_0).
unuseful_3 @ green(X_0) \ supported_3(X_0)<=>
   success.
propagate_3 @ out_red(X_0) \ supported_3(X_0)<=>
   green_1(X_0), green(X_0).
blocked_3 @ red(X_0) \ supported_3(X_0)<=>
   success.
exclusion_3 @ out_red(X_0),exclusion_3(X_0)<=>
   failure.
clean_exclusion_3 @ red(X_0) \ exclusion_3(X_0)<=>
   success.

%% red(_40154):-v(_40154),not(green(_40154))
supported_4 @ v(X_0)==>
   true | 
   supported_4(X_0).
unuseful_4 @ red(X_0) \ supported_4(X_0)<=>
   success.
propagate_4 @ out_green(X_0) \ supported_4(X_0)<=>
   red_1(X_0), red(X_0).
blocked_4 @ green(X_0) \ supported_4(X_0)<=>
   success.
exclusion_4 @ out_green(X_0),exclusion_4(X_0)<=>
   failure.
clean_exclusion_4 @ green(X_0) \ exclusion_4(X_0)<=>
   success.
choice_3 @ next_it(X_1),supported_3(X_0) # passive <=>
   X_2 is X_1*2, out_red(X_0),green_1(X_0), green(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_1),supported_4(X_0) # passive <=>
   X_2 is X_1*2, out_green(X_0),red_1(X_0), red(X_0),next_it(X_2) ; X_2 is X_1*2+1, exclusion_4(X_0),next_it(X_2).




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

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

launcher <=> v(1), v(2), v(3), edge(1,3), edge(3,4), green(4), 
   next_it(0).

clean_result, out_red(X_0) # passive <=> clean_result.
clean_result, out_green(X_0) # passive <=> clean_result.
clean_result <=> true.




