Commit cbf964c0 authored by SOLIMAN Sylvain's avatar SOLIMAN Sylvain
Browse files

removed useless rescaled system, now working

parent 370b31b0
......@@ -101,18 +101,12 @@ conserve(L, D) :-
% P-invariants already computed to enforce constraints on the exponents Ai
set_conservations(Ai, Places) :-
nb_getval(base, B),
(
B \= 0
->
invariants:vars(Vars),
length(Ai, N),
length(Bi, N),
reorder_place_vars(Ai, Bi, Places, Vars),
get_initial_values(Vars, Di),
set_conservations_rec(B, Bi, Di)
;
true
),
invariants:vars(Vars),
length(Ai, N),
length(Bi, N),
reorder_place_vars(Ai, Bi, Places, Vars),
get_initial_values(Vars, Di),
set_conservations_rec(B, Bi, Di),
set_constant_vars.
......@@ -303,6 +297,7 @@ get_equilibrations(Vars, Ai, E, DE) :-
),
L
),
debug(tropical, "ODEs: ~w", [L]),
get_equilibrations_rec(L, Vars, Ai, E, DE).
......@@ -323,7 +318,7 @@ get_equilibrations_rec([(S, O) | L], Vars, Ai, [E | EE], [DE | DEE]) :-
substract_rec(L, A, LA) :-
maplist(L, reverse_minus(A), LA).
maplist(tropical:reverse_minus(A), L, LA).
reverse_minus(A, B, B - A).
......@@ -334,7 +329,7 @@ show_rescaling([], []) :-
show_rescaling([A | AA], [V | VV]) :-
epsilon_degree(A, D),
format("~p_ = ~p~p~n", [V, D, V]),
format("~w' = ~w~w~n", [V, D, V]),
show_rescaling(AA, VV).
......@@ -363,152 +358,6 @@ epsilon_degree(D, A) :-
).
rescale_system(E, S) :-
eval_rec(E, EE),
get_rescaled_odes(EE, O),
sort_by_scale_rec(O, OO),
predsort(compare_first_degree, OO, S).
print_system([]) :-
nl.
print_system([(Species, ODE) | L]) :-
format("d~p/dt = ", [Species]),
print_ode(ODE),
print_system(L).
print_ode([]) :-
write('0\n').
print_ode([(D, T) | O]) :-
epsilon_degree(D, A),
print(A),
(
A \= '',
T = _ + _
->
format("(~p)", [T])
;
print(T)
),
(
O == []
->
nl
;
print(' + '),
print_ode(O)
).
compare_first_degree(Result, (S1, [(D1, _) | _]), (S2, [(D2, _) | _])) :-
compare(Result, (D1, S1), (D2, S2)).
get_rescaled_odes([], []).
get_rescaled_odes([(LPos, LNeg) | E], [(Species, O) | OO]) :-
retract(ode(Species, T)),
rescale_to(T, LPos, LNeg, O),
get_rescaled_odes(E, OO).
rescale_to(E + N * T, Pos, Neg, EEE) :-
!,
rescale_to(N * T, Pos1, Neg1, RT),
append(RT, EE, EEE),
append(Pos1, LPos, Pos),
append(Neg1, LNeg, Neg),
rescale_to(E, LPos, LNeg, EE).
rescale_to(N * (A + B), Pos, Neg, EE) :-
!,
rescale_to(N * A + N * B, Pos, Neg, EE).
rescale_to(N * (A - B), Pos, Neg, EE) :-
!,
M is -N,
rescale_to(N * A + M * B, Pos, Neg, EE).
rescale_to(_ * T, [], [], []) :-
is_zero(T),
!.
rescale_to(N * T, LPos, LNeg, [RT]) :-
!,
(
N > 0
->
LPos = [Exp],
LNeg = []
;
LNeg = [Exp],
LPos = []
),
RT = (Exp, N * T).
sort_by_scale_rec([], []).
sort_by_scale_rec([(Species, Ode) | L], [(Species, SOde) | LL]) :-
sort_by_scale(Ode, SOde),
sort_by_scale_rec(L, LL).
sort_by_scale(L, SL) :-
sort_by_scale_aux(L, SL, []).
sort_by_scale_aux([], L, L).
sort_by_scale_aux([H | T], SL, L) :-
merge_by_scale(L, H, LL),
sort_by_scale_aux(T, SL, LL).
merge_by_scale([(N, T1) | L], (N, T2), [(N, T1 + T2) | L]) :-
!.
merge_by_scale([(N, T1) | L], (M, T2), [(N, T1) | LL]) :-
N < M,
!,
merge_by_scale(L, (M, T2), LL).
merge_by_scale(L, (M, T2), [(M, T2) | L]).
eval_rec([], []) :-
!.
eval_rec([H | T], [HH | TT]) :-
!,
eval_rec(H, HH),
eval_rec(T, TT).
eval_rec((A, B), (AA, BB)) :-
!,
eval_rec(A, AA),
eval_rec(B, BB).
eval_rec(A, B) :-
B is A.
% FIXME add rescaled conservation to S1
reduce_system([], [], []).
reduce_system([(Species, [(D, T) | _]) | ODEs], [T = 0 | S1], S2) :-
D < 0,
format("~p is a fast variable with invariant manifold ~p = 0~n", [Species, T]),
reduce_system(ODEs, S1, S2).
reduce_system([(Species, [(D, T) | L]) | ODEs], S1, [(Species, [(D, T) | L]) | S2]) :-
D >= 0,
format("~p is a slow variable~n", [Species]),
reduce_system(ODEs, S1, S2).
% look for an atom as a leaf of a term, not trying to unify FD vars
atom_is_subterm(_, Y) :-
var(Y),
......@@ -621,9 +470,7 @@ tropicalize :-
;
find_pinvar(4)
),
% FIXME why is this needed?
!,
debug(tropical, "invar done~n", []),
debug(tropical, "invar done", []),
statistics(cputime, Time0),
molecules_vars(Vars),
length(Vars, VL),
......@@ -637,10 +484,11 @@ tropicalize :-
between(2, Max, Power),
MaxD is 2^Power
),
debug(tropical, "about to set conservations…~n", []),
debug(tropical, "about to set conservations… (Max = ~w)", [MaxD]),
set_conservations(Ai, Vars),
debug(tropical, "conservations done~n", []),
get_equilibrations(Vars, Ai, E, DE),
debug(tropical, "conservations done", []),
get_equilibrations(Vars, Ai, E, _DE),
debug(tropical, "equilibrations: ~w", [E]),
(
Partial == 0
->
......@@ -662,20 +510,14 @@ tropicalize :-
labeling([bisect], Ai), % ffc makes biomodel 407 slow...
% bisect slightly better
(
Ovidiu \= 0
nb_current(ovidiu_file, _)
->
show_rescaling_ovidiu(Ai)
;
write('\nfound a complete equilibration leading to the rescaling:\n'),
show_rescaling(Ai, Vars),
rescale_system(DE, S),
write('using old variable names, here is the rescaled system:\n'),
print_system(S),
reduce_system(S, _S1, S2),
% FIXME should use S1 to simplify S2
write('\nreduced system:\n'),
print_system(S2)
)
show_rescaling(Ai, Vars)
),
fail
;
write('\nNo (more) complete equilibration\n'),
(
......
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