Commit c9a1dfed authored by SOLIMAN Sylvain's avatar SOLIMAN Sylvain

put as much as possible into catalysts, i.e. 2 * a => a has a catalyst

parent 7195ee60
......@@ -491,14 +491,31 @@ collect_object([CoefficientObject | Tail], Object, Sum, Others) :-
simplify_catalyst([], Right, [], [], Right).
simplify_catalyst([Head | Tail], Right, NewLeft, Catalyst, NewRight) :-
simplify_catalyst([LeftCoeff*Head | Tail], Right, NewLeft, Catalyst, NewRight) :-
(
select(Head, Right, OthersRight)
select(RightCoeff*Head, Right, OthersRight)
->
Catalyst = [Head | CatalystTail],
simplify_catalyst(Tail, OthersRight, NewLeft, CatalystTail, NewRight)
Coeff is min(LeftCoeff, RightCoeff),
Catalyst = [Coeff*Head | CatalystTail],
(
Coeff < LeftCoeff
->
Remain is LeftCoeff - Coeff,
NewLeft = [Remain*Head | RemainLeft],
NewRight = RemainRight
;
Coeff < RightCoeff
->
Remain is RightCoeff - Coeff,
NewLeft = RemainLeft,
NewRight = [Remain*Head | RemainRight]
;
NewLeft = RemainLeft,
NewRight = RemainRight
),
simplify_catalyst(Tail, OthersRight, RemainLeft, CatalystTail, RemainRight)
;
NewLeft = [Head | LeftTail],
NewLeft = [LeftCoeff*Head | LeftTail],
simplify_catalyst(Tail, Right, LeftTail, Catalyst, NewRight)
).
......
......@@ -14,7 +14,7 @@ test(
test(
'catalyst',
[Reactions == [2 * b =[ a + c ]=> b, b =[ a + c ]=> 2 * b]]
[Reactions == [b =[ b + a + c ]=> '_', '_' =[ b + a + c ]=> b]]
) :-
clear_model,
add_reaction(a + b + c <=[ b ]=> a + 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