/// <summary> /// /// </summary> /// <param name="anASTNode"></param> /// <returns></returns> private ASTNode convertVariableName(ASTNode anASTNode) { long aNumChildren = anASTNode.getNumChildren(); if ( aNumChildren == 2 ) { this.convertVariableName( anASTNode.getLeftChild() ); this.convertVariableName( anASTNode.getRightChild() ); return anASTNode; } else if ( aNumChildren == 1 ) { this.convertVariableName( anASTNode.getLeftChild() ); return anASTNode; } else if ( aNumChildren == 0 ) { if ( anASTNode.isNumber() ) { } else { string aName = anASTNode.getName(); string variableName = ""; // Check Species foreach(SpeciesStruct aSpecies in this.Model.SpeciesList) { if ( aSpecies.ID != aName && aSpecies.Name != aName) continue; // Check VariableReference foreach(VariableReferenceStruct aVariableReference in this.VariableReferenceList) if (aVariableReference.Variable.Split(':')[2] == aName) variableName = aVariableReference.Name; if (variableName == "") { string aModifierID = this.Model.getSpeciesReferenceID(aName); VariableReferenceStruct varRef = new VariableReferenceStruct( "C" + this.ModifierNumber.ToString(), "Variable:" + aModifierID, 0); this.VariableReferenceList.Add(varRef); variableName = varRef.Name; this.ModifierNumber++; } //string compartmentName = this.setCompartmentToVariableReference( aSpecies.Compartment ); //anASTNode.setType( libsbml.libsbml.AST_DIVIDE ); //anASTNode.addChild( new ASTNode( libsbml.libsbml.AST_NAME ) ); //anASTNode.addChild( new ASTNode( libsbml.libsbml.AST_NAME ) ); //anASTNode.getLeftChild().setName( variableName + ".Value" ); //anASTNode.getRightChild().setName( compartmentName + ".Value" ) ; anASTNode.setName(variableName + ".Value"); return anASTNode; } // Check Parameters. foreach(ParameterStruct aParameter in this.Model.ParameterList) { if (aParameter.ID != aName && aParameter.Name != aName) continue; foreach(VariableReferenceStruct aVariableReference in this.VariableReferenceList) if (aVariableReference.Variable.Split(':')[2] == aName) variableName = aVariableReference.Name; if( variableName == "" ) { VariableReferenceStruct varRef = new VariableReferenceStruct( aName, "Variable:/:" + aName, 0 ); this.VariableReferenceList.Add( varRef ); this.ParameterNumber++; variableName = varRef.Name; } anASTNode.setName( variableName + ".Value" ); return anASTNode; } // if variableName == '': variableName = this.setCompartmentToVariableReference( aName ); if (variableName != "") anASTNode.setName( variableName + ".Value" ); } } return anASTNode; }
public void test_ASTNode_no_children() { ASTNode node = new ASTNode(); assertTrue( node.getNumChildren() == 0 ); assertTrue( node.getLeftChild() == null ); assertTrue( node.getRightChild() == null ); assertTrue( node.getChild(0) == null ); node = null; }
public void test_ASTNode_one_child() { ASTNode node = new ASTNode(); ASTNode child = new ASTNode(); node.addChild(child); assertTrue( node.getNumChildren() == 1 ); assertTrue( node.getLeftChild() == child ); assertTrue( node.getRightChild() == null ); assertTrue( node.getChild(0) == child ); assertTrue( node.getChild(1) == null ); node = null; }
public void test_ASTNode_children() { ASTNode parent = new ASTNode(); ASTNode left = new ASTNode(); ASTNode right = new ASTNode(); ASTNode right2 = new ASTNode(); parent.setType(libsbml.AST_PLUS); left.setValue(1); right.setValue(2); right2.setValue(3); parent.addChild(left); parent.addChild(right); assertTrue( parent.getNumChildren() == 2 ); assertTrue( left.getNumChildren() == 0 ); assertTrue( right.getNumChildren() == 0 ); assertTrue( parent.getLeftChild() == left ); assertTrue( parent.getRightChild() == right ); assertTrue( parent.getChild(0) == left ); assertTrue( parent.getChild(1) == right ); assertTrue( parent.getChild(2) == null ); parent.addChild(right2); assertTrue( parent.getNumChildren() == 3 ); assertTrue( left.getNumChildren() == 0 ); assertTrue( right.getNumChildren() == 0 ); assertTrue( right2.getNumChildren() == 0 ); assertTrue( parent.getLeftChild() == left ); assertTrue( parent.getRightChild() == right2 ); assertTrue( parent.getChild(0) == left ); assertTrue( parent.getChild(1) == right ); assertTrue( parent.getChild(2) == right2 ); assertTrue( parent.getChild(3) == null ); parent = null; }
public void test_ASTNode_deepCopy_1() { ASTNode node = new ASTNode(); ASTNode child, copy; node.setCharacter( '+'); node.addChild(new ASTNode()); node.addChild(new ASTNode()); node.getLeftChild().setValue(1); node.getRightChild().setValue(2); assertTrue( node.getType() == libsbml.AST_PLUS ); assertTrue( node.getCharacter() == '+' ); assertTrue( node.getNumChildren() == 2 ); child = node.getLeftChild(); assertTrue( child.getType() == libsbml.AST_INTEGER ); assertTrue( child.getInteger() == 1 ); assertTrue( child.getNumChildren() == 0 ); child = node.getRightChild(); assertTrue( child.getType() == libsbml.AST_INTEGER ); assertTrue( child.getInteger() == 2 ); assertTrue( child.getNumChildren() == 0 ); copy = node.deepCopy(); assertTrue( copy != node ); assertTrue( copy.getType() == libsbml.AST_PLUS ); assertTrue( copy.getCharacter() == '+' ); assertTrue( copy.getNumChildren() == 2 ); child = copy.getLeftChild(); assertTrue( child != node.getLeftChild() ); assertTrue( child.getType() == libsbml.AST_INTEGER ); assertTrue( child.getInteger() == 1 ); assertTrue( child.getNumChildren() == 0 ); child = copy.getRightChild(); assertTrue( child != node.getRightChild() ); assertTrue( child.getType() == libsbml.AST_INTEGER ); assertTrue( child.getInteger() == 2 ); assertTrue( child.getNumChildren() == 0 ); node = null; copy = null; }
public void test_ASTNode_canonicalizeFunctionsL1() { ASTNode n = new ASTNode(libsbml.AST_FUNCTION); ASTNode c; n.setName( "acos"); assertTrue( n.getType() == libsbml.AST_FUNCTION ); n.canonicalize(); assertTrue( n.getType() == libsbml.AST_FUNCTION_ARCCOS ); n.setType(libsbml.AST_FUNCTION); n.setName( "asin"); assertTrue( n.getType() == libsbml.AST_FUNCTION ); n.canonicalize(); assertTrue( n.getType() == libsbml.AST_FUNCTION_ARCSIN ); n.setType(libsbml.AST_FUNCTION); n.setName( "atan"); assertTrue( n.getType() == libsbml.AST_FUNCTION ); n.canonicalize(); assertTrue( n.getType() == libsbml.AST_FUNCTION_ARCTAN ); n.setType(libsbml.AST_FUNCTION); n.setName( "ceil"); assertTrue( n.getType() == libsbml.AST_FUNCTION ); n.canonicalize(); assertTrue( n.getType() == libsbml.AST_FUNCTION_CEILING ); n.setType(libsbml.AST_FUNCTION); n.setName( "pow"); assertTrue( n.getType() == libsbml.AST_FUNCTION ); n.canonicalize(); assertTrue( n.getType() == libsbml.AST_FUNCTION_POWER ); n = null; n = new ASTNode(libsbml.AST_FUNCTION); n.setName( "log"); c = new ASTNode(); c.setName( "x"); n.addChild(c); assertTrue( n.getType() == libsbml.AST_FUNCTION ); assertTrue( n.getNumChildren() == 1 ); n.canonicalize(); assertTrue( n.getType() == libsbml.AST_FUNCTION_LN ); assertTrue( n.getNumChildren() == 1 ); n.setType(libsbml.AST_FUNCTION); c = new ASTNode(); c.setName( "y"); n.addChild(c); assertTrue( n.getType() == libsbml.AST_FUNCTION ); assertTrue( n.getNumChildren() == 2 ); n.canonicalize(); assertTrue( n.getType() == libsbml.AST_FUNCTION_LOG ); n = null; n = new ASTNode(libsbml.AST_FUNCTION); n.setName( "log10"); c = new ASTNode(); c.setName( "x"); n.addChild(c); assertTrue( n.getType() == libsbml.AST_FUNCTION ); assertTrue( n.getNumChildren() == 1 ); n.canonicalize(); assertTrue( n.getType() == libsbml.AST_FUNCTION_LOG ); assertTrue( n.getNumChildren() == 2 ); c = n.getLeftChild(); assertTrue( c.getType() == libsbml.AST_INTEGER ); assertTrue( c.getInteger() == 10 ); c = n.getRightChild(); assertTrue( c.getType() == libsbml.AST_NAME ); assertTrue(( "x" == c.getName() )); n = null; n = new ASTNode(libsbml.AST_FUNCTION); n.setName( "sqr"); c = new ASTNode(); c.setName( "x"); n.addChild(c); assertTrue( n.getType() == libsbml.AST_FUNCTION ); assertTrue( n.getNumChildren() == 1 ); n.canonicalize(); assertTrue( n.getType() == libsbml.AST_FUNCTION_POWER ); assertTrue( n.getNumChildren() == 2 ); c = n.getLeftChild(); assertTrue( c.getType() == libsbml.AST_NAME ); assertTrue(( "x" == c.getName() )); c = n.getRightChild(); assertTrue( c.getType() == libsbml.AST_INTEGER ); assertTrue( c.getInteger() == 2 ); n = null; n = new ASTNode(libsbml.AST_FUNCTION); n.setName( "sqrt"); c = new ASTNode(); c.setName( "x"); n.addChild(c); assertTrue( n.getType() == libsbml.AST_FUNCTION ); assertTrue( n.getNumChildren() == 1 ); n.canonicalize(); assertTrue( n.getType() == libsbml.AST_FUNCTION_ROOT ); assertTrue( n.getNumChildren() == 2 ); c = n.getLeftChild(); assertTrue( c.getType() == libsbml.AST_INTEGER ); assertTrue( c.getInteger() == 2 ); c = n.getRightChild(); assertTrue( c.getType() == libsbml.AST_NAME ); assertTrue(( "x" == c.getName() )); n = null; }
/// <summary> /// /// </summary> /// <param name="anASTNode"></param> /// <returns></returns> private ASTNode convertVariableName(ASTNode anASTNode) { long aNumChildren = anASTNode.getNumChildren(); if ( aNumChildren == 2 ) { this.convertVariableName( anASTNode.getLeftChild() ); this.convertVariableName( anASTNode.getRightChild() ); } else if ( aNumChildren == 1 ) { this.convertVariableName( anASTNode.getLeftChild() ); } else if ( aNumChildren == 0 ) { if ( anASTNode.isNumber() ) { } else { string aName = anASTNode.getName(); int aType = this.getVariableType( aName ); //# Species if ( aType == libsbml.libsbml.SBML_SPECIES ) { string variableName = this.setSpeciesToVariableReference( aName , 0); if( variableName != "" ) { anASTNode.setName( variableName + ".Value" ); return anASTNode; } } //# Parameter else if ( aType == libsbml.libsbml.SBML_PARAMETER ) { string variableName = this.setParameterToVariableReference( aName , 0); if( variableName != "" ) { anASTNode.setName( variableName + ".Value" ); return anASTNode; } } //# Compartment else if (aType == libsbml.libsbml.SBML_COMPARTMENT) { string variableName = this.setCompartmentToVariableReference(aName, 0); if( variableName != "" ) { anASTNode.setName( variableName + ".Value" ); return anASTNode; } } } } return anASTNode; }
public void test_element_bug_csymbol_delay_1() { string s = wrapMathML("<apply>" + " <csymbol encoding='text' definitionURL='http://www.sbml.org/sbml/" + "symbols/delay'> my_delay </csymbol>" + " <ci> x </ci>" + " <cn> 0.1 </cn>" + "</apply>\n"); N = libsbml.readMathMLFromString(s); assertTrue( N != null ); assertTrue( N.getType() == libsbml.AST_FUNCTION_DELAY ); assertTrue(( "my_delay" == N.getName() )); assertTrue( N.getNumChildren() == 2 ); ASTNode c = N.getLeftChild(); assertTrue( c != null ); assertTrue( c.getType() == libsbml.AST_NAME ); assertTrue(( "x" == c.getName() )); assertTrue( c.getNumChildren() == 0 ); c = N.getRightChild(); assertTrue( c != null ); assertTrue( c.getType() == libsbml.AST_REAL ); assertTrue( c.getReal() == 0.1 ); assertTrue( c.getNumChildren() == 0 ); }
public void test_element_bug_csymbol_1() { string s = wrapMathML("<apply>" + " <gt/>" + " <csymbol encoding='text' " + " definitionURL='http://www.sbml.org/sbml/symbols/time'>time</csymbol>" + " <cn>5000</cn>" + "</apply>"); N = libsbml.readMathMLFromString(s); assertTrue( N != null ); assertTrue( N.getType() == libsbml.AST_RELATIONAL_GT ); assertTrue( N.getNumChildren() == 2 ); ASTNode c = N.getLeftChild(); assertTrue( c != null ); assertTrue( c.getType() == libsbml.AST_NAME_TIME ); assertTrue(( "time" == c.getName() )); assertTrue( c.getNumChildren() == 0 ); c = N.getRightChild(); assertTrue( c != null ); assertTrue( c.getType() == libsbml.AST_REAL ); assertTrue( c.getReal() == 5000 ); assertTrue( c.getNumChildren() == 0 ); }
private static ASTNode setDelayType(ASTNode anASTNode) { long aNumChildren = anASTNode.getNumChildren(); if ( aNumChildren == 2 ) { if ( anASTNode.isFunction() == true && anASTNode.getName() == "delay" ) anASTNode.setType( libsbml.libsbml.AST_FUNCTION_DELAY ); setDelayType(anASTNode.getLeftChild()); setDelayType(anASTNode.getRightChild()); } else if ( aNumChildren == 1 ) setDelayType( anASTNode.getLeftChild() ); return anASTNode; }