Commit 33b0c8d4 authored by HEMERY Mathieu's avatar HEMERY Mathieu
Browse files

Rewrite print_normal (now build_normal) and its subfunctions

parent e602b2a4
......@@ -531,9 +531,8 @@ print_event(Reactions_data, Stoch_list, Hybrid_reactants_list, Constraints_list,
build_alphas(Number_of_alpha, Alpha_accumulation_list),
% 3. Print reactions in event
constant_list(Number_of_species,[],Init_list2),
% Build the print_helper_list.
print_normal(Reactions_data, Init_list2, Print_helper_list, Alpha_accumulation_list, Constraints_list, Stoch_list, 1),
build_normal(Reactions_data, Print_helper_list, Alpha_accumulation_list, Constraints_list, Stoch_list, 1),
% Use print_helper_list to really print out the event part.
print_change_list(Number_of_species,Print_helper_list, Stoch_list, 1, Number_of_species, Stream).
......@@ -650,110 +649,48 @@ alpha_accumulation([], _Acc, []).
%== Get Data from Reactions ==%
%=============================%
%! print_normal(Reactions_data, In_list, Out_list, Alpha_accumulation_list, Constraints_list, Stoch_species_order)
%! build_normal(Reactions_data, Out_list, Alpha_accumulation_list, Constraints_list, Stoch_list)
%
% Construct the evenment of stochastic reactions
print_normal([[Sp_change|_]|DataTail], In_list, Out_list, [Alp1|AlpTail], [Cons|ConsTail], Sp_list, 1) :-
check_change1(Alp1, Cons, Sp_list, 1, Sp_change, In_list, Tempo_list),
print_normal(DataTail, Tempo_list, Out_list, [Alp1|AlpTail], ConsTail, Sp_list, 2).
build_normal([[Sp_change|_]|DataTail], Out_list, [Alp1|AlpTail], [Cons|ConsTail], Sp_list, 1) :-
build_change(0, Alp1, Cons, Sp_list, Sp_change, Modif_list),
build_normal(DataTail, Tempo_list, [Alp1|AlpTail], ConsTail, Sp_list, 2),
append_elem_list(Modif_list, Tempo_list, Out_list).
print_normal([[Sp_change|_]|DataTail], In_list, Out_list, [A1,A2|ATail], [Cons|CTail], Sp_list, 2) :-
check_change(A1, A2, Cons, Sp_list, 1, Sp_change, In_list, Tempo_list),
print_normal(DataTail, Tempo_list, Out_list, [A2|ATail], CTail, Sp_list, 2).
build_normal([[Sp_change|_]|DataTail], Out_list, [A1,A2|ATail], [Cons|CTail], Sp_list, 2) :-
build_change(A1, A2, Cons, Sp_list, Sp_change, Modif_list),
build_normal(DataTail, Tempo_list, [A2|ATail], CTail, Sp_list, 2),
append_elem_list(Modif_list, Tempo_list, Out_list).
print_normal([], Out_list, Out_list, _A, _C_list, _Sp_list, _N).
build_normal([], Out_list, _A, _C_list, Sp_list, _N) :-
length(Sp_list, N_species),
constant_list(N_species, [], Out_list).
%! build_change(Alpha1, Alpha2, Constraint, Species_list, Change_list, Modif_list)
build_change(_A1, _A2, _Constraint, [], [], []).
build_change(A1, A2, Constraint, [_Species|Sp_tail], ['+0'|Ch_tail], [[]|Out_tail]) :-
!,
build_change(A1, A2, Constraint, Sp_tail, Ch_tail, Out_tail).
check_change1(First_alpha, Constraint, Stoch_species_order, Species_counter, First_species_change, Orig_list, Later_list) :-
nth1(Species_counter, First_species_change, Species_change),
(
Species_change == '+0'
->
(
length(Stoch_species_order, Last_count),
Species_counter < Last_count
->
Next_species_counter is (Species_counter + 1),
check_change1(First_alpha, Constraint, Stoch_species_order,Next_species_counter, First_species_change, Orig_list, Later_list)
;
Later_list = Orig_list
)
;
nth1(Species_counter, Stoch_species_order, Species),
nth1(Species_counter, First_species_change, Species_change),
atom_concat(Species, Species_change, Change),
nth1(Species_counter, Orig_list, _Append_position),
% !!! Putting things into the helper list !!!
add_n_copy_list(Orig_list, 1, Species_counter, [[0, First_alpha], Change, Constraint], [], Next_list),
%%% print('Next list = '), print(Next_list), print('\n'),
(
length(Stoch_species_order, Last_count),
Species_counter < Last_count
->
Next_counter is (Species_counter + 1),
check_change1(First_alpha, Constraint, Stoch_species_order, Next_counter,First_species_change, Next_list, Later_list)
build_change(A1, A2, Constraint, [Species|Sp_tail], [Change|Ch_tail], [Head|Out_tail]) :-
atom_concat(Species,Change,NumChange),
Head = [[A1, A2], NumChange, Constraint],
build_change(A1, A2, Constraint, Sp_tail, Ch_tail, Out_tail).
;
Later_list = Next_list
)
).
add_n_copy_list(Orig_list, Start_counter, Species_counter, Next_list_temp, Out_init, Next_list) :-
length(Orig_list, Total_length),
(
Start_counter =< Total_length
->
(
Start_counter == Species_counter
->
nth1(Start_counter, Orig_list, To_add),
append(To_add, Next_list_temp, Next_insert),
append(Out_init, [Next_insert], Middle_list)
;
nth1(Start_counter, Orig_list, To_add),
%%% print('to add = '), print(To_add), print('\n'),
append(Out_init, [To_add], Middle_list)
),
Next_counter is (Start_counter + 1),
add_n_copy_list(Orig_list, Next_counter, Species_counter, Next_list_temp, Middle_list, Next_list)
;
Next_list = Out_init
).
%! append_elem_list(+L1, +L2, -L12)
%
% append all the element of the 2 lists
check_change(First_alpha, Second_alpha, Constraint, Stoch_species_order,Species_counter, Species_change, Orig_list, Result_list) :-
append_elem_list([],[],[]).
nth1(Species_counter, Species_change, Change),
(
Change == '+0'
->
length(Stoch_species_order, Last_count),
(
Species_counter < Last_count
->
Next_species is (Species_counter + 1),
check_change(First_alpha, Second_alpha, Constraint, Stoch_species_order,Next_species, Species_change, Orig_list, Result_list)
;
Result_list = Orig_list
)
;
nth1(Species_counter, Stoch_species_order, Species),
nth1(Species_counter, Species_change, Change),
atom_concat(Species, Change, Numerous_change),
% !!! Putting things into the helper list !!!
add_n_copy_list(Orig_list, 1, Species_counter,
[[First_alpha, Second_alpha], Numerous_change, Constraint], [], Next_list),
length(Stoch_species_order, Last_count),
(
Species_counter < Last_count
->
Next_species is (Species_counter + 1),
check_change(First_alpha, Second_alpha, Constraint, Stoch_species_order,Next_species, Species_change, Next_list, Result_list)
;
Next_list = Result_list
)
).
append_elem_list([H1|T1],[H2|T2],[H12|T12]) :-
append(H1,H2,H12),
append_elem_list(T1,T2,T12).
%======================%
%== Real Output Part ==%
......@@ -1182,11 +1119,9 @@ print_dynamic_event(SortedSpecies,Reactions_data, HybridDynamicReactants,MaxPart
% 3. Print reactions in event
length(Stoch_species_order, Number_of_species),
constant_list(Number_of_species,[],Init_list2),
% Build the print_helper_list.
print_normal(Reactions_data, Init_list2, Print_helper_list, Alpha_accumulation_list, Constraints_list, Stoch_species_order, 1),
build_normal(Reactions_data, Print_helper_list, Alpha_accumulation_list, Constraints_list, Stoch_species_order, 1),
% Use print_helper_list to really print out the event part.
length(Stoch_species_order,NumberOfSpecies),
print_change_list(NumberOfSpecies,Print_helper_list, Stoch_species_order, 1, Number_of_species, Stream).
print_change_list(NumberOfSpecies,Print_helper_list, Stoch_species_order, 1, NumberOfSpecies, Stream).
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment