%%% BEGINNING OF THE TRANSLATION %%%


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: jack_happy :- { ticket(b) # 1, ticket(f) # 1, ticket(s) # 1, ticket(i) # 1, ticket(n) # 1 | jack_pref }, is_summer, num_of_tickets(1).
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: jack_happy :- { ticket(b) # 1, ticket(f) # 1, ticket(s) # 1, ticket(i) # 1, ticket(n) # 1 | jack_pref }, is_summer, num_of_tickets(1).


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: jack_happy :- { ticket(b) # 1, ticket(f) # 1, ticket(s) # 1, ticket(i) # 1, ticket(n) # 1 | jack_pref }, is_summer, num_of_tickets(1).


%% P-Sets in the R-Rule's body:
%% { ticket(b) # 1, ticket(f) # 1, ticket(s) # 1, ticket(i) # 1, ticket(n) # 1 | jack_pref }
%% P-Set : { ticket(b) # 1, ticket(f) # 1, ticket(s) # 1, ticket(i) # 1, ticket(n) # 1 | jack_pref }
rasp_dom(rasp_pset_1_1, ticket(b)).
rasp_dom(rasp_pset_1_1, ticket(f)).
rasp_dom(rasp_pset_1_1, ticket(s)).
rasp_dom(rasp_pset_1_1, ticket(i)).
rasp_dom(rasp_pset_1_1, ticket(n)).
rasp_num(rasp_pset_1_1, 1).
rasp_num(rasp_pset_1_1, 2).
rasp_num(rasp_pset_1_1, 3).
rasp_num(rasp_pset_1_1, 4).
rasp_num(rasp_pset_1_1, 5).
rasp_pset_name(rasp_pset_1_1) :- rasp_fired(rasp_1).
rasp_cl(rasp_pset_1_1, X, Y) :- jack_pref(X, Y), X != Y, rasp_fired(rasp_1).
rasp_ordered(rasp_pset_1_1, ticket(b)) :- rasp_order(rasp_pset_1_1, ticket(b), N), rasp_num(rasp_pset_1_1, N).
rasp_ordered(rasp_pset_1_1, ticket(f)) :- rasp_order(rasp_pset_1_1, ticket(f), N), rasp_num(rasp_pset_1_1, N).
rasp_ordered(rasp_pset_1_1, ticket(s)) :- rasp_order(rasp_pset_1_1, ticket(s), N), rasp_num(rasp_pset_1_1, N).
rasp_ordered(rasp_pset_1_1, ticket(i)) :- rasp_order(rasp_pset_1_1, ticket(i), N), rasp_num(rasp_pset_1_1, N).
rasp_ordered(rasp_pset_1_1, ticket(n)) :- rasp_order(rasp_pset_1_1, ticket(n), N), rasp_num(rasp_pset_1_1, N).
:- not rasp_ordered(rasp_pset_1_1, ticket(b)), rasp_use_pl(rasp_1, ticket(b), I, 1, rasp_pset_1_1), rasp_iter(I).
:- not rasp_ordered(rasp_pset_1_1, ticket(f)), rasp_use_pl(rasp_1, ticket(f), I, 1, rasp_pset_1_1), rasp_iter(I).
:- not rasp_ordered(rasp_pset_1_1, ticket(s)), rasp_use_pl(rasp_1, ticket(s), I, 1, rasp_pset_1_1), rasp_iter(I).
:- not rasp_ordered(rasp_pset_1_1, ticket(i)), rasp_use_pl(rasp_1, ticket(i), I, 1, rasp_pset_1_1), rasp_iter(I).
:- not rasp_ordered(rasp_pset_1_1, ticket(n)), rasp_use_pl(rasp_1, ticket(n), I, 1, rasp_pset_1_1), rasp_iter(I).
rasp_auxres(rasp_1, rasp_pset_1_1).
1 { rasp_use_pl(rasp_1, ticket(b), I, 1, rasp_pset_1_1), rasp_use_pl(rasp_1, ticket(f), I, 1, rasp_pset_1_1), rasp_use_pl(rasp_1, ticket(s), I, 1, rasp_pset_1_1), rasp_use_pl(rasp_1, ticket(i), I, 1, rasp_pset_1_1), rasp_use_pl(rasp_1, ticket(n), I, 1, rasp_pset_1_1) } 1 :-
	rasp_use(rasp_1, 0, rasp_pset_1_1, -(NumFirings)),
	rasp_iter(I), I <= NumFirings, rasp_counter(rasp_1, NumFirings).
rasp_res_pl(rasp_1, rasp_pset_1_1, T, N) :- rasp_order(rasp_pset_1_1, T, N), rasp_fired(rasp_1).
%% R-Rule cleaned from P-Sets:
%%		[1-1]: jack_happy :- rasp_pset_1_1 # 1, is_summer, num_of_tickets(1).


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: jack_happy :- rasp_pset_1_1 # 1, is_summer, num_of_tickets(1).
%% R-Rule cleaned from P-Lists:
%%		[1-1]: jack_happy :- rasp_pset_1_1 # 1, is_summer, num_of_tickets(1).


%%%%%% Translation of the rule rasp_1:
%%		[1-1]: jack_happy :- rasp_pset_1_1 # 1, is_summer, num_of_tickets(1).
rasp_rrule(rasp_1).
rasp_firings(rasp_1, 1..1).
:- not is_summer, rasp_fired(rasp_1).
:- not num_of_tickets(1), rasp_fired(rasp_1).
%% rule (6)(6'):
rasp_a_atom(rasp_1, 0, rasp_pset_1_1, -(1)).
%% rule (3):
jack_happy :-
	is_summer, num_of_tickets(1),
	rasp_fired(rasp_1).
%% Policy
rasp_optional(rasp_1).


%%%%%% Amount-Atoms corresponding to P-Sets in the current R-Rule:


%% rasp_pset_1_1 # 1.


%%%%%% Translation of the rule (fact) rasp_2:
%%		rasp_pset_1_1 # 1.
rasp_rrule(rasp_2).
%% fact (6)(6'):
rasp_a_atom(rasp_2, 0, rasp_pset_1_1, 1).
%% fact (5)(5'):
rasp_fired(rasp_2).
rasp_firings(rasp_2, 1).


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: jack_happy :- { ticket(b) # 2, ticket(f) # 2, ticket(s) # 2, ticket(i) # 2, ticket(n) # 2 | jack_pref }, is_summer, num_of_tickets(2).
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: jack_happy :- { ticket(b) # 2, ticket(f) # 2, ticket(s) # 2, ticket(i) # 2, ticket(n) # 2 | jack_pref }, is_summer, num_of_tickets(2).


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: jack_happy :- { ticket(b) # 2, ticket(f) # 2, ticket(s) # 2, ticket(i) # 2, ticket(n) # 2 | jack_pref }, is_summer, num_of_tickets(2).


%% P-Sets in the R-Rule's body:
%% { ticket(b) # 2, ticket(f) # 2, ticket(s) # 2, ticket(i) # 2, ticket(n) # 2 | jack_pref }
%% P-Set : { ticket(b) # 2, ticket(f) # 2, ticket(s) # 2, ticket(i) # 2, ticket(n) # 2 | jack_pref }
rasp_dom(rasp_pset_3_1, ticket(b)).
rasp_dom(rasp_pset_3_1, ticket(f)).
rasp_dom(rasp_pset_3_1, ticket(s)).
rasp_dom(rasp_pset_3_1, ticket(i)).
rasp_dom(rasp_pset_3_1, ticket(n)).
rasp_num(rasp_pset_3_1, 1).
rasp_num(rasp_pset_3_1, 2).
rasp_num(rasp_pset_3_1, 3).
rasp_num(rasp_pset_3_1, 4).
rasp_num(rasp_pset_3_1, 5).
rasp_pset_name(rasp_pset_3_1) :- rasp_fired(rasp_3).
rasp_cl(rasp_pset_3_1, X, Y) :- jack_pref(X, Y), X != Y, rasp_fired(rasp_3).
rasp_ordered(rasp_pset_3_1, ticket(b)) :- rasp_order(rasp_pset_3_1, ticket(b), N), rasp_num(rasp_pset_3_1, N).
rasp_ordered(rasp_pset_3_1, ticket(f)) :- rasp_order(rasp_pset_3_1, ticket(f), N), rasp_num(rasp_pset_3_1, N).
rasp_ordered(rasp_pset_3_1, ticket(s)) :- rasp_order(rasp_pset_3_1, ticket(s), N), rasp_num(rasp_pset_3_1, N).
rasp_ordered(rasp_pset_3_1, ticket(i)) :- rasp_order(rasp_pset_3_1, ticket(i), N), rasp_num(rasp_pset_3_1, N).
rasp_ordered(rasp_pset_3_1, ticket(n)) :- rasp_order(rasp_pset_3_1, ticket(n), N), rasp_num(rasp_pset_3_1, N).
:- not rasp_ordered(rasp_pset_3_1, ticket(b)), rasp_use_pl(rasp_3, ticket(b), I, 2, rasp_pset_3_1), rasp_iter(I).
:- not rasp_ordered(rasp_pset_3_1, ticket(f)), rasp_use_pl(rasp_3, ticket(f), I, 2, rasp_pset_3_1), rasp_iter(I).
:- not rasp_ordered(rasp_pset_3_1, ticket(s)), rasp_use_pl(rasp_3, ticket(s), I, 2, rasp_pset_3_1), rasp_iter(I).
:- not rasp_ordered(rasp_pset_3_1, ticket(i)), rasp_use_pl(rasp_3, ticket(i), I, 2, rasp_pset_3_1), rasp_iter(I).
:- not rasp_ordered(rasp_pset_3_1, ticket(n)), rasp_use_pl(rasp_3, ticket(n), I, 2, rasp_pset_3_1), rasp_iter(I).
rasp_auxres(rasp_3, rasp_pset_3_1).
1 { rasp_use_pl(rasp_3, ticket(b), I, 2, rasp_pset_3_1), rasp_use_pl(rasp_3, ticket(f), I, 2, rasp_pset_3_1), rasp_use_pl(rasp_3, ticket(s), I, 2, rasp_pset_3_1), rasp_use_pl(rasp_3, ticket(i), I, 2, rasp_pset_3_1), rasp_use_pl(rasp_3, ticket(n), I, 2, rasp_pset_3_1) } 1 :-
	rasp_use(rasp_3, 0, rasp_pset_3_1, -(NumFirings)),
	rasp_iter(I), I <= NumFirings, rasp_counter(rasp_3, NumFirings).
rasp_res_pl(rasp_3, rasp_pset_3_1, T, N) :- rasp_order(rasp_pset_3_1, T, N), rasp_fired(rasp_3).
%% R-Rule cleaned from P-Sets:
%%		[1-1]: jack_happy :- rasp_pset_3_1 # 1, is_summer, num_of_tickets(2).


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: jack_happy :- rasp_pset_3_1 # 1, is_summer, num_of_tickets(2).
%% R-Rule cleaned from P-Lists:
%%		[1-1]: jack_happy :- rasp_pset_3_1 # 1, is_summer, num_of_tickets(2).


%%%%%% Translation of the rule rasp_3:
%%		[1-1]: jack_happy :- rasp_pset_3_1 # 1, is_summer, num_of_tickets(2).
rasp_rrule(rasp_3).
rasp_firings(rasp_3, 1..1).
:- not is_summer, rasp_fired(rasp_3).
:- not num_of_tickets(2), rasp_fired(rasp_3).
%% rule (6)(6'):
rasp_a_atom(rasp_3, 0, rasp_pset_3_1, -(1)).
%% rule (3):
jack_happy :-
	is_summer, num_of_tickets(2),
	rasp_fired(rasp_3).
%% Policy
rasp_optional(rasp_3).


%%%%%% Amount-Atoms corresponding to P-Sets in the current R-Rule:


%% rasp_pset_3_1 # 1.


%%%%%% Translation of the rule (fact) rasp_4:
%%		rasp_pset_3_1 # 1.
rasp_rrule(rasp_4).
%% fact (6)(6'):
rasp_a_atom(rasp_4, 0, rasp_pset_3_1, 1).
%% fact (5)(5'):
rasp_fired(rasp_4).
rasp_firings(rasp_4, 1).


%%%%%% Proper GrinGo statement rewritten
jack_pref(ticket(b), ticket(f)).


%%%%%% Proper GrinGo statement rewritten
jack_pref(ticket(f), ticket(i)).


%%%%%% Proper GrinGo statement rewritten
jack_pref(ticket(f), ticket(s)).


%%%%%% Proper GrinGo statement rewritten
jack_pref(ticket(s), ticket(f)).


%%%%%% Proper GrinGo statement rewritten
jack_pref(ticket(f), ticket(n)).


%%%%%% Proper GrinGo statement rewritten
jack_pref(ticket(n), ticket(i)) :- is_august.


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: ticket(b) # 1 :- money # 9, cost(b, 9), 9 == 9 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: ticket(b) # 1 :- money # 9, cost(b, 9), 9 == 9 * 1, num_of_tickets(1), aux # 1.


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: ticket(b) # 1 :- money # 9, cost(b, 9), 9 == 9 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from P-Sets:
%%		[1-1]: ticket(b) # 1 :- money # 9, cost(b, 9), 9 == 9 * 1, num_of_tickets(1), aux # 1.


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: ticket(b) # 1 :- money # 9, cost(b, 9), 9 == 9 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from P-Lists:
%%		[1-1]: ticket(b) # 1 :- money # 9, cost(b, 9), 9 == 9 * 1, num_of_tickets(1), aux # 1.


%%%%%% Translation of the rule rasp_5:
%%		[1-1]: ticket(b) # 1 :- money # 9, cost(b, 9), 9 == 9 * 1, num_of_tickets(1), aux # 1.
rasp_rrule(rasp_5).
rasp_firings(rasp_5, 1..1).
:- not cost(b, 9), rasp_fired(rasp_5).
:- not num_of_tickets(1), rasp_fired(rasp_5).
%% rule (6)(6'):
rasp_a_atom(rasp_5, 0, ticket(b), 1).
%% rule (6)(6'):
rasp_a_atom(rasp_5, 1, money, -(9)).
%% rule (6)(6'):
rasp_a_atom(rasp_5, 2, aux, -(1)).
%% Policy
rasp_optional(rasp_5).


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: ticket(f) # 1 :- money # 6, cost(f, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: ticket(f) # 1 :- money # 6, cost(f, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: ticket(f) # 1 :- money # 6, cost(f, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from P-Sets:
%%		[1-1]: ticket(f) # 1 :- money # 6, cost(f, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: ticket(f) # 1 :- money # 6, cost(f, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from P-Lists:
%%		[1-1]: ticket(f) # 1 :- money # 6, cost(f, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.


%%%%%% Translation of the rule rasp_6:
%%		[1-1]: ticket(f) # 1 :- money # 6, cost(f, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.
rasp_rrule(rasp_6).
rasp_firings(rasp_6, 1..1).
:- not cost(f, 6), rasp_fired(rasp_6).
:- not num_of_tickets(1), rasp_fired(rasp_6).
%% rule (6)(6'):
rasp_a_atom(rasp_6, 0, ticket(f), 1).
%% rule (6)(6'):
rasp_a_atom(rasp_6, 1, money, -(6)).
%% rule (6)(6'):
rasp_a_atom(rasp_6, 2, aux, -(1)).
%% Policy
rasp_optional(rasp_6).


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: ticket(s) # 1 :- money # 5, cost(s, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: ticket(s) # 1 :- money # 5, cost(s, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: ticket(s) # 1 :- money # 5, cost(s, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from P-Sets:
%%		[1-1]: ticket(s) # 1 :- money # 5, cost(s, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: ticket(s) # 1 :- money # 5, cost(s, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from P-Lists:
%%		[1-1]: ticket(s) # 1 :- money # 5, cost(s, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.


%%%%%% Translation of the rule rasp_7:
%%		[1-1]: ticket(s) # 1 :- money # 5, cost(s, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.
rasp_rrule(rasp_7).
rasp_firings(rasp_7, 1..1).
:- not cost(s, 5), rasp_fired(rasp_7).
:- not num_of_tickets(1), rasp_fired(rasp_7).
%% rule (6)(6'):
rasp_a_atom(rasp_7, 0, ticket(s), 1).
%% rule (6)(6'):
rasp_a_atom(rasp_7, 1, money, -(5)).
%% rule (6)(6'):
rasp_a_atom(rasp_7, 2, aux, -(1)).
%% Policy
rasp_optional(rasp_7).


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: ticket(i) # 1 :- money # 5, cost(i, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: ticket(i) # 1 :- money # 5, cost(i, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: ticket(i) # 1 :- money # 5, cost(i, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from P-Sets:
%%		[1-1]: ticket(i) # 1 :- money # 5, cost(i, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: ticket(i) # 1 :- money # 5, cost(i, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from P-Lists:
%%		[1-1]: ticket(i) # 1 :- money # 5, cost(i, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.


%%%%%% Translation of the rule rasp_8:
%%		[1-1]: ticket(i) # 1 :- money # 5, cost(i, 5), 5 == 5 * 1, num_of_tickets(1), aux # 1.
rasp_rrule(rasp_8).
rasp_firings(rasp_8, 1..1).
:- not cost(i, 5), rasp_fired(rasp_8).
:- not num_of_tickets(1), rasp_fired(rasp_8).
%% rule (6)(6'):
rasp_a_atom(rasp_8, 0, ticket(i), 1).
%% rule (6)(6'):
rasp_a_atom(rasp_8, 1, money, -(5)).
%% rule (6)(6'):
rasp_a_atom(rasp_8, 2, aux, -(1)).
%% Policy
rasp_optional(rasp_8).


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: ticket(n) # 1 :- money # 6, cost(n, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: ticket(n) # 1 :- money # 6, cost(n, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: ticket(n) # 1 :- money # 6, cost(n, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from P-Sets:
%%		[1-1]: ticket(n) # 1 :- money # 6, cost(n, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: ticket(n) # 1 :- money # 6, cost(n, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.
%% R-Rule cleaned from P-Lists:
%%		[1-1]: ticket(n) # 1 :- money # 6, cost(n, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.


%%%%%% Translation of the rule rasp_9:
%%		[1-1]: ticket(n) # 1 :- money # 6, cost(n, 6), 6 == 6 * 1, num_of_tickets(1), aux # 1.
rasp_rrule(rasp_9).
rasp_firings(rasp_9, 1..1).
:- not cost(n, 6), rasp_fired(rasp_9).
:- not num_of_tickets(1), rasp_fired(rasp_9).
%% rule (6)(6'):
rasp_a_atom(rasp_9, 0, ticket(n), 1).
%% rule (6)(6'):
rasp_a_atom(rasp_9, 1, money, -(6)).
%% rule (6)(6'):
rasp_a_atom(rasp_9, 2, aux, -(1)).
%% Policy
rasp_optional(rasp_9).


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: ticket(b) # 2 :- money # 18, cost(b, 9), 18 == 9 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: ticket(b) # 2 :- money # 18, cost(b, 9), 18 == 9 * 2, num_of_tickets(2), aux # 1.


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: ticket(b) # 2 :- money # 18, cost(b, 9), 18 == 9 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from P-Sets:
%%		[1-1]: ticket(b) # 2 :- money # 18, cost(b, 9), 18 == 9 * 2, num_of_tickets(2), aux # 1.


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: ticket(b) # 2 :- money # 18, cost(b, 9), 18 == 9 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from P-Lists:
%%		[1-1]: ticket(b) # 2 :- money # 18, cost(b, 9), 18 == 9 * 2, num_of_tickets(2), aux # 1.


%%%%%% Translation of the rule rasp_10:
%%		[1-1]: ticket(b) # 2 :- money # 18, cost(b, 9), 18 == 9 * 2, num_of_tickets(2), aux # 1.
rasp_rrule(rasp_10).
rasp_firings(rasp_10, 1..1).
:- not cost(b, 9), rasp_fired(rasp_10).
:- not num_of_tickets(2), rasp_fired(rasp_10).
%% rule (6)(6'):
rasp_a_atom(rasp_10, 0, ticket(b), 2).
%% rule (6)(6'):
rasp_a_atom(rasp_10, 1, money, -(18)).
%% rule (6)(6'):
rasp_a_atom(rasp_10, 2, aux, -(1)).
%% Policy
rasp_optional(rasp_10).


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: ticket(f) # 2 :- money # 12, cost(f, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: ticket(f) # 2 :- money # 12, cost(f, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: ticket(f) # 2 :- money # 12, cost(f, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from P-Sets:
%%		[1-1]: ticket(f) # 2 :- money # 12, cost(f, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: ticket(f) # 2 :- money # 12, cost(f, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from P-Lists:
%%		[1-1]: ticket(f) # 2 :- money # 12, cost(f, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.


%%%%%% Translation of the rule rasp_11:
%%		[1-1]: ticket(f) # 2 :- money # 12, cost(f, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.
rasp_rrule(rasp_11).
rasp_firings(rasp_11, 1..1).
:- not cost(f, 6), rasp_fired(rasp_11).
:- not num_of_tickets(2), rasp_fired(rasp_11).
%% rule (6)(6'):
rasp_a_atom(rasp_11, 0, ticket(f), 2).
%% rule (6)(6'):
rasp_a_atom(rasp_11, 1, money, -(12)).
%% rule (6)(6'):
rasp_a_atom(rasp_11, 2, aux, -(1)).
%% Policy
rasp_optional(rasp_11).


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: ticket(s) # 2 :- money # 10, cost(s, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: ticket(s) # 2 :- money # 10, cost(s, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: ticket(s) # 2 :- money # 10, cost(s, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from P-Sets:
%%		[1-1]: ticket(s) # 2 :- money # 10, cost(s, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: ticket(s) # 2 :- money # 10, cost(s, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from P-Lists:
%%		[1-1]: ticket(s) # 2 :- money # 10, cost(s, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.


%%%%%% Translation of the rule rasp_12:
%%		[1-1]: ticket(s) # 2 :- money # 10, cost(s, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.
rasp_rrule(rasp_12).
rasp_firings(rasp_12, 1..1).
:- not cost(s, 5), rasp_fired(rasp_12).
:- not num_of_tickets(2), rasp_fired(rasp_12).
%% rule (6)(6'):
rasp_a_atom(rasp_12, 0, ticket(s), 2).
%% rule (6)(6'):
rasp_a_atom(rasp_12, 1, money, -(10)).
%% rule (6)(6'):
rasp_a_atom(rasp_12, 2, aux, -(1)).
%% Policy
rasp_optional(rasp_12).


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: ticket(i) # 2 :- money # 10, cost(i, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: ticket(i) # 2 :- money # 10, cost(i, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: ticket(i) # 2 :- money # 10, cost(i, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from P-Sets:
%%		[1-1]: ticket(i) # 2 :- money # 10, cost(i, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: ticket(i) # 2 :- money # 10, cost(i, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from P-Lists:
%%		[1-1]: ticket(i) # 2 :- money # 10, cost(i, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.


%%%%%% Translation of the rule rasp_13:
%%		[1-1]: ticket(i) # 2 :- money # 10, cost(i, 5), 10 == 5 * 2, num_of_tickets(2), aux # 1.
rasp_rrule(rasp_13).
rasp_firings(rasp_13, 1..1).
:- not cost(i, 5), rasp_fired(rasp_13).
:- not num_of_tickets(2), rasp_fired(rasp_13).
%% rule (6)(6'):
rasp_a_atom(rasp_13, 0, ticket(i), 2).
%% rule (6)(6'):
rasp_a_atom(rasp_13, 1, money, -(10)).
%% rule (6)(6'):
rasp_a_atom(rasp_13, 2, aux, -(1)).
%% Policy
rasp_optional(rasp_13).


%%%%%% Cleaning R-Rule from CP-Lists
%% Original R-Rule:
%%		[1-1]: ticket(n) # 2 :- money # 12, cost(n, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from CP-Lists:
%%		[1-1]: ticket(n) # 2 :- money # 12, cost(n, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.


%%%%%% Cleaning R-Rule from P-Sets
%% Original R-Rule:
%%		[1-1]: ticket(n) # 2 :- money # 12, cost(n, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from P-Sets:
%%		[1-1]: ticket(n) # 2 :- money # 12, cost(n, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.


%%%%%% Cleaning R-Rule from P-Lists
%% Original R-Rule:
%%		[1-1]: ticket(n) # 2 :- money # 12, cost(n, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.
%% R-Rule cleaned from P-Lists:
%%		[1-1]: ticket(n) # 2 :- money # 12, cost(n, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.


%%%%%% Translation of the rule rasp_14:
%%		[1-1]: ticket(n) # 2 :- money # 12, cost(n, 6), 12 == 6 * 2, num_of_tickets(2), aux # 1.
rasp_rrule(rasp_14).
rasp_firings(rasp_14, 1..1).
:- not cost(n, 6), rasp_fired(rasp_14).
:- not num_of_tickets(2), rasp_fired(rasp_14).
%% rule (6)(6'):
rasp_a_atom(rasp_14, 0, ticket(n), 2).
%% rule (6)(6'):
rasp_a_atom(rasp_14, 1, money, -(12)).
%% rule (6)(6'):
rasp_a_atom(rasp_14, 2, aux, -(1)).
%% Policy
rasp_optional(rasp_14).


%%%%%% Proper GrinGo statement rewritten
cost(b, 9).


%%%%%% Proper GrinGo statement rewritten
cost(f, 6).


%%%%%% Proper GrinGo statement rewritten
cost(s, 5).


%%%%%% Proper GrinGo statement rewritten
cost(i, 5).


%%%%%% Proper GrinGo statement rewritten
cost(n, 6).


%%%%%% Translation of the rule (fact) rasp_15:
%%		aux # 1.
rasp_rrule(rasp_15).
%% fact (6)(6'):
rasp_a_atom(rasp_15, 0, aux, 1).
%% fact (5)(5'):
rasp_fired(rasp_15).
rasp_firings(rasp_15, 1).


%%%%%% Proper GrinGo statement rewritten
num_of_tickets(1) :- jill_works.


%%%%%% Proper GrinGo statement rewritten
num_of_tickets(2) :- not jill_works.


%%%%%% Translation of the rule (fact) rasp_16:
%%		money # 20.
rasp_rrule(rasp_16).
%% fact (6)(6'):
rasp_a_atom(rasp_16, 0, money, 20).
%% fact (5)(5'):
rasp_fired(rasp_16).
rasp_firings(rasp_16, 1).


%%%%%% Proper GrinGo statement rewritten
is_summer.


%%%%%% Domain predicates for P-Lists:
rasp_num(0..1).
rasp_iter(1..1).


%%%%%% Engine for P-Lists:
rasp_resource(Pl) :- rasp_auxres(G, Pl), rasp_rrule(G).
rasp_use(G, Idx, R, TEMP) :- TEMP = U * N, rasp_sum_use_pl(G, R, N, Pl), rasp_res_pl(G, Pl, R, Grade), rasp_rrule(G), rasp_allval(N), rasp_a_atom(G, Idx, Pl, U), N != 0.

rasp_sum_use_pl(G, R, N, Pl) :- N = #sum [ rasp_use_pl(G, R, Iter, Q, Pl) : rasp_firings(G, Iter) : rasp_iter(Iter) : rasp_allval(Q) = Q ], rasp_res_pl(G, Pl, R, Grade), rasp_rrule(G), rasp_allval(N), rasp_auxres(G, Pl).
1 { rasp_sum_use_pl(G, R, N, Pl) : rasp_allval(N) } 1 :- rasp_res_pl(G, Pl, R, Grade), rasp_rrule(G).



%%%%%% Engine for P-Sets:
rasp_cl(PS, X, Y) :- rasp_dom(PS, X), rasp_dom(PS, Y), rasp_dom(PS, Z), rasp_cl(PS, X, Z), rasp_cl(PS, Z, Y), X != Y, rasp_pset_name(PS).
rasp_eq(PS, T1, T2) :- rasp_cl(PS, T1, T2), rasp_cl(PS, T2, T1), rasp_dom(PS, T1), rasp_dom(PS, T2), rasp_pset_name(PS).
1 { rasp_idx(PS, T, N) : rasp_num(PS, N) } 1 :- rasp_dom(PS, T), rasp_pset_name(PS).
rasp_used_idx(PS, N) :- rasp_dom(PS, T), rasp_idx(PS, T, N), rasp_num(PS, N), rasp_pset_name(PS).
:- rasp_dom(PS, T), rasp_idx(PS, T, N), rasp_num(PS, N), N > 1, N1 = N - 1, not rasp_used_idx(PS, N1), rasp_pset_name(PS).
:- rasp_dom(PS, T1), rasp_dom(PS, T2), rasp_idx(PS, T1, N1), rasp_idx(PS, T2, N2), rasp_num(PS, N1), rasp_num(PS, N2), rasp_cl(PS, T1, T2), not rasp_cl(PS, T2, T1), N2 <= N1, T1 != T2, rasp_pset_name(PS).
:- not rasp_eq(PS, T1, T2), rasp_dom(PS, T1), rasp_dom(PS, T2), rasp_idx(PS, T1, N), rasp_idx(PS, T2, N), rasp_num(PS, N), T1 != T2, rasp_pset_name(PS).
rasp_idx(PS, T2, N) :- rasp_eq(PS, T1, T2), rasp_dom(PS, T1), rasp_dom(PS, T2), rasp_idx(PS, T1, N), rasp_num(PS, N), rasp_pset_name(PS).
rasp_order(PS, T, N) :- rasp_idx(PS, T, N), not rasp_other(PS, T, N), rasp_dom(PS, T), rasp_num(PS, N), rasp_pset_name(PS).
rasp_other(PS, T, N) :- rasp_order(PS, T2, N), T != T2, rasp_dom(PS, T), rasp_dom(PS, T2), rasp_num(PS, N), rasp_pset_name(PS).
rasp_grade(N) :- rasp_other(PS, T, N), rasp_dom(PS, T), rasp_num(PS, N), rasp_pset_name(PS).


%%%%%% Domain predicates:
rasp_val(0..30).
rasp_allval(-30..30).
rasp_idx(0..2).


%%%%%% Resources:
rasp_resource(aux).
rasp_resource(money).
rasp_resource(rasp_pset_1_1).
rasp_resource(rasp_pset_3_1).
rasp_resource(ticket(b)).
rasp_resource(ticket(f)).
rasp_resource(ticket(i)).
rasp_resource(ticket(n)).
rasp_resource(ticket(s)).


%%%%%% Main engine (PAPER):
rasp_res_rrule(Res, Rule) :- rasp_a_atom(Rule, I, Res, Q).
rasp_fired(Rule) :- not rasp_notfired(Rule), rasp_rrule(Rule).
rasp_notfired(Rule) :- not rasp_fired(Rule), rasp_rrule(Rule).
rasp_use(Rule, I, Res, TEMP) :- TEMP = C * Q, rasp_fired(Rule), rasp_counter(Rule, C), rasp_firings(Rule, C), rasp_resource(Res), rasp_a_atom(Rule, I, Res, Q).
rasp_fired(Rule) :- rasp_use(Rule, I, Res, TEMP), TEMP = C * Q, rasp_counter(Rule, C), rasp_firings(Rule, C), rasp_resource(Res), rasp_a_atom(Rule, I, Res, Q).
rasp_notfired(Rule) :- not rasp_use(Rule, I, Res, TEMP), TEMP = C * Q, rasp_counter(Rule, C), rasp_firings(Rule, C), rasp_resource(Res), rasp_a_atom(Rule, I, Res, Q).

rasp_notcounter(G, C) :- rasp_counter(G, D), rasp_firings(G, C), C != D, rasp_rrule(G), rasp_firings(G, D).
rasp_counter(G, C) :- rasp_firings(G, C), rasp_fired(G), not rasp_notcounter(G, C).
:- not rasp_fired(G), rasp_counter(G, C), rasp_rrule(G), rasp_firings(G, C).

rasp_balance(Res, N) :- N = #sum [ rasp_use(Rule, Idx, Res, Q) : rasp_rrule(Rule) : rasp_idx(Idx) : rasp_allval(Q) = Q ], rasp_resource(Res).
:- rasp_balance(Res, N), N < 0, rasp_resource(Res), rasp_allval(N).




%%%%%% Mr.Hyde:
#hide rasp_auxatom.
#hide rasp_cons(X,Y,Z,W).
#hide rasp_consumes(X,Y,Z).
#hide rasp_enabled(X).
#hide rasp_enbld(X,Y).
#hide rasp_firings(X,Y).
#hide rasp_idx(X).
#hide rasp_num(X).
#hide rasp_prod(X,Y,Z,W).
#hide rasp_produces(X,Y,Z).
#hide rasp_resource(X).
#hide rasp_RID.
#hide rasp_rrule(X).
#hide rasp_use_n(X,Y,Z,W).
#hide rasp_use_p(X,Y,Z,W).
#hide rasp_val(X).
#hide rasp_optional(X).
#hide rasp_thrifty(X).
#hide rasp_prodigal(X).
#hide rasp_use(X,Y,Z,W).
#hide rasp_extraneeded(X,Y,Z).
#hide rasp_notcounter(X,Y).
#hide rasp_allval(X).
#hide rasp_res_rrule(X,Y).
#hide rasp_auxres(X,Y).
#hide rasp_use_pl(X,Y,Z,W).
#hide rasp_res_pl(X,Y,Z,W).
#hide rasp_sum_use_pl(X,Y,Z,W).
#hide rasp_num_n_choice(X,Y).
#hide rasp_grade(X).
#hide rasp_iter(X).
#hide rasp_cl(X,Y,Z).
#hide rasp_eq(X,Y,Z).
#hide rasp_idx(X,Y,Z).
#hide rasp_num(X,Y).
#hide rasp_dom(X,Y).
#hide rasp_used_idx(X,Y).
#hide rasp_pset_name(X).
#hide rasp_order(X,Y,Z).
#hide rasp_other(X,Y,Z).
#hide rasp_ordered(X,Y,Z,W,U,V).
#hide rasp_auxpred(X,Y).


%%% END OF THE TRANSLATION %%%

