COPASI API  4.16.103
test_expression_comparison.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/compareExpressions/unittests/test_expression_comparison.cpp,v $
3 // $Revision: 1.7 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:26:44 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 #include "test_expression_comparison.hpp"
24 
25 #include <stdexcept>
26 
33 
34 void test_expression_comparison::setUp()
35 {
36  CCopasiRootContainer::init(false, 0, NULL);
37 }
38 
39 void test_expression_comparison::tearDown()
40 {
42 }
43 
44 void test_expression_comparison::test_substrate_activation()
45 {
46  // latex expression infix 1:
47  // \frac{V*\(\frac{substrate}{Ksa}\)^{2}}{1+\frac{substrate}{Ksc}+\frac{substrate}{Ksa}+\(\frac{substrate}{Ksa}\)^{2}}
48  std::string infix1("V*(substrate/Ksa)^2/(1+substrate/Ksc+substrate/Ksa+(substrate/Ksa)^2)");
49  // latex expression infix 2:
50  // \frac{V*substrate^2}{substrate^2+Ksa*(Ksa*Ksc^(-1)+1)*substrate+Ksa^2}
51  std::string infix2("V*substrate^2/(substrate^2+Ksa*(Ksa*Ksc^(-1)+1)*substrate+Ksa^2)");
52  CEvaluationTree* firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
53  firstTree->setInfix(infix1);
54  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
55  CEvaluationTree* secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
56  secondTree->setInfix(infix2);
57  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
58  CNormalBase * firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
59  CPPUNIT_ASSERT(firstBase != NULL);
60  CNormalFraction* firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
61  CPPUNIT_ASSERT(firstFraction != NULL);
62  CNormalBase * secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
63  CPPUNIT_ASSERT(secondBase != NULL);
64  CNormalFraction* secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
65  CPPUNIT_ASSERT(secondFraction != NULL);
66  CPPUNIT_ASSERT(*firstFraction == *secondFraction);
67  delete secondBase;
68  delete firstBase;
69  delete secondTree;
70  delete firstTree;
71 }
72 
73 void test_expression_comparison::test_allosteric_inhibition()
74 {
75  try
76  {
77  // latex expression infix 1
78  // {V*substrate*\(Ks+substrate╦ť)^{n-1}}{L*\(Ks*\(1+\frac{Inhibitor}{Ki}\)\)^{n}+\(Ks+substrate\)^{n}}
79  std::string infix1("V*substrate*(Ks+substrate)^(n-1)/(L*(Ks*(1+Inhibitor/Ki))^n+(Ks+substrate)^n)");
80  // latex expression infix 2
81  // \frac{\(Ks+substrate\)^{-1}*substrate*V}{1+L*\(\frac{Ki^{-1}*Ks*Inhibitor+Ks}{substrate+Ks}\)^{n}}
82  std::string infix2("(Ks+substrate)^(-1)*(substrate*V)/(1+L*((Ki^(-1)*Ks*Inhibitor+Ks)/(substrate+Ks))^n)");
83  CEvaluationTree* firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
84  firstTree->setInfix(infix1);
85  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
86  CEvaluationTree* secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
87  secondTree->setInfix(infix2);
88  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
89  //std::cout << firstTree->getRoot()->getInfix() << std::endl;
90  CNormalBase * firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
91  CPPUNIT_ASSERT(firstBase != NULL);
92  CNormalFraction* firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
93  CPPUNIT_ASSERT(firstFraction != NULL);
94  std::string s1 = firstFraction->toString();
95  //std::cout << "fraction 1: " << s1 << std::endl;
96  CNormalBase * secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
97  CPPUNIT_ASSERT(secondBase != NULL);
98  CNormalFraction* secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
99  CPPUNIT_ASSERT(secondFraction != NULL);
100  std::string s2 = secondFraction->toString();
101  //std::cout << "fraction 2: " << s2 << std::endl;
102  CPPUNIT_ASSERT(*firstFraction == *secondFraction);
103  delete secondBase;
104  delete firstBase;
105  delete secondTree;
106  delete firstTree;
107  }
108  catch (CCopasiException cce)
109  {
110  std::cout << "A COPASI exception." << std::endl;
111  }
112 }
113 
114 void test_expression_comparison::test_hyperbolic_modifier()
115 {
116  // Latex expression infix 1
117  // \frac{\(Vf*\frac{substrate}{Kms}-Vr*\frac{product}{Kmp}\)*\(1+\frac{b*Modifier}{a*Kd}\)}{1+\frac{Modifier}{Kd}+\(\frac{substrate}{Kms}+\frac{product}{Kmp}\)*\(1+\frac{Modifier}{a*Kd}\)}
118  std::string infix1("((Vf*substrate/Kms-Vr*product/Kmp)*(1+b*Modifier/(a*Kd)))/(1+Modifier/Kd+(substrate/Kms+product/Kmp)*(1+Modifier/(a*Kd)))");
119 
120  // Latex expression infix 2
121  // \frac{Kms^{-1}*Vf*substrate-Kmp^{-1}*Vr*product+\(\frac{Vf*b*substrate}{Kms*a}+\frac{b*-Vr*product}{a*Kmp}\)*Modifier/Kd}{1+\frac{1}{Kmp}*product+\frac{1}{Kms}*substrate+\(1+1/(a*Kms)*substrate+\frac{1}{a*Kmp}*product\)*\frac{Modifier}{Kd}}
122  std::string infix2("(Kms^(-1)*Vf*substrate-Kmp^(-1)*Vr*product+((Vf*b*substrate)/(Kms*a)+(b*(-Vr)*product)/(a*Kmp))*Modifier/Kd)/(1+1/Kmp*product+1/Kms*substrate+(1+1/(a*Kms)*substrate+1/(a*Kmp)*product)*Modifier/Kd)");
123  CEvaluationTree* firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
124  firstTree->setInfix(infix1);
125  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
126  CEvaluationTree* secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
127  secondTree->setInfix(infix2);
128  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
129  CNormalBase * firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
130  CPPUNIT_ASSERT(firstBase != NULL);
131  CNormalFraction* firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
132  CPPUNIT_ASSERT(firstFraction != NULL);
133  std::string s1 = firstFraction->toString();
134  //std::cout << "first : " << s1 << std::endl;
135  CNormalBase * secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
136  CPPUNIT_ASSERT(secondBase != NULL);
137  CNormalFraction* secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
138  CPPUNIT_ASSERT(secondFraction != NULL);
139  std::string s2 = secondFraction->toString();
140  //std::cout << "second: " << s2 << std::endl;
141  CPPUNIT_ASSERT(*firstFraction == *secondFraction);
142  delete secondBase;
143  delete firstBase;
144  delete secondTree;
145  delete firstTree;
146 }
147 
148 void test_expression_comparison::test_specific_activation_reversible()
149 {
150  // latex expression 1
151  // \frac{\(Vf*\frac{substrate}{Kms}-Vr*\frac{product}{Kmp}\)*Activator}{Ka+\(1+\frac{substrate}{Kms}+\frac{product}{Kmp}\)*Activator}
152  std::string infix1("(Vf*substrate/Kms-Vr*product/Kmp)*Activator/(Ka+(1+substrate/Kms+product/Kmp)*Activator)");
153  // latex expression 2
154  // \frac{K_{mp}*V_{f}*substrate-K_{ms}*V_{r}*product}{Activator^{-1}*K_{a}*K_{ms}*K_{mp}+K_{ms}*K_{mp}+K_{mp}*substrate+K_{ms}*product}
155  std::string infix2("(Kmp*Vf*substrate-Kms*Vr*product)/(Activator^(-1)*Ka*Kms*Kmp+Kms*Kmp+Kmp*substrate+Kms*product)");
156  CEvaluationTree* firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
157  firstTree->setInfix(infix1);
158  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
159  CEvaluationTree* secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
160  secondTree->setInfix(infix2);
161  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
162  CNormalBase * firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
163  CPPUNIT_ASSERT(firstBase != NULL);
164  CNormalFraction* firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
165  CPPUNIT_ASSERT(firstFraction != NULL);
166  CNormalBase * secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
167  CPPUNIT_ASSERT(secondBase != NULL);
168  CNormalFraction* secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
169  CPPUNIT_ASSERT(secondFraction != NULL);
170  CPPUNIT_ASSERT(*firstFraction == *secondFraction);
171  delete secondBase;
172  delete firstBase;
173  delete secondTree;
174  delete firstTree;
175 }
176 
177 void test_expression_comparison::test_ordered_bi_bi()
178 {
179  // latex expression 1
180  // \frac{Vf*\(substratea*substrateb-\frac{productp*productq}{Keq}\)}/{substratea*substrateb*\(1+\frac{productp}{Kip}\)+Kma*substrateb+Kmb*\(substratea+Kia\)+\frac{Vf}{Vr*Keq}*\(Kmq*productp*\(1+\frac{substratea}{Kia}\)+productq*\(Kmp*\(1+\frac{Kia*substrateb}{Kma*Kmb}\)+productp*\(1+\frac{substrateb}{Kib}\)\)\)}
181  std::string infix1("Vf*(substratea*substrateb-productp*productq/Keq)/(substratea*substrateb*(1+productp/Kip)+Kma*substrateb+Kmb*(substratea+Kia)+Vf/(Vr*Keq)*(Kmq*productp*(1+substratea/Kia)+productq*(Kmp*(1+Kia*substrateb/(Kma*Kmb))+productp*(1+substrateb/Kib))))");
182  // latex expression 2
183  // \frac{Vf*\left(productp^{-1}*productq^{-1}-substratea^{-1}*substrateb^{-1}*Keq^{-1}\right)}{productq^{-1}*\left(productp^{-1}+Kip^{-1}\right)+Kma*substratea^{-1}*productp^{-1}*productq^{-1}+productp^{-1}*productq^{-1}*Kmb*substrateb^{-1}*\left(1+Kia*substratea^{-1}\right)+\frac{Vf}{Vr*Keq}*\left(Kmq*productq^{-1}*substrateb^{-1}*(substratea^{-1}+\frac{1}{Kia})+Kmp*productp^{-1}*substratea^{-1}*\left(substrateb^{-1}+\frac{Kia}{Kma*Kmb}\right)+substratea^{-1}*(substrateb^{-1}+\frac{1}{Kib}\right)}
184  std::string infix2("Vf*(productp^(-1)*productq^(-1)-substratea^(-1)*substrateb^(-1)*Keq^(-1))/(productq^(-1)*(productp^(-1)+Kip^(-1))+Kma*substratea^(-1)*productp^(-1)*productq^(-1)+productp^(-1)*productq^(-1)*Kmb*substrateb^(-1)*(1+Kia*substratea^(-1))+Vf/(Vr*Keq)*(Kmq*productq^(-1)*substrateb^(-1)*(substratea^(-1)+1/Kia)+Kmp*productp^(-1)*substratea^(-1)*(substrateb^(-1)+Kia/(Kma*Kmb))+substratea^(-1)*(substrateb^(-1)+1/Kib)))");
185  CEvaluationTree* firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
186  firstTree->setInfix(infix1);
187  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
188  CEvaluationTree* secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
189  secondTree->setInfix(infix2);
190  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
191  CNormalBase * firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
192  CPPUNIT_ASSERT(firstBase != NULL);
193  CNormalFraction* firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
194  CPPUNIT_ASSERT(firstFraction != NULL);
195  CNormalBase * secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
196  CPPUNIT_ASSERT(secondBase != NULL);
197  CNormalFraction* secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
198  CPPUNIT_ASSERT(secondFraction != NULL);
199  CPPUNIT_ASSERT(*firstFraction == *secondFraction);
200  delete secondBase;
201  delete firstBase;
202  delete secondTree;
203  delete firstTree;
204 }
205 
206 void test_expression_comparison::test_reversible_hill()
207 {
208  try
209  {
210  //std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
211  //std::cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN\"" << std::endl;
212  //std::cout << "\"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd\" [" << std::endl;
213  //std::cout << "<!ENTITY mathml \"http://www.w3.org/1998/Math/MathML\">" << std::endl;
214  //std::cout << "]>" << std::endl;
215  //std::cout << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<header></header>\n<body>" << std::endl;
216  // latex expression 1
217  // \frac{Vf*\frac{substrate}{Shalve}*\(1-\frac{product}{substrate*Keq}\)*\(\frac{substrate}{Shalve}+\frac{product}{Phalve}\)^{h-1}}{1+(\frac{substrate}{Shalve}+\frac{product}{Phalve})^{h}}
218  std::string infix_numerator1 = "Vf*substrate/Shalve*(1-product/(substrate*Keq))*(substrate/Shalve+product/Phalve)^(h-1)";
219  // Test with a simpler version
220  std::string infix_denominator1 = "(1+(substrate/Shalve+product/Phalve)^h)";
221  std::string infix1("Vf*substrate/Shalve*(1-product/(substrate*Keq))*(substrate/Shalve+product/Phalve)^(h-1)/(1+(substrate/Shalve+product/Phalve)^h)");
222  // latex expression 2
223  // \frac{(substrate*Phalve+product*Shalve)^{h-1}*\frac{Vf}{Shalve}*(substrate-Keq^{-1}*product)}{Phalve^{h-1}*Shalve^{h-1}+\frac{(substrate*Phalve+product*Shalve)^{h}}{Shalve*Phalve}}
224 
225  std::string infix_numerator2 = "((substrate*Phalve+product*Shalve)^(h-1)*Vf/Shalve*(substrate-Keq^(-1)*product))";
226  std::string infix_denominator2 = "(Phalve^(h-1)*Shalve^(h-1)+(substrate*Phalve+product*Shalve)^h/(Shalve*Phalve))";
227  std::string infix2("((substrate*Phalve+product*Shalve)^(h-1)*Vf/Shalve*(substrate-Keq^(-1)*product))/(Phalve^(h-1)*Shalve^(h-1)+(substrate*Phalve+product*Shalve)^h/(Shalve*Phalve))");
228  //std::string infix1("Vf*substrate/Shalve*(1-product/(substrate*Keq))*(substrate/Shalve+product/Phalve)^(5-1)/(1+(substrate/Shalve+product/Phalve)^5)");
229  //std::string infix2("(substrate*Phalve+product*Shalve)^(5-1)*Vf/Shalve*(substrate-Keq^(-1)*product)/(Phalve^(5-1)*Shalve^(5-1)+(substrate*Phalve+product*Shalve)^5/(Shalve*Phalve))");
230 
231 
232  // numerators
233  CEvaluationTree* firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
234  firstTree->setInfix(infix_numerator1);
235  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
236  CEvaluationTree* secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
237  secondTree->setInfix(infix_numerator2);
238  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
239  //std::cout << "<p>Normalizing first tree.</p>" << std::endl;
240  CNormalBase * firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
241  CPPUNIT_ASSERT(firstBase != NULL);
242  CNormalFraction* firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
243  CPPUNIT_ASSERT(firstFraction != NULL);
244  std::string s1 = firstFraction->toString();
245  // I do seem to get the expected term below
246  //((-1) * Phalve * Vf * product * (Phalve * substrate + Shalve * product)^(h) + Keq * Phalve * Vf * substrate * (Phalve * substrate + Shalve * product)^(h))/(Keq * Phalve * substrate * (Phalve)^(h) * (Shalve)^(h) + Keq * Shalve * product * (Phalve)^(h) * (Shalve)^(h))
247  //std::cout << "numerator 1: " << s1 << std::endl;
248  //std::cout << "<p>Normalizing second tree.</p>" << std::endl;
249  CNormalBase * secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
250  CPPUNIT_ASSERT(secondBase != NULL);
251  CNormalFraction* secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
252  CPPUNIT_ASSERT(secondFraction != NULL);
253  std::string s2 = secondFraction->toString();
254  // the normalization of the numerator leads to the same result I got when I did it manually
255  // "((-1) * Vf * product * (Phalve * substrate + Shalve * product)^(h) + Keq * Vf * substrate * (Phalve * substrate + Shalve * product)^(h))/(Keq * Phalve * Shalve * substrate + Keq * Shalve^2 * product)"
256  //std::cout << "numerator 2: " << s2 << std::endl;
257 
258  // denominator
259  delete secondBase;
260  delete firstBase;
261  delete firstTree;
262  firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
263  firstTree->setInfix(infix_denominator1);
264  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
265  delete secondTree;
266  secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
267  secondTree->setInfix(infix_denominator2);
268  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
269  //std::cout << "<p>Normalizing first tree.</p>" << std::endl;
270  firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
271  CPPUNIT_ASSERT(firstBase != NULL);
272  firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
273  CPPUNIT_ASSERT(firstFraction != NULL);
274  s1 = firstFraction->toString();
275  // the results of the normalization of the first denominator is the same I get when I do it manually
276  // "((Phalve)^(h) * (Shalve)^(h) + (Phalve * substrate + Shalve * product)^(h))/((Phalve)^(h) * (Shalve)^(h))"
277  //std::cout << "denominator 1: " << s1 << std::endl;
278  //std::cout << "<p>Normalizing second tree.</p>" << std::endl;
279  secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
280  CPPUNIT_ASSERT(secondBase != NULL);
281  secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
282  CPPUNIT_ASSERT(secondFraction != NULL);
283  s2 = secondFraction->toString();
284  // the results of the normalization of the second denominator is the same I get when I do it manually
285  // "((Phalve)^(h) * (Shalve)^(h) + (Phalve * substrate + Shalve * product)^(h))/(Phalve * Shalve)"
286  //std::cout << "denominator 2: " << s2 << std::endl;
287 
288  // complete infix
289  delete secondBase;
290  delete firstBase;
291  delete firstTree;
292  firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
293  firstTree->setInfix(infix1);
294  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
295  delete secondTree;
296  secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
297  secondTree->setInfix(infix2);
298  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
299  //std::cout << "<p>Normalizing first tree.</p>" << std::endl;
300  firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
301  CPPUNIT_ASSERT(firstBase != NULL);
302  firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
303  CPPUNIT_ASSERT(firstFraction != NULL);
304  s1 = firstFraction->toString();
305  //std::cout << "infix 1: " << s1 << std::endl;
306  //std::cout << "<p>Normalizing second tree.</p>" << std::endl;
307  secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
308  CPPUNIT_ASSERT(secondBase != NULL);
309  secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
310  CPPUNIT_ASSERT(secondFraction != NULL);
311  s2 = secondFraction->toString();
312  //std::cout << "infix 2: " << s2 << std::endl;
313  //std::cout << "<p>first: " << std::endl;
314  //std::cout << "first: " << *firstFraction << std::endl;
315  //std::cout << "<p>second: " << std::endl;
316  //std::cout << "second: " << *secondFraction << std::endl;
317  //std::cout << "</body>\n</html>" << std::endl;
318 
319  // this is probably one of the cases where the normalization of two
320  // equivalent equations does not lead to the same normalform.
321  // At least not when I tried to do it manually.
322  //CPPUNIT_ASSERT(*firstFraction == *secondFraction);
323  delete secondBase;
324  delete firstBase;
325  delete secondTree;
326  delete firstTree;
327  }
328  catch (CCopasiException cce)
329  {
330  std::cout << "CopasiException " << std::endl;
331  }
332 }
333 
334 void test_expression_comparison::test_reversible_hill_one_modifier()
335 {
336  // latex expression 1
337  // \frac{Vf*\frac{substrate}{Shalve}*\(1-\frac{product}{substrate*Keq}\)*(\frac{substrate}{Shalve}+\frac{product}{Phalve})^{h-1}}{\frac{1+\(\frac{Modifier}{Mhalve}\)^h}/{1+alpha*\(\frac{Modifier}{Mhalve}\)^h}+\(\frac{substrate}{Shalve}+\frac{product}{Phalve}\)^h}
338  std::string infix1("Vf*substrate/Shalve*(1-product/(substrate*Keq))*(substrate/Shalve+product/Phalve)^(h-1)/((1+(Modifier/Mhalve)^h)/(1+alpha*(Modifier/Mhalve)^h)+(substrate/Shalve+product/Phalve)^h)");
339  // latex expression 2
340  // \frac{Vf*Shalve^{-1}*(substrate-Keq^{-1}*product)*(Shalve^{-1}*substrate+Phalve^{-1}*product)^{h-1}}{\frac{Modifier^{h}+Mhalve^{h}}{alpha*Modifier^{h}+Mhalve^{h}}+(Shalve^{-1}*substrate+Phalve^{-1}*product)^{h}}
341  std::string infix2("(Vf*Shalve^(-1)*(substrate-Keq^(-1)*product)*(Shalve^(-1)*substrate+Phalve^(-1)*product)^(h-1))/((Modifier^h+Mhalve^h)/(alpha*Modifier^h+Mhalve^h)+(Shalve^(-1)*substrate+Phalve^(-1)*product)^h)");
342  CEvaluationTree* firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
343  firstTree->setInfix(infix1);
344  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
345  CEvaluationTree* secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
346  secondTree->setInfix(infix2);
347  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
348  CNormalBase * firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
349  CPPUNIT_ASSERT(firstBase != NULL);
350  CNormalFraction* firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
351  CPPUNIT_ASSERT(firstFraction != NULL);
352  CNormalBase * secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
353  CPPUNIT_ASSERT(secondBase != NULL);
354  CNormalFraction* secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
355  CPPUNIT_ASSERT(secondFraction != NULL);
356  //CPPUNIT_ASSERT(*firstFraction == *secondFraction);
357  delete secondBase;
358  delete firstBase;
359  delete secondTree;
360  delete firstTree;
361 }
362 
363 void test_expression_comparison::test_reversible_hill_two_modifiers()
364 {
365  // latex expression 1
366  // \frac{Vf*\frac{substrate}{Shalve}*\(1-\frac{product}{substrate*Keq}\)*\(\frac{substrate}{Shalve}+\frac{product}{Phalve}\)^{h-1}}{\frac{1+\(\frac{ModifierA}{MAhalve}\)^{h}+\(\frac{ModifierB}{MBhalve}\)^{h}}{1+alphaA*\(\frac{ModifierA}{MAhalve}\)^{h}+alphaB*\(\frac{ModifierB}{MBhalve}\)^{h}+alphaA*alphaB*alphaAB*\(\frac{ModifierA}{MAhalve}\)^{h}*\(\frac{ModifierB}{MBhalve}\)^{h}}+\(\frac{substrate}{Shalve}+\frac{product}{Phalve}\)^{h}}
367  std::string infix1("Vf*substrate/Shalve*(1-product/(substrate*Keq))*(substrate/Shalve+product/Phalve)^(h-1)/((1+(ModifierA/MAhalve)^h+(ModifierB/MBhalve)^h)/(1+alphaA*(ModifierA/MAhalve)^h+alphaB*(ModifierB/MBhalve)^h+alphaA*alphaB*alphaAB*(ModifierA/MAhalve)^h*(ModifierB/MBhalve)^h)+(substrate/Shalve+product/Phalve)^h)");
368  // latex expression 2
369  // \frac{Shalve^{-1}*Vf*\(substrate-Keq^{-1}*product\)*(Shalve^{-1}*substrate+Phalve^{-1}*product)^{h-1}}{\frac{MAhalve^{h}*MBhalve^{h}+ModifierA^{h}*MBhalve^{h}+ModifierB^{h}*MAhalve^{h}}{MAhalve^{h}*MBhalve^{h}+alphaA*ModifierA^{h}*MBhalve^{h}+alphaB*ModifierB^{h}*MAhalve^{h}+alphaA*alphaB*alphaAB*ModifierA^{h}*ModifierB^{h}}+\(Shalve^{-1}*substrate+Phalve^{-1}*product\)^{h}}
370  std::string infix2("Shalve^(-1)*Vf*(substrate-Keq^(-1)*product)*(Shalve^(-1)*substrate+Phalve^(-1)*product)^(h-1)/((MAhalve^h*MBhalve^h+ModifierA^h*MBhalve^h+ModifierB^h*MAhalve^h)/(MAhalve^h*MBhalve^h+alphaA*ModifierA^h*MBhalve^h+alphaB*ModifierB^h*MAhalve^h+alphaA*alphaB*alphaAB*ModifierA^h*ModifierB^h)+(Shalve^(-1)*substrate+Phalve^(-1)*product)^h)");
371  CEvaluationTree* firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
372  firstTree->setInfix(infix1);
373  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
374  CEvaluationTree* secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
375  secondTree->setInfix(infix2);
376  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
377  CNormalBase * firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
378  CPPUNIT_ASSERT(firstBase != NULL);
379  CNormalFraction* firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
380  CPPUNIT_ASSERT(firstFraction != NULL);
381  std::string s1 = firstFraction->toString();
382  CNormalBase * secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
383  CPPUNIT_ASSERT(secondBase != NULL);
384  CNormalFraction* secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
385  CPPUNIT_ASSERT(secondFraction != NULL);
386  std::string s2 = secondFraction->toString();
387  //CPPUNIT_ASSERT(*firstFraction == *secondFraction);
388  delete secondBase;
389  delete firstBase;
390  delete secondTree;
391  delete firstTree;
392 }
393 
394 bool test_expression_comparison::are_expressions_equal(const std::string& expr1, const std::string& expr2, const std::string& /*filename*/, bool oldStyle)
395 {
396  bool result = false;
397 
398  //std::ofstream file(filename.c_str(),std::ios_base::out|std::ios_base::trunc);
399  //std::streambuf* sbuf = std::cout.rdbuf();
400  //std::cout.rdbuf(file.rdbuf());
401  try
402  {
403  //std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
404  //std::cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN\"" << std::endl;
405  //std::cout << "\"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd\" [" << std::endl;
406  //std::cout << "<!ENTITY mathml \"http://www.w3.org/1998/Math/MathML\">" << std::endl;
407  //std::cout << "]>" << std::endl;
408  //std::cout << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<header></header>\n<body>" << std::endl;
409  CEvaluationTree* firstTree = new CEvaluationTree("first tree", NULL, CEvaluationTree::Function);
410  firstTree->setInfix(expr1);
411  CPPUNIT_ASSERT(firstTree->getRoot() != NULL);
412  CEvaluationTree* secondTree = new CEvaluationTree("second tree", NULL, CEvaluationTree::Function);
413  secondTree->setInfix(expr2);
414  CPPUNIT_ASSERT(secondTree->getRoot() != NULL);
415  //std::cout << "<p>Normalizing first tree.</p>" << std::endl;
416  CNormalBase * firstBase = NULL;
417 
418  if (oldStyle == true)
419  {
420  firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree));
421  }
422  else
423  {
424  firstBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(firstTree->getRoot()));
425  }
426 
427  CPPUNIT_ASSERT(firstBase != NULL);
428  CNormalFraction* firstFraction = dynamic_cast<CNormalFraction*>(firstBase);
429  CPPUNIT_ASSERT(firstFraction != NULL);
430  //std::cout << "<p>Normalizing second tree.</p>" << std::endl;
431  CNormalBase * secondBase = NULL;
432 
433  if (oldStyle == true)
434  {
435  secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree));
436  }
437  else
438  {
439  secondBase = dynamic_cast<CNormalFraction*>(CNormalTranslation::normAndSimplifyReptdly(secondTree->getRoot()));
440  }
441 
442  CPPUNIT_ASSERT(secondBase != NULL);
443  CNormalFraction* secondFraction = dynamic_cast<CNormalFraction*>(secondBase);
444  CPPUNIT_ASSERT(secondFraction != NULL);
445  //std::cout << "<p>first: " << std::endl;
446  //std::cout << *firstFraction << "</p>" << std::endl;
447  //std::cout << "<p>second: " << std::endl;
448  //std::cout << *secondFraction << "</p>" << std::endl;
449  //std::cout << "</body>\n</html>" << std::endl;
450  result = (*firstFraction == *secondFraction);
451  delete secondBase;
452  delete firstBase;
453  delete secondTree;
454  delete firstTree;
455  }
456  catch (CCopasiException cce)
457  {
458  std::cout << "CopasiException " << std::endl;
459  }
460 
461  //file.close();
462  //std::cout.rdbuf(sbuf);
463  return result;
464 }
465 
466 void test_expression_comparison::test_fraction_to_a_power()
467 {
468  std::string expr1("(A/B+C/D)^E");
469  std::string expr2("(C/D+A/B)^E");
470  bool result = are_expressions_equal(expr1, expr2, "are_expressions_equal.xhtml", false);
471  CPPUNIT_ASSERT(result == true);
472 }
static CNormalFraction * normAndSimplifyReptdly(const CEvaluationTree *tree0, unsigned int depth=0)
virtual std::string toString() const
static void init(int argc, char *argv[], const bool &withGui=false)
CEvaluationNode * getRoot()
virtual bool setInfix(const std::string &infix)