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

Correct a cut in is_present that make bad behavior of infer_hidden_molecules

parent 767ab0d1
......@@ -773,6 +773,7 @@ infer_hidden_molecules(Id) :-
ode(Id, _X, Expr),
hidden_molecules(Expr, IS)
->
format("Correcting: ~w~n", [IS]),
correct_hidden_molecules(Id, IS),
fail
;
......@@ -780,6 +781,7 @@ infer_hidden_molecules(Id) :-
).
% correct_hidden_molecules(+Id, +Implicit_Species)
%
% modify the current ODE system to add the implicit species and insert it in the
......@@ -879,7 +881,9 @@ hidden_molecules(Expression, K-X-Y) :-
;
is_present(-X-Y+K, Expression)
),
is_numeric(K).
is_numeric(K),
is_molecule_like(X),
is_molecule_like(Y).
hidden_molecules(Expression, K-X) :-
(
......@@ -887,8 +891,19 @@ hidden_molecules(Expression, K-X) :-
;
is_present(-X+K, Expression)
),
is_numeric(K).
format("candidate: ~w~n", [K-X]),
is_numeric(K),
writeln(ok),
is_molecule_like(X).
is_molecule_like(X) :-
is_molecule(X).
is_molecule_like(K*X) :-
is_numeric(K),
is_molecule(X).
is_molecule_like(X*K) :-
is_numeric(K),
is_molecule(X).
:- dynamic(reactant/2).
......@@ -1717,9 +1732,11 @@ is_polynomial_sr(A) :- is_numeric(A).
is_molecule(A) :-
identifier_kind(_ModelId, A, object),!.
is_molecule(A) :-
% needed when parameters only attached to ode system
get_current_ode_system(Id),
item([parent:Id, kind:ode, item:d(A)/dt=_Derivative]),
% needed when molecules only attached to ode system
get_current_ode_system(Idp),
item([parent:Idp, kind:ode, id:ODE_Id]),
item([id:ODE_Id, item:MyODE]),
MyODE = (d(A)/dt=_Der),
!.
is_numeric(N) :-
......
......@@ -974,12 +974,11 @@ realsetof(X, Goal, List):-
%
% succeed if Term is present in Expression
is_present(Term, Term) :- !.
is_present(Term, Term).
is_present(Term, Expression) :-
Expression =.. [_Functor| Termlist],
is_present_list(Term, Termlist).
is_present_list(Term, [Expr|_Tail]) :-
is_present(Term, Expr),
!.
is_present(Term, Expr).
is_present_list(Term, [_Other|Tail]) :-
is_present_list(Term, Tail).
......@@ -19,7 +19,7 @@ test('expand_polynomial') :-
expand_polynomial(p*r1*n1*(1-(n0+n1+n2)/k)/co, p/co*r1*n1*1-p/co*r1*n1*(n0/k)-p/co*r1*n1*(n1/k)-p/co*r1*n1*(n2/k)),
expand_polynomial(bb/e*(pa+ -1)*db, bb/e*pa*db + bb/e*(-1)*db).
test('is_present') :-
test('is_present', [nondet]) :-
is_present(a, b*f(a)),
is_present(a, b*f(a/c)),
is_present(a, f(a*b)/c),
......
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