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

Rewrite some list constructer and find some bugs

parent b313399f
......@@ -175,7 +175,7 @@ hybrid_static_simulation(ODEFilename, StochFilename, OutFilename, Volume, Time)
Reactants_by_rules),
build_constraints_by_rules(Reactants_by_rules, SortedReactants, 1, [], Hybrid_reactants_list),
build_constraints_list(Hybrid_reactants_list, 1, [], Constraints_list),
build_constraints_list(Hybrid_reactants_list, Constraints_list),
findall(Reactant_stoch,
(
......@@ -201,7 +201,11 @@ hybrid_static_simulation(ODEFilename, StochFilename, OutFilename, Volume, Time)
% build StochReactants(with '_total') from SortedStochSpecies.
length(SortedStochSpecies, Species_number),
build_reactants(SortedStochSpecies, SortedODESpecies, Species_number, 1, [], StochReactants),
build_reactants_old(SortedStochSpecies, SortedODESpecies, Species_number, 1, [], StochReactantsold),
writeln(SortedStochSpecies),
writeln(SortedODESpecies),
writeln(StochReactants),
writeln(StochReactantsold),
%========================================%
%==== Build Data Lists for Reactions ====%
%========================================%
......@@ -232,7 +236,7 @@ hybrid_static_simulation(ODEFilename, StochFilename, OutFilename, Volume, Time)
),
Reactions_data),
%== Build Events and Calaculate Alphas==%
%== Build Events and Calculate Alphas==%
print_event(Reactions_data, SortedStochSpecies, StochReactants,Hybrid_reactants_list, Constraints_list, Stream),
format(Stream, "~n% Plot part~n~n", []),
......@@ -241,6 +245,8 @@ hybrid_static_simulation(ODEFilename, StochFilename, OutFilename, Volume, Time)
format(Stream, "numerical_simulation(method:rsbk, time: ~g).~n", Time),
format(Stream, "plot.~noption(show: {}).~n", []),
close(Stream),
%== Clean Biocham state and call the simulation ==%
nb_delete(volume),
nb_delete(reactions),
retractall(reaction_kinetics(_,_)),
......@@ -271,93 +277,111 @@ species_to_stoch(Species, Species_stoch) :-
species_to_total(Species, Species_total) :-
atomic_list_concat(['\'', Species, '_total\''], Species_total).
%! build_constraints_by_rules(Reactants_by_rules, ODEReactants, Current_counter, Orig_list, Results_list)
%
% The 'Current_counter' here is used for indexing reactions.
build_constraints_by_rules(Reactants_by_rules, ODEReactants, Current_counter, Orig_list, Results_list) :-
length(Reactants_by_rules, Number_of_rules),
nth1(Current_counter, Reactants_by_rules, This_reactants_list),
findall(Constraints,(
(
\+(list(This_reactants_list))
->
This_reactants_list = Least_number * Reactant_name,
member(Reactant_name, ODEReactants)
;
member(Reactants_pair, This_reactants_list),
Reactants_pair = Least_number * Reactant_name,
member(Reactant_name, ODEReactants)
)
->
(
species_to_total(Reactant_name, Reactant_total),
atom_concat(Reactant_total, ' >= ', Temp),
Reactants_pair = Least_number * Reactant_name,
atom_number(Least_number_atom,Least_number),
atom_concat(Temp, Least_number_atom, Constraints)
)
;
Constraints = 0
),This_constraints_list),
findall(Constraints,
(
(
\+(list(This_reactants_list))
->
This_reactants_list = Least_number * Reactant_name,
member(Reactant_name, ODEReactants)
;
member(Reactants_pair, This_reactants_list),
Reactants_pair = Least_number * Reactant_name,
member(Reactant_name, ODEReactants)
)
->
(
species_to_total(Reactant_name, Reactant_total),
atom_concat(Reactant_total, ' >= ', Temp),
Reactants_pair = Least_number * Reactant_name,
atom_number(Least_number_atom,Least_number),
atom_concat(Temp, Least_number_atom, Constraints)
)
;
Constraints = 0
),
This_constraints_list),
append(Orig_list, [This_constraints_list], Next_list),
(
Current_counter < Number_of_rules
->
(
Next_counter is Current_counter + 1,
build_constraints_by_rules(Reactants_by_rules, ODEReactants, Next_counter, Next_list, Results_list)
)
;
(
Results_list = Next_list,
!
)
).
Current_counter < Number_of_rules
->
(
Next_counter is Current_counter + 1,
build_constraints_by_rules(Reactants_by_rules, ODEReactants, Next_counter, Next_list, Results_list)
)
;
Results_list = Next_list, !
).
build_constraints_list(Hybrid_reactants_list, Reaction_counter, Init_list, Constraints_list) :-
nth1(Reaction_counter, Hybrid_reactants_list, This_list),
(
This_list \== [0]
->
(
atom_number(Reaction_counter_atom,Reaction_counter),
atom_concat('lower_level', Reaction_counter_atom, Corresponding_constraint),
append(Init_list, [Corresponding_constraint], Next_list)
)
;
%! build_constraints_list(+Hybrid_reactants_list, -Constraints_list)
%
% Construct the lists of lower_level#r atom for later use
build_constraints_list(Hybrid_list, Constraint_list) :-
build_constraints_list(Hybrid_list, 1, Constraint_list).
build_constraints_list([], _Counter, []).
build_constraints_list([List| InTail], Counter, [Constraint| OutTail]) :-
(
append(Init_list, ['0'], Next_list)
)
),
(
length(Hybrid_reactants_list, Total_count),
Reaction_counter < Total_count
->
List = [0]
->
Constraint = '0'
;
atom_number(Counter_atom, Counter),
atom_concat('lower_level', Counter_atom, Constraint)
),
Counterp is Counter + 1,
build_constraints_list(InTail, Counterp, OutTail).
% build_reactants(StochSpecies, ODESpecies, Species_number, Counter, Init, StochReactants)
build_reactants(StochSpecies, ODESpecies, _SpN, _Cou, _Ini, StochReactants) :-
build_reactants(StochSpecies, ODESpecies, StochReactants).
build_reactants([], _ODESpecies, []).
build_reactants([Species|SpTail], ODESpecies, [Reactant|ReacTail]) :-
(
Next_counter is Reaction_counter + 1,
build_constraints_list(Hybrid_reactants_list, Next_counter, Next_list, Constraints_list)
)
;
Constraints_list = Next_list
).
member(Species, ODESpecies)
->
species_to_total(Species, Reactant)
;
species_to_stoch(Species, Reactant)
),
build_reactants(SpTail, ODESpecies, ReacTail).
build_reactants(StochSpecies, ODESpecies, Species_number, Counter, Init, StochReactants) :-
build_reactants_old(StochSpecies, ODESpecies, Species_number, Counter, Init, StochReactants) :-
nth1(Counter, StochSpecies, This_species),
(
member(This_species, ODESpecies)
->
species_to_total(This_species, This_reactant)
member(This_species, ODESpecies)
->
species_to_total(This_species, This_reactant)
;
species_to_stoch(This_species, This_reactant)
species_to_stoch(This_species, This_reactant)
),
append(Init, [This_reactant], Next),
(
Counter < Species_number
Counter < Species_number
->
Next_counter is Counter + 1,
build_reactants(StochSpecies, ODESpecies, Species_number, Next_counter, Next, StochReactants)
Next_counter is Counter + 1,
build_reactants_old(StochSpecies, ODESpecies, Species_number, Next_counter, Next, StochReactants)
;
StochReactants = Next
StochReactants = Next
).
write_hybrid_ode(Stream,Hybrid_original_list) :-
list_hybrid_ode(Stream,Hybrid_original_list),
with_output_to(Stream, models:list_model_initial_state),
......@@ -1206,7 +1230,7 @@ hybrid_dynamic_simulation(InputFile,OutFilename,Volume,Time,PropTresh,PartTresh)
SortedStochSpecies),
build_constraints_by_rules(Reactants_by_rules, SortedReactants, 1, [], Hybrid_reactants_list),
build_constraints_list(Hybrid_reactants_list, 1, [], Constraints_list),
build_constraints_list(Hybrid_reactants_list, Constraints_list),
length(SortedSpecies,Species_number),
build_reactants(SortedSpecies, SortedSpecies, Species_number, 1, [], StochReactants),
......
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