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

Repair the construction of the maximum threshold

parent 7cea27c7
......@@ -1191,14 +1191,9 @@ hybrid_dynamic_simulation(InputFile,OutFilename,Volume,Time,PropTresh,PartTresh)
prepare_change_list(Reactions, SortedSpecies, Reaction_list),
build_reaction_data(Reaction_list, SortedSpecies, Reactions_data),
% Because inf/0 is not defined in old versions of SWI-Prolog, we use
% something else
current_prolog_flag(max_tagged_integer, Inf),
assertz(minimum_reactant_change(Inf)),
assertz(maximum_reactant_change(0)),
assertz(minimum_product_change(Inf)),
assertz(maximum_product_change(0)),
compute_maximum_change(Reaction_list, MaxParticleChange),
ParticuleTreshold is MaxParticleChange*PartTresh,
findall([RSpecies,Alpha],
(
member(Element,Reaction_list),
......@@ -1213,8 +1208,6 @@ hybrid_dynamic_simulation(InputFile,OutFilename,Volume,Time,PropTresh,PartTresh)
),
HybridDynamicReactants),
compute_maximum_change(MaxParticleChange),
ParticuleTreshold is MaxParticleChange*PartTresh,
close(Stream),
open(OutFilename,append,StreamAppend),
print_dynamic_event(SortedSpecies,Reactions_data, HybridDynamicReactants,ParticuleTreshold,PropTresh, SortedStochSpecies, StochReactants,Hybrid_reactants_list, Constraints_list, StreamAppend),
......@@ -1242,48 +1235,31 @@ hybrid_dynamic_simulation(InputFile,OutFilename,Volume,Time,PropTresh,PartTresh)
:- biocham(hybrid_dynamic_simulation('library:examples/hybrid/Goutsias_dynamic.bc',20,10)).
:- doc('\\end{example}').
compute_partial_maximum_change(RSum,PSum) :-
retract(minimum_reactant_change(OldRMin)),
retract(maximum_reactant_change(OldRMax)),
retract(minimum_product_change(OldPMin)),
retract(maximum_product_change(OldPMax)),
(
RSum < OldRMin
->
assertz(minimum_reactant_change(RSum))
;
assertz(minimum_reactant_change(OldRMin))
),
(
RSum > OldRMax
->
assertz(maximum_reactant_change(RSum))
;
assertz(maximum_reactant_change(OldRMax))
),
(
PSum < OldPMin
->
assertz(minimum_product_change(PSum))
;
assertz(minimum_product_change(OldPMin))
),
(
PSum > OldPMax
->
assertz(maximum_product_change(PSum))
;
assertz(maximum_product_change(OldPMax))
).
compute_maximum_change(MaxParticleChange) :-
retract(minimum_reactant_change(RMin)),
retract(maximum_reactant_change(RMax)),
retract(minimum_product_change(PMin)),
retract(maximum_product_change(PMax)),
Max1 is abs(PMax-RMin),
Max2 is abs(RMax-PMin),
MaxParticleChange is max(Max1,Max2).
%! compute_maximum_change(+Reaction_list, -MaxParticleChange) :-
compute_maximum_change(Reaction_list, MaxParticleChange) :-
extract_stoechiometry_list(Reaction_list, Reactant_list, Product_list),
min_list(Reactant_list, RMin),
max_list(Reactant_list, RMax),
min_list(Product_list, PMin),
max_list(Product_list, PMax),
MaxParticleChange is max(abs(PMax-RMin),abs(RMax-PMin)).
%! extract_stoechiometry_list(+Reaction_list, -Reactant_list, -Product_list)
%
% Extract a list of the total stoechiometry of each reaction
extract_stoechiometry_list([],[],[]) :- !.
extract_stoechiometry_list([[Reactants, Products, _A]|TReac], [SR|TReactant], [SP|TProduct]) :-
findall(CoeffR, member(CoeffR*_RSpecies, Reactants), CoeffR_list),
sum_list(CoeffR_list, SR),
findall(CoeffP, member(CoeffP*_PSpecies, Products), CoeffP_list),
sum_list(CoeffP_list, SP),
extract_stoechiometry_list(TReac, TReactant, TProduct).
particle_sum_list([],0).
......
:- use_module(hybrid).
example_reactions([[[1*gen],[1*tem],c1*'gen_stoch'],[[1*tem],[],c2*('tem_total'/(100*1))],[[1*tem],[1*tem,1*gen],c3*('tem_total'/(100*1))],[[1*gen,1*struc],[1*virus],c4*('gen_stoch'*('struc_total'/(100*1)))]]).
:- begin_tests(hybrid).
test(build_constraints_list) :-
......@@ -7,8 +9,12 @@ test(build_constraints_list) :-
test(build_reaction_data) :-
Sorted_species = [gen,struc,tem,virus],
List = [[[1*gen],[1*tem],c1*'gen_stoch'],[[1*tem],[],c2*('tem_total'/(100*1))],[[1*tem],[1*tem,1*gen],c3*('tem_total'/(100*1))],[[1*gen,1*struc],[1*virus],c4*('gen_stoch'*('struc_total'/(100*1)))]],
example_reactions(List),
hybrid:build_reaction_data(List, Sorted_species, Data),
Data = [[['-1','+0','+1','+0'],c1*'gen_stoch'],[['+0','+0','-1','+0'],c2*('tem_total'/(100*1))],[['+1','+0','+0','+0'],c3*('tem_total'/(100*1))],[['-1','-1','+0','+1'],c4*('gen_stoch'*('struc_total'/(100*1)))]].
test(compute_maximum_change) :-
example_reactions(List),
hybrid:compute_maximum_change(List,2).
:- end_tests(hybrid).
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