Skip to content

Commit

Permalink
committing and hopefully I have turned off all build
Browse files Browse the repository at this point in the history
  • Loading branch information
skeating committed Dec 19, 2024
1 parent 07dec3f commit ac9fe51
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/brief.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CMake (rapid build on push)

on: [push]
on:

env:
BUILD_TYPE: Release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/matlab.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Matlab (ubuntu) build and test

on: [push]
on: []

env:
MATLAB_VERSION: R2021a
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/octave.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Octave

on: [push]
on:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down
3 changes: 2 additions & 1 deletion src/sbml/conversion/ExpressionAnalyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ ExpressionAnalyser::shouldAddExpression(SubstitutionValues_t* value)
bool
ExpressionAnalyser::analyseNode(ASTNode* node, SubstitutionValues_t *value)
{
cout << "current node: " << SBML_formulaToL3String(node) << endl;
// 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 @@ -678,6 +678,7 @@ ExpressionAnalyser::analyse(bool minusXPlusYOnly)
ASTNode* currentNode = (ASTNode*)*it;
SubstitutionValues_t* value = createBlankSubstitutionValues();

cout << "current node: " << SBML_formulaToL3String(currentNode) << endl;
if (analyseNode(currentNode, value))
{
value->odeIndex = odeIndex;
Expand Down
125 changes: 123 additions & 2 deletions src/sbml/conversion/test/TestExpressionAnalyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,124 @@ START_TEST(test_analyse_1)
fail_unless(util_isNaN(value->k_real_value));
}
END_TEST

START_TEST(test_analyse_1_same)
{
RateRule* rr = d->getModel()->createRateRule();
rr->setVariable("a");
rr->setMath(SBML_parseFormula("k + v - x - y"));
RateRule* rr1 = d->getModel()->createRateRule();
rr1->setVariable("b");
rr1->setMath(SBML_parseFormula("k + v - x - y"));

converter->populateInitialODEinfo();
ExpressionAnalyser* analyser = new ExpressionAnalyser(m, converter->getOdePairs());

fail_unless(analyser->getNumExpressions() == 0);

analyser->analyse();

fail_unless(analyser->getNumExpressions() == 1);
SubstitutionValues_t* value = analyser->getExpression(0);
fail_unless(value->k_value == "k");
fail_unless(value->x_value == "x");
fail_unless(value->y_value == "y");
fail_unless(value->z_value.empty());
fail_unless(value->type == TYPE_K_PLUS_V_MINUS_X_MINUS_Y);
fail_unless(formulas_equal("k + v - x - y", value->current));
fail_unless(formulas_equal("0", value->dxdt_expression));
fail_unless(formulas_equal("0", value->dydt_expression));
fail_unless(formulas_equal("v", value->v_expression));
fail_unless(value->w_expression == NULL);
fail_unless(value->z_expression == NULL);
fail_unless(value->odeIndex == 0);
fail_unless(util_isNaN(value->k_real_value));
}
END_TEST



START_TEST(test_analyse_1_two_terms)
{
RateRule* rr = d->getModel()->createRateRule();
rr->setVariable("a");
rr->setMath(SBML_parseFormula("(k + v - x - y) + (k - x)"));

converter->populateInitialODEinfo();
ExpressionAnalyser* analyser = new ExpressionAnalyser(m, converter->getOdePairs());

fail_unless(analyser->getNumExpressions() == 0);

analyser->analyse();

fail_unless(analyser->getNumExpressions() == 2);
SubstitutionValues_t* value = analyser->getExpression(0);
fail_unless(value->k_value == "k");
fail_unless(value->x_value == "x");
fail_unless(value->y_value == "y");
fail_unless(value->z_value.empty());
fail_unless(value->type == TYPE_K_PLUS_V_MINUS_X_MINUS_Y);
fail_unless(formulas_equal("k + v - x - y", value->current));
fail_unless(formulas_equal("0", value->dxdt_expression));
fail_unless(formulas_equal("0", value->dydt_expression));
fail_unless(formulas_equal("v", value->v_expression));
fail_unless(value->w_expression == NULL);
fail_unless(value->z_expression == NULL);
fail_unless(value->odeIndex == 0);
fail_unless(util_isNaN(value->k_real_value));

SubstitutionValues_t* value1 = analyser->getExpression(1);
fail_unless(value1->k_value == "k");
fail_unless(value1->x_value == "x");
fail_unless(value1->y_value.empty());
fail_unless(value1->z_value.empty());
fail_unless(value1->type == TYPE_K_MINUS_X);
fail_unless(formulas_equal("k - x", value1->current));
fail_unless(formulas_equal("0", value1->dxdt_expression));
fail_unless(value1->dydt_expression == NULL);
fail_unless(value1->v_expression == NULL);
fail_unless(value1->w_expression == NULL);
fail_unless(value1->z_expression == NULL);
fail_unless(value1->odeIndex == 0);
fail_unless(util_isNaN(value1->k_real_value));

}
END_TEST


START_TEST(test_analyse_1_different)
{
RateRule* rr = d->getModel()->createRateRule();
rr->setVariable("a");
rr->setMath(SBML_parseFormula("k + v - x - y"));
RateRule* rr1 = d->getModel()->createRateRule();
rr1->setVariable("b");
rr1->setMath(SBML_parseFormula("k + v - x - a"));
converter->populateInitialODEinfo();
ExpressionAnalyser* analyser = new ExpressionAnalyser(m, converter->getOdePairs());

fail_unless(analyser->getNumExpressions() == 0);

analyser->analyse();

fail_unless(analyser->getNumExpressions() == 2);
SubstitutionValues_t* value = analyser->getExpression(1);
fail_unless(value->k_value == "k");
fail_unless(value->x_value == "x");
fail_unless(value->y_value == "a");
fail_unless(value->z_value.empty());
fail_unless(value->type == TYPE_K_PLUS_V_MINUS_X_MINUS_Y);
fail_unless(formulas_equal("k + v - x - a", value->current));
fail_unless(formulas_equal("0", value->dxdt_expression));
fail_unless(formulas_equal("k + v - x - y", value->dydt_expression));
fail_unless(formulas_equal("v", value->v_expression));
fail_unless(value->w_expression == NULL);
fail_unless(value->z_expression == NULL);
fail_unless(value->odeIndex == 1);
fail_unless(util_isNaN(value->k_real_value));
}
END_TEST

START_TEST(test_analyse_2)
{
RateRule* rr = d->getModel()->createRateRule();
Expand Down Expand Up @@ -598,15 +716,15 @@ END_TEST
Suite *
create_suite_TestExpressionAnalyser (void)
{
bool testing = false;
bool testing = true;
Suite *suite = suite_create("ExpressionAnalyser");
TCase *tcase = tcase_create("ExpressionAnalyser");
tcase_add_checked_fixture(tcase,
ExpressionAnalyser_setup, ExpressionAnalyser_teardown);

if (testing)
{
tcase_add_test(tcase, test_analyse_different_expression);
tcase_add_test(tcase, test_analyse_1_two_terms);
}
else
{
Expand All @@ -617,6 +735,9 @@ Suite *suite = suite_create("ExpressionAnalyser");
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_analyse_1_same); //k+v-x-y
tcase_add_test(tcase, test_analyse_1_two_terms); //(k+v-x-y)+(k-x)
tcase_add_test(tcase, test_analyse_1_different); //k+v-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
3 changes: 3 additions & 0 deletions src/sbml/conversion/test/test-data/test
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,6 @@ reconstructModel
plus
return False
values: k x dx v type=k+v-x

hasExpressionAlreadyBeanRecorded
expressionExistsaround
40 changes: 38 additions & 2 deletions src/sbml/math/ASTNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,19 @@ ASTNode::getListOfNodes (ASTNodePredicate predicate) const
return lst;
}

LIBSBML_EXTERN
ASTNodeLevels
ASTNode::getListOfNodesWithLevel() const
{
ASTNodeLevels vector_pairs;


fillListOfNodesWithLevel((ASTNodePredicate)ASTNode_isOperator, vector_pairs, 0);
fillListOfNodesWithLevel((ASTNodePredicate)ASTNode_isName, vector_pairs, 0);

return vector_pairs;
}


/*
* This method is identical in functionality to getListOfNodes(), except
Expand All @@ -1145,8 +1158,6 @@ ASTNode::fillListOfNodes (ASTNodePredicate predicate, List* lst) const
unsigned int c;
unsigned int numChildren = getNumChildren();



if (predicate(this) != 0)
{
lst->add( const_cast<ASTNode*>(this) );
Expand All @@ -1159,6 +1170,31 @@ ASTNode::fillListOfNodes (ASTNodePredicate predicate, List* lst) const
}
}

void ASTNode::fillListOfNodesWithLevel(ASTNodePredicate predicate, ASTNodeLevels& vector_pairs, unsigned int level) const
{
if (this == NULL ||
(vector_pairs.size() == 1 && vector_pairs.back().second == NULL) ||
predicate == NULL)
return;

ASTNode* child;
unsigned int c;
unsigned int numChildren = getNumChildren();

if (predicate(this) != 0)
{
cout << "Level " << level << ": " << SBML_formulaToL3String(this) << endl;
vector_pairs.push_back(std::make_pair(level, (ASTNode*)this));
}

for (c = 0; c < numChildren; c++)
{
child = getChild(c);
child->fillListOfNodesWithLevel(predicate, vector_pairs, level + 1);
}

}


/*
* @return the value of this ASTNode as a single character. This function
Expand Down
15 changes: 14 additions & 1 deletion src/sbml/math/ASTNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,14 @@ typedef int (*ASTNodePredicate) (const ASTNode_t *node);
LIBSBML_CPP_NAMESPACE_END

#ifdef __cplusplus

LIBSBML_CPP_NAMESPACE_BEGIN

typedef std::pair<unsigned int, ASTNode*> ASTNodePair;
typedef std::vector<ASTNodePair> ASTNodeLevels;
typedef ASTNodeLevels::iterator ASTNodeLevelsIterator;



class List;
class ASTBasePlugin;
class ExtendedMathList;
Expand Down Expand Up @@ -604,6 +609,10 @@ int (*ASTNodePredicate) (const ASTNode *node);
List* getListOfNodes (ASTNodePredicate predicate) const;


LIBSBML_EXTERN
ASTNodeLevels getListOfNodesWithLevel () const;


/**
* Returns a list of nodes rooted at a given node and satisfying a given
* predicate.
Expand Down Expand Up @@ -635,6 +644,10 @@ int (*ASTNodePredicate) (const ASTNode_t *node);
LIBSBML_EXTERN
void fillListOfNodes (ASTNodePredicate predicate, List* lst) const;

LIBSBML_EXTERN
void fillListOfNodesWithLevel(ASTNodePredicate predicate, ASTNodeLevels& vector_pairs, unsigned int level) const;



/**
* Returns the value of this node as a single character.
Expand Down
Loading

0 comments on commit ac9fe51

Please sign in to comment.