Commit b9d1dd08 authored by HEMERY Mathieu's avatar HEMERY Mathieu
Browse files

Rewrite the alpha list building functions

parent e2d4344e
......@@ -528,10 +528,7 @@ print_event(Reactions_data, Stoch_list, Hybrid_reactants_list, Constraints_list,
print_hybrid_species_constraint(Hybrid_reactants_list, 1, Stream),
% 2. Build alpha list and alpha subsums.
build_alpha_list(1, [], Number_of_alpha, Alpha_list),
nth1(1,Alpha_list, First_alpha),
append([], [First_alpha], Init_list),
alpha_accumulation(Alpha_list, Init_list, Alpha_accumulation_list, 2),
build_alphas(Number_of_alpha, Alpha_list, Alpha_accumulation_list),
% 3. Print reactions in event
constant_list(Number_of_species,[],Init_list2),
......@@ -615,37 +612,39 @@ print_alpha_sr([N|Tail], Stream) :-
%========================================%
%== Build Alpha list for current event ==%
%== Build Alpha lists for current event ==%
%========================================%
build_alpha_list(Counter_for_alpha, Init, Number_of_alpha, Alpha_list) :-
(
Counter_for_alpha =< Number_of_alpha
->
atom_number(Counter_for_alpha_atom,Counter_for_alpha),
atom_concat('alpha', Counter_for_alpha_atom, Current_alpha),
append(Init, [Current_alpha], Next_init),
Next_counter_alpha is (Counter_for_alpha + 1),
build_alpha_list(Next_counter_alpha, Next_init, Number_of_alpha, Alpha_list)
;
Alpha_list = Init
).
alpha_accumulation(Alpha_list, Previous_list,Alpha_accumulation_list, Current_count) :-
length(Alpha_list, Number_of_alpha),
(
Current_count =< Number_of_alpha
->
nth1(Current_count, Alpha_list, Alpha_2add),
Previous_count is (Current_count - 1),
nth1(Previous_count, Previous_list, Previous_sum),
atom_concat(Previous_sum, ' + ', Temp),
atom_concat(Temp, Alpha_2add, New_sum),
append(Previous_list, [New_sum], New_list),
New_count is (Current_count + 1),
alpha_accumulation(Alpha_list, New_list,Alpha_accumulation_list, New_count)
;
Alpha_accumulation_list = Previous_list
).
%! build_alphas(+N_alpha, -Alpha_list, -Alpha_accumulation_list)
build_alphas(N_alpha, Alpha_list, Alpha_accumulation_list) :-
numlist(1, N_alpha, NL),
build_alpha_list(NL, Alpha_list),
alpha_accumulation(Alpha_list, '', Alpha_accumulation_list).
%! build_alpha_list(+Num_list, -Alpha_list)
build_alpha_list([], []).
build_alpha_list([N|NTail], [Alpha| AlphaTail]) :-
atom_concat('alpha', N, Alpha),
build_alpha_list(NTail, AlphaTail).
%! alpha_accumulation(+Alpha_list, +'', -Alpha_accumulation_list)
%
% Accumulate the alphas, the mid argument should be '' to initialize the accumulator
alpha_accumulation([A|Tail_A], '', [A|Tail_Acc]) :- !,
alpha_accumulation(Tail_A, A, Tail_Acc).
alpha_accumulation([A|Tail_A], Acc, [Accn|Tail_Acc]) :-
atomic_list_concat([Acc,'+',A], Accn),
alpha_accumulation(Tail_A, Accn, Tail_Acc).
alpha_accumulation([], _Acc, []).
%=============================%
%== Get Data from Reactions ==%
......@@ -1239,17 +1238,7 @@ print_dynamic_event(SortedSpecies,Reactions_data, HybridDynamicReactants,MaxPart
write(Stream,' tau = Time+delta_t/'),write(Stream,Rate),write(Stream,','),nl(Stream),
write(Stream,' ran = random_float,'),nl(Stream),
print_hybrid_species_constraint(Hybrid_reactants_list, 1, Stream),
% 2. Build alpha list and alpha subsums.
length(Reactions_data, Number_of_alpha),
% Build Alpha_list
build_alpha_list(1, [], Number_of_alpha, Alpha_list),
% Build Alpha subsums
nth1(1,Alpha_list, First_alpha),
append([], [First_alpha], Init_list),
alpha_accumulation(Alpha_list, Init_list, Alpha_accumulation_list, 2),
build_alphas(Number_of_alpha, Alpha_list, Alpha_accumulation_list),
% 3. Print reactions in event
......
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