Commit 5a4a1020 authored by Mathieu Hemery's avatar Mathieu Hemery

Add the testsuite and some minor buggs correction

parent d840a9a8
......@@ -24,12 +24,12 @@ where reactions_s1 is a list of lists of the form
% the pivp_list (before rewriting).
rewrite_PIVP([N,ODE,Init], [NewN,NewODE,NewInit], VarNeg) :-
negative_initial_concentration(Init,VarNeg_Init),
negative_initial_concentration(Init, VarNeg_Init),
find_troubling_variables_main(ODE, VarNeg_Init, VarNeg),
rewrite_derivative_main(ODE, VarNeg, ODE_Tempo),
clean_ODE(ODE_Tempo,VarNeg,NewODE),
rewrite_initial_concentration(Init,VarNeg,NewInit),
length(VarNeg,NVN), NewN is N+NVN.
rewrite_initial_concentration(Init, VarNeg, NewInit),
length(VarNeg, NVN), NewN is N+NVN.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Detection part %%%
......@@ -85,7 +85,7 @@ find_troubling_variables_sr([], _LNVar, [], _N).
% skip the already negated variables
find_troubling_variables_sr([_Poly|Tail], LNVar, New_LNvar, N) :-
member(N,LNVar),
member(N,LNVar),!,
Np is N+1,
find_troubling_variables_sr(Tail, LNVar, New_LNvar, Np).
......@@ -106,7 +106,7 @@ find_troubling_variables_sr([Poly|Tail], LNVar, New_LNvar, N) :-
% true if the variable has to be negated at the polynomial level
find_troubling_polynomial(X, [Monom|Poly], LVar) :-
find_troubling_monomial(X, Monom, LVar);
find_troubling_monomial(X, Monom, LVar),!;
find_troubling_polynomial(X, Poly, LVar).
%! find_troubling_monomial(+Variable,+Monomial,+VarNeg_Current)
......@@ -122,7 +122,7 @@ find_troubling_monomial(X,[_Rate,Exponent],LVar) :-
nth1(X,Exponent,0),
member(Y,LVar),
nth1(Y,Exponent,N),
N > 0.
N > 0,!.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Rewriting part %%%
......@@ -216,7 +216,7 @@ rewrite_polynomial([Monom|Poly], Negated_Var, PolyMod) :-
rewrite_monomial([Rate,Expo], Negated_Var, [[Rate,Expand]]) :-
nth1(Negated_Var, Expo, 0),
rewrite_exponent(Expo, Negated_Var, Expand, _Dummy).
rewrite_exponent(Expo, Negated_Var, Expand, _Dummy),!.
rewrite_monomial([Rate,Expo], Negated_Var, [M1,M2]) :-
nth1(Negated_Var,Expo,EN),
......@@ -260,7 +260,7 @@ rewrite_exponent([E|Tail],Negated_Var,[Ep|Tailp],[En|Tailn]) :-
clean_ODE(ODE, List_Var_Neg, NewODE) :-
clean_ODE(ODE, List_Var_Neg, NewODE, 1).
clean_ODE([], _VarNeg, [], _N).
clean_ODE([], _VarNeg, [], _N) :- !.
clean_ODE(ODE, List_Var_Neg, NewODE, N) :-
(
member(N, List_Var_Neg)
......
:- use_module(library(plunit)).
:- use_module(lazy_negation_gpac).
example_lng(1,PIVP) :-
PIVP = [2,[ [[1,[0,1]]] , [[-1,[1,0]]] ],[1,0]].
example_lng(2,PIVP) :-
PIVP = [2,[ [[1,[1,0]]] , [[-1,[1,1]]] ],[-1,0]].
example_lng(3,PIVP) :-
PIVP = [2,[ [[1,[1,0]],[1,[0,1]]] , [[-1,[1,0]]] ],[1,0]].
example_lng(4,PIVP) :-
PIVP = [2,[ [[-1,[1,1]],[1,[0,1]]] , [[-1,[1,0]]] ],[1,0]].
example_lng(5,PIVP) :-
PIVP = [2,[ [[1,[0,0]],[-1,[2,0]]] , [[1,[1,0]],[-1,[0,1]]] ],[1,0]].
:- begin_tests(lazy_negation_gpac).
test(rewrite_pivp) :-
example_lng(2,PIVP_2),
rewrite_PIVP(PIVP_2, [3,[[[1, [1, 0, 0]]], [[1, [0, 1, 0]]], [[-1, [1, 0, 1]], [1, [0, 1, 1]]]], [0,1,0]], [1]).
test(negative_initial_concentration) :-
lng:negative_initial_concentration([0,0,-1,2],[3]),
lng:negative_initial_concentration([-4,0,2,-1,2],[1,4]),
lng:negative_initial_concentration([0,1,2],[]).
test(find_troubling_variables_main) :-
example_lng(1,[2, ODE1, _Init1]),
lng:find_troubling_variables_main(ODE1, [], NV1),
msort(NV1,[1,2]),
example_lng(2,[2, ODE2, _Init2]),
lng:find_troubling_variables_main(ODE2, [1], NV2),
msort(NV2,[1]),
example_lng(3,[2, ODE3, _Init3]),
lng:find_troubling_variables_main(ODE3, [], NV3),
msort(NV3,[1,2]),
example_lng(4,[2, ODE4, _Init4]),
lng:find_troubling_variables_main(ODE4, [], NV4),
msort(NV4,[1,2]),
example_lng(5,[2, ODE5, _Init5]),
lng:find_troubling_variables_main(ODE5, [], NV5),
msort(NV5,[]).
test(find_troubling_monomial) :-
lng:find_troubling_monomial(1,[-1,[0,1,1]],[]),
lng:find_troubling_monomial(1,[1,[0,1,1]],[3]),
lng:find_troubling_monomial(2,[1,[0,0,1]],[3]),
\+(lng:find_troubling_monomial(1,[-1,[1,0,1]],[])),
\+(lng:find_troubling_monomial(1,[1,[1,0,1]],[3])).
test(rewrite_initial_concentration) :-
lng:rewrite_initial_concentration([1,2,3],[2],[1,2,0,3]),
lng:rewrite_initial_concentration([1,-2,3],[2],[1,0,2,3]).
test(rewrite_derivative_sr) :-
example_lng(1,[2, ODE1, _Init1]),
lng:rewrite_derivative_sr(ODE1,2,[ [[1,[0,1,0]], [-1,[0,0,1]]], [[-1,[1,0,0]]], [] ]),
example_lng(2,[2, ODE2, _Init2]),
lng:rewrite_derivative_sr(ODE2,1,[ [[1,[1,0,0]], [-1,[0,1,0]]], [] , [[-1,[1,0,1]], [1,[0,1,1]]] ]).
:- end_tests(lazy_negation_gpac).
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