/** * @param math * @return */ public static boolean isVectorOperation(ASTNode math) { boolean hasVector = false; for (int i = 0; i < math.getChildCount(); ++i) { if (math.getChild(i).isVector()) { hasVector = true; break; } } return hasVector; }
/** * @param model * @param mathContainer * @return */ public static boolean isVectorBalanced(Model model, MathContainer mathContainer) { if (model == null || mathContainer == null) { return false; } ASTNode math = mathContainer.getMath(); if (math.isVector()) { Map<Integer, Integer> sizeByLevel = ArraysMath.getVectorDimensionSizes(model, math); return checkSizeRecursive(model, sizeByLevel, math, 0); } return true; }
/** * @param node * @param value */ private void updateASTNodeName(ASTNode node, int value) { if (node.isVector()) { for (int i = 0; i < node.getChildCount(); ++i) { ASTNode child = node.getChild(i); updateASTNodeName(child, value); } } else if (node.isName()) { node.setName("_" + String.valueOf(value) + node.getName()); } else { node.setName("unknown"); } }
@Override public ASTNodeValue selector(List<ASTNode> nodes) throws SBMLException { ASTNode object = nodes.get(0); ASTNode result; if (object.isVector()) { result = object; for (int i = 1; i < nodes.size(); ++i) { int index = (int) nodes.get(i).compile(this).toDouble(); result = result.getChild(index); } return result.compile(this); } else if (object.isVariable()) { compile(object.getVariable()); } else if (object.isString()) { compile(object.getName()); } return unknownValue(); }
/** * @param value */ private void sinRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { sinRecursive(value.getChild(i)); } else if (useId){ ASTNode sinValue = new ASTNode(ASTNode.Type.FUNCTION_SIN, child.getParentSBMLObject()); sinValue.addChild(child.clone()); value.replaceChild(i, sinValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.sin(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void ceilingRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { ceilingRecursive(value.getChild(i)); } else if (useId){ ASTNode ceilValue = new ASTNode(ASTNode.Type.FUNCTION_CEILING, child.getParentSBMLObject()); ceilValue.addChild(child.clone()); value.replaceChild(i, ceilValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.ceil(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void logRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { logRecursive(value.getChild(i)); } else if (useId){ ASTNode logValue = new ASTNode(ASTNode.Type.FUNCTION_LOG, child.getParentSBMLObject()); logValue.addChild(child.clone()); value.replaceChild(i, logValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.log10(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arcsinRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arcsinRecursive(value.getChild(i)); } else if (useId){ ASTNode arcsinValue = new ASTNode(ASTNode.Type.FUNCTION_ARCSIN, child.getParentSBMLObject()); arcsinValue.addChild(child.clone()); value.replaceChild(i, arcsinValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.asin(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void lnRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { lnRecursive(value.getChild(i)); } else if (useId){ ASTNode lnValue = new ASTNode(ASTNode.Type.FUNCTION_LN, child.getParentSBMLObject()); lnValue.addChild(child.clone()); value.replaceChild(i, lnValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.log(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arctanhRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arctanhRecursive(value.getChild(i)); } else if (useId){ ASTNode arctanhValue = new ASTNode(ASTNode.Type.FUNCTION_ARCTANH, child.getParentSBMLObject()); arctanhValue.addChild(child.clone()); value.replaceChild(i, arctanhValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arctanh(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void cothRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { cothRecursive(value.getChild(i)); } else if (useId){ ASTNode cothValue = new ASTNode(ASTNode.Type.FUNCTION_COTH, child.getParentSBMLObject()); cothValue.addChild(child.clone()); value.replaceChild(i, cothValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.coth(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arccothRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arccothRecursive(value.getChild(i)); } else if (useId){ ASTNode arccothValue = new ASTNode(ASTNode.Type.FUNCTION_ARCCOTH, child.getParentSBMLObject()); arccothValue.addChild(child.clone()); value.replaceChild(i, arccothValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arccoth(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arccscRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arccscRecursive(value.getChild(i)); } else if (useId){ ASTNode arccscValue = new ASTNode(ASTNode.Type.FUNCTION_ARCCSC, child.getParentSBMLObject()); arccscValue.addChild(child.clone()); value.replaceChild(i, arccscValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arccsc(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arcsecRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arcsecRecursive(value.getChild(i)); } else if (useId){ ASTNode arcsecValue = new ASTNode(ASTNode.Type.FUNCTION_ARCSEC, child.getParentSBMLObject()); arcsecValue.addChild(child.clone()); value.replaceChild(i, arcsecValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arcsec(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void coshRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isNumber()) { value.getChild(i).setValue(Math.cosh(child.getReal())); } else if (child.isVector()) { coshRecursive(value.getChild(i)); } else if (useId){ ASTNode coshValue = new ASTNode(ASTNode.Type.FUNCTION_COSH, child.getParentSBMLObject()); coshValue.addChild(child.clone()); value.replaceChild(i, coshValue); } else { throw new SBMLException(); } } }
/** * @param value */ private void cschRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { cschRecursive(value.getChild(i)); } else if (useId){ ASTNode cschValue = new ASTNode(ASTNode.Type.FUNCTION_CSCH, child.getParentSBMLObject()); cschValue.addChild(child.clone()); value.replaceChild(i, cschValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.csch(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arcsechRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arcsechRecursive(value.getChild(i)); } else if (useId){ ASTNode arcsechValue = new ASTNode(ASTNode.Type.FUNCTION_ARCSECH, child.getParentSBMLObject()); arcsechValue.addChild(child.clone()); value.replaceChild(i, arcsechValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arcsech(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void cscRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { cscRecursive(value.getChild(i)); } else if (useId){ ASTNode cscValue = new ASTNode(ASTNode.Type.FUNCTION_CSC, child.getParentSBMLObject()); cscValue.addChild(child.clone()); value.replaceChild(i, cscValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.csc(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void cotRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isNumber()) { value.getChild(i).setValue(Maths.cot(child.getReal())); } else if (child.isVector()) { cotRecursive(value.getChild(i)); } else if (useId){ ASTNode cotValue = new ASTNode(ASTNode.Type.FUNCTION_COT, child.getParentSBMLObject()); cotValue.addChild(child.clone()); value.replaceChild(i, cotValue); } else { throw new SBMLException(); } } }
/** * @param value */ private void sechRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { sechRecursive(value.getChild(i)); } else if (useId){ ASTNode sechValue = new ASTNode(ASTNode.Type.FUNCTION_SECH, child.getParentSBMLObject()); sechValue.addChild(child.clone()); value.replaceChild(i, sechValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.sech(child.getReal())); } else { throw new SBMLException(); } } }