Commit a3497ba4 authored by Mathieu Hemery's avatar Mathieu Hemery
Browse files

Rewrite in depth the print_change_list

parent 6b3552b9
......@@ -514,7 +514,6 @@ build_reaction_data([[RList, PList, Coef]|ReacTail], Species_list, [[Stoech, Coe
print_event(Reactions_data, Stoch_list, Hybrid_reactants_list, Constraints_list, Stream) :-
get_option(stochastic_conversion,Rate),
length(Reactions_data, Number_of_alpha),
length(Stoch_list, Number_of_species),
print_alpha_parameters(Number_of_alpha, Stream),
print_constraints_parameters(Constraints_list, Stream),
......@@ -534,7 +533,7 @@ print_event(Reactions_data, Stoch_list, Hybrid_reactants_list, Constraints_list,
% Build the print_helper_list.
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).
print_change_list(Print_helper_list, Stoch_list, Stream).
%! print_alpha_parameters(+N_alpha, +Stream)
......@@ -696,77 +695,40 @@ append_elem_list([H1|T1],[H2|T2],[H12|T12]) :-
%== Real Output Part ==%
%======================%
print_change_list(NumberOfSpecies,Print_helper_list, Species_order, Current_counter, Last_counter, Stream) :-
%%% print(Print_helper_list), print('\n'),
nth1(Current_counter, Print_helper_list, Change_list),
Change_list = [[Lower, Upper], First_change, Constraint | Change_Tail],
nth1(Current_counter,Species_order,Species),
%! print_change_list(Modif_list, species_list, Stream)
%
% write the event of a stochastic reaction in the output_file.
print_change_list([], [], Stream) :-
format(Stream, ").~n", []), !.
print_change_list([Change_list | Helper_tail], [Species | Sp_tail], Stream) :-
(
length(Change_list, Triple_of_change),
Triple_of_change > 0
Change_list = [[Lower, Upper], First_change, Constraint | Change_Tail]
->
% First Change start with only "if".
format(Stream, " ~w = (if alpha_sum*ran>~w and alpha_sum*ran<=~w", [Species, Lower, Upper]),
(
Constraint == '0'
->
true
;
format(Stream, " and ~w >0", [Constraint])
),
(Constraint == '0' -> true ; format(Stream, " and ~w >0", [Constraint])),
format(Stream, " then ~w", [First_change]),
(
Change_number is (Triple_of_change / 3),
Change_number > 1
->
print_ifThenElse(Change_Tail, Stream)
;
!
),
% The last one.
print_if_then_else(Change_Tail, Stream),
format(Stream, "~n else ~w)", [Species]),
(
Current_counter = NumberOfSpecies
->
true
;
write(Stream,',')
),
(Sp_tail = [] -> true ; write(Stream,',')),
nl(Stream)
;
nth1(Current_counter, Species_order, Species_name),
write(Stream, Species_name)
write(Stream, Species)
),
% Recursive condition on species
(
Current_counter < Last_counter
->
Next_counter is (Current_counter + 1),
print_change_list(NumberOfSpecies,Print_helper_list, Species_order, Next_counter, Last_counter, Stream)
;
write(Stream, ').'), nl(Stream), !
).
print_change_list(Helper_tail, Sp_tail, Stream).
print_ifThenElse([], _Stream) :- !.
print_ifThenElse([[Lower, Upper], Change, Constraint | Change_Tail], Stream) :-
nl(Stream),
write(Stream, ' else if alpha_sum*ran>'),
write(Stream, Lower),
write(Stream, ' and alpha_sum*ran<='),
write(Stream, Upper),
(
Constraint \== '0'
->
write(Stream, ' and '),
write(Stream, Constraint),
write(Stream, '>0')
;
true
),
write(Stream, ' then '),
write(Stream, Change),
print_ifThenElse(Change_Tail, Stream).
%! print_if_then_else(+Change_list, +Stream)
print_if_then_else([], _Stream) :- !.
print_if_then_else([[Lower, Upper], Change, Constraint | Change_Tail], Stream) :-
format(Stream, "~n else if alpha_sum*ran>~w and alpha_sum*ran<=~w", [Lower, Upper]),
(Constraint == '0' -> true ; format(Stream, " and ~w >0", [Constraint])),
format(Stream, " then ~w", [Change]),
print_if_then_else(Change_Tail, Stream).
print_single_reaction_constraints(Constraints, Total, Current, Stream) :-
(
......@@ -1088,7 +1050,4 @@ print_dynamic_event(SortedSpecies,Reactions_data, HybridDynamicReactants,MaxPart
% 3. Print reactions in event
% Build the print_helper_list.
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, NumberOfSpecies, Stream).
print_change_list(Print_helper_list, Stoch_species_order, 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