Skip to content

Commit

Permalink
committing while I have hard drive issues
Browse files Browse the repository at this point in the history
  • Loading branch information
skeating committed Dec 15, 2024
1 parent e11fd97 commit 07dec3f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 113 deletions.
184 changes: 79 additions & 105 deletions src/sbml/conversion/ExpressionAnalyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,12 @@ bool ExpressionAnalyser::expressionExists(SubstitutionValues_t* current,
{
bool alreadyExists = false;
// all expressions will have K and X
alreadyExists = matchesK(current, mightAdd) &&
alreadyExists = matchesType(current, mightAdd) &&
matchesK(current, mightAdd) &&
matchesXValue(current, mightAdd) &&
matchesDxdtExpression(current, mightAdd);

if (alreadyExists && current->type == mightAdd->type)
if (alreadyExists)
{
switch (current->type)
{
Expand All @@ -334,106 +335,62 @@ bool ExpressionAnalyser::expressionExists(SubstitutionValues_t* current,
return alreadyExists;
}

//switch (current->type)
//{
//case TYPE_K_MINUS_X_MINUS_Y:
// switch (mightAdd->type)
// {
// case TYPE_K_MINUS_X_MINUS_Y:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesXValue(current, mightAdd) &&
// matchesYValue(current, mightAdd) &&
// matchesDxdtExpression(current, mightAdd) &&
// matchesDydtExpression(current, mightAdd) ;
// break;
// case TYPE_K_PLUS_V_MINUS_X_MINUS_Y:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesVExpression(current, mightAdd) &&
// matchesXValue(current, mightAdd) &&
// matchesYValue(current, mightAdd);
// break;
// case TYPE_K_MINUS_X_PLUS_W_MINUS_Y:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesWExpression(current, mightAdd) &&
// matchesXValue(current, mightAdd) &&
// matchesYValue(current, mightAdd);
// break;
// case TYPE_K_MINUS_X:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesXValue(current, mightAdd) &&
// matchesDxdtExpression(current, mightAdd);
// break;
// case TYPE_K_PLUS_V_MINUS_X:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesVExpression(current, mightAdd) &&
// matchesXValue(current, mightAdd);
// break;
// default:
// break;
// }
// break;
//case TYPE_K_PLUS_V_MINUS_X_MINUS_Y:
// switch (mightAdd->type)
// { // if we already have k+v-x-y then we need to record that we have k-x-y as well
// // so we only record a match value if one of the values doesn't match
// case TYPE_K_MINUS_X_MINUS_Y:
// alreadyExists = !matchesKValue(current, mightAdd) ||
// !matchesXValue(current, mightAdd) ||
// !matchesYValue(current, mightAdd) ||
// !matchesDxdtExpression(current, mightAdd) ||
// !matchesDydtExpression(current, mightAdd);
// break;
// case TYPE_K_PLUS_V_MINUS_X_MINUS_Y:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesVExpression(current, mightAdd) &&
// matchesXValue(current, mightAdd) &&
// matchesYValue(current, mightAdd);
// break;
// case TYPE_K_MINUS_X_PLUS_W_MINUS_Y:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesWExpression(current, mightAdd) &&
// matchesXValue(current, mightAdd) &&
// matchesYValue(current, mightAdd);
// break;
// case TYPE_K_MINUS_X:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesXValue(current, mightAdd) &&
// matchesDxdtExpression(current, mightAdd);
// break;
// case TYPE_K_PLUS_V_MINUS_X:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesXValue(current, mightAdd) &&
// matchesDxdtExpression(current, mightAdd);
// break;
// default:
// break;
// }
// break;
//case TYPE_K_MINUS_X_PLUS_W_MINUS_Y:
// printSubstitutionValues(current);
// printSubstitutionValues(mightAdd);
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesWExpression(current, mightAdd) &&
// matchesXValue(current, mightAdd) &&
// matchesDxdtExpression(current, mightAdd) &&
// matchesYValue(current, mightAdd) &&
// matchesDydtExpression(current, mightAdd);
// break;
//case TYPE_K_MINUS_X:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesXValue(current, mightAdd);
// break;
//case TYPE_K_PLUS_V_MINUS_X:
// alreadyExists = matchesKValue(current, mightAdd) &&
// matchesVExpression(current, mightAdd) &&
// matchesXValue(current, mightAdd);
// break;
//default:
// break;
//}

return alreadyExists;
}
}
bool ExpressionAnalyser::parentExpressionExists(SubstitutionValues_t* current, SubstitutionValues_t* mightAdd)
{
bool parentExists = false;
// here we want to find out if the expression is actually a child of another
// and therefore need not be logged
// all expressions will have K and X but the type may not be the same
parentExists = matchesK(current, mightAdd) &&
matchesXValue(current, mightAdd) &&
matchesDxdtExpression(current, mightAdd);

if (parentExists)
{
switch (current->type)
{
case TYPE_K_MINUS_X_MINUS_Y:
parentExists = parentExists && mightAdd->type == TYPE_K_MINUS_X;
break;
case TYPE_K_PLUS_V_MINUS_X_MINUS_Y:
switch (mightAdd->type)
{
case TYPE_K_PLUS_V_MINUS_X:
parentExists = parentExists && matchesVExpression(current, mightAdd);
break;
case TYPE_K_MINUS_X:
parentExists = true;
break;
default:
parentExists = false;
break;
}
break;
case TYPE_K_MINUS_X_PLUS_W_MINUS_Y:
switch (mightAdd->type)
{
case TYPE_K_MINUS_X:
parentExists = true;
break;
case TYPE_K_MINUS_X_MINUS_Y:
parentExists = parentExists && matchesYValue(current, mightAdd);
break;
default:
parentExists = false;
break;
}
break;
default:
break;
}
return parentExists;
}

return parentExists;
}


bool ExpressionAnalyser::matchesK(SubstitutionValues_t* values1, SubstitutionValues_t* values2)
{
Expand Down Expand Up @@ -491,6 +448,11 @@ bool ExpressionAnalyser::matchesCurrentNode(SubstitutionValues_t* values1, Subst
values1->current->exactlyEqual(*(values2->current)) == true);
}

bool ExpressionAnalyser::matchesType(SubstitutionValues_t* values1, SubstitutionValues_t* values2)
{
return values1->type == values2->type;
}


void
ExpressionAnalyser::printSubstitutionValues(const SubstitutionValues_t* values)
Expand Down Expand Up @@ -568,23 +530,35 @@ SubstitutionValues_t* ExpressionAnalyser::getExpression(unsigned int index)
* e.g. if we have k-x-y do not need to analyse k-x
*/
bool
ExpressionAnalyser::hasExpressionAlreadyBeenRecorded(SubstitutionValues_t* value)
ExpressionAnalyser::shouldAddExpression(SubstitutionValues_t* value)
{
bool found = false;
bool foundParent = false;
size_t size = mExpressions.size();

while (size > 0 && !found)
{
found = expressionExists(mExpressions.at(size - 1), value);
size--;
}
return found ;
if (!found)
{
size = mExpressions.size();
while (size > 0 && !foundParent)
{
foundParent = parentExpressionExists(mExpressions.at(size - 1), value);
size--;
}

}
return !found && !foundParent;
}


bool
ExpressionAnalyser::analyseNode(ASTNode* node, SubstitutionValues_t *value)
{
cout << "current node: " << SBML_formulaToL3String(node) << endl;
unsigned int numChildren = node->getNumChildren();
ASTNodeType_t type = node->getType();
ASTNode* rightChild = node->getRightChild();
Expand Down Expand Up @@ -674,7 +648,7 @@ ExpressionAnalyser::detect_minusXPlusYOnly()
value->type = TYPE_MINUS_X_PLUS_Y;
value->current = currentNode;
value->odeIndex = odeIndex;
if (!hasExpressionAlreadyBeenRecorded(value))
if (!shouldAddExpression(value))
{
printSubstitutionValues(value);
mExpressions.push_back(value);
Expand Down Expand Up @@ -707,7 +681,7 @@ ExpressionAnalyser::analyse(bool minusXPlusYOnly)
if (analyseNode(currentNode, value))
{
value->odeIndex = odeIndex;
if (hasExpressionAlreadyBeenRecorded(value) == false)
if (shouldAddExpression(value))
{
//printSubstitutionValues(value);
mExpressions.push_back(value);
Expand Down
9 changes: 6 additions & 3 deletions src/sbml/conversion/ExpressionAnalyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ class LIBSBML_EXTERN ExpressionAnalyser
void printSubstitutionValues(const SubstitutionValues_t* values1);
bool areIdenticalSubstitutionValues(SubstitutionValues_t* values1, SubstitutionValues_t* values2);

bool expressionExists(SubstitutionValues_t* values1, SubstitutionValues_t* values2);

void substituteParametersForExpressions(List* hiddenSpecies);

/*
Expand All @@ -197,6 +195,7 @@ class LIBSBML_EXTERN ExpressionAnalyser
bool matchesDxdtExpression(SubstitutionValues_t* values1, SubstitutionValues_t* values2);
bool matchesDydtExpression(SubstitutionValues_t* values1, SubstitutionValues_t* values2);
bool matchesCurrentNode(SubstitutionValues_t* values1, SubstitutionValues_t* values2);
bool matchesType(SubstitutionValues_t* values1, SubstitutionValues_t* values2);


void substituteParameters(List* hiddenSpecies, SubstitutionValues_t* values);
Expand Down Expand Up @@ -237,7 +236,11 @@ class LIBSBML_EXTERN ExpressionAnalyser
/*
* Loops through expressions already recorded and checks for exact matches
*/
bool hasExpressionAlreadyBeenRecorded(SubstitutionValues_t* value);
bool shouldAddExpression(SubstitutionValues_t* value);

bool expressionExists(SubstitutionValues_t* current, SubstitutionValues_t* mightAdd);

bool parentExpressionExists(SubstitutionValues_t* current, SubstitutionValues_t* mightAdd);

/**
* Searches for a node's parent and its index as the parent's child in a one-directional tree (nodes know their children, but not their parent).
Expand Down
11 changes: 6 additions & 5 deletions src/sbml/conversion/test/TestExpressionAnalyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,16 @@ START_TEST(test_analyse_different_expression)
SubstitutionValues_t* value = analyser->getExpression(1);
fail_unless(value->k_value == "k");
fail_unless(value->x_value == "x");
fail_unless(value->y_value == "c");
fail_unless(value->y_value == "a");
fail_unless(value->z_value.empty());
fail_unless(value->type == TYPE_K_MINUS_X_MINUS_Y);
fail_unless(formulas_equal("k - x - c", value->current));
fail_unless(formulas_equal("k - x - a", value->current));
fail_unless(formulas_equal("0", value->dxdt_expression));
fail_unless(formulas_equal("0", value->dydt_expression));
fail_unless(formulas_equal("k - x - y", value->dydt_expression));
fail_unless(value->v_expression == NULL);
fail_unless(value->w_expression == NULL);
fail_unless(value->z_expression == NULL);
fail_unless(value->odeIndex == 0);
fail_unless(value->odeIndex == 1);
fail_unless(util_isNaN(value->k_real_value));
}
END_TEST
Expand Down Expand Up @@ -598,7 +598,7 @@ END_TEST
Suite *
create_suite_TestExpressionAnalyser (void)
{
bool testing = true;
bool testing = false;
Suite *suite = suite_create("ExpressionAnalyser");
TCase *tcase = tcase_create("ExpressionAnalyser");
tcase_add_checked_fixture(tcase,
Expand All @@ -616,6 +616,7 @@ Suite *suite = suite_create("ExpressionAnalyser");
tcase_add_test(tcase, test_analyse_3); //k-x
tcase_add_test(tcase, test_analyse_4); //k+v-x
tcase_add_test(tcase, test_analyse_same_expression); //k-x-y
tcase_add_test(tcase, test_analyse_different_expression); //k-x-y
//tcase_add_test(tcase, test_order_of_replacements);
//tcase_add_test(tcase, test_order_of_replacements1);
//tcase_add_test(tcase, test_order_of_replacements2);
Expand Down

0 comments on commit 07dec3f

Please sign in to comment.