/** @file OSnLNode.h * \brief This file defines the OSnLNode class along with its derived classes. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * Copyright (C) 2005, Robert Fourer, Jun Ma, Kipp Martin, * Northwestern University, and the University of Chicago. * All Rights Reserved. * This software is licensed under the Common Public License. * Please see the accompanying LICENSE file in root directory for terms. * */ #ifndef OSNLNODE_H #define OSNLNODE_H #include #include #include #include /** \enum OP_CODES we give a name or op code to each of the values of * inodeInt (number identifying the type of node) -- this is * easier to work with */ enum OP_CODES{ OS_PLUS = 1001, OS_SUM = 1002, OS_MINUS = 1003, OS_NEGATE = 1004, OS_TIMES = 1005, OS_DIVIDE = 1006, OS_POWER = 1009, OS_PRODUCT = 1010, OS_ABS = 2001, OS_SQUARE = 2005, OS_SQRT = 2006, OS_LN = 2007, OS_EXP = 2010, OS_SIN = 3001, OS_COS = 3002, OS_MIN = 4010, OS_MAX = 4011, OS_NUMBER = 5001, OS_PI = 5003, OS_E = 5004, OS_VARIABLE = 6001, OS_IF = 7001, OS_ALLDIF = 7016 }; using CppAD::AD; using CppAD::vector; /*! \class OSnLNode OSnLNode.h "OSnLNode.h" * \brief The OSnLNode Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * in this file we define an OSnL node for a subset of the nodes * defined in the OSnL schema * */ class OSnLNode{ public: /** nodeName holds the OSnLNode name */ std::string snodeName; /** numberOfChildren is the number of OSnLNode child elements*/ int inumberOfChildren; /** ssymbolInt is the unique integer assigned to the OSnLNode*/ int inodeInt; /** inodeType is the number of children the node has, it is set * to -1 if the number is not known a prior, e.g. a sum node */ int inodeType; /** * m_mChildren holds all the operands, that is nodes that the current node operate on. */ OSnLNode **m_mChildren; /** * m_dFunctionValue holds the function value given the current variable values. */ double m_dFunctionValue; /** * m_CppADTape stores the espression tree for the this OSnLNode as an AD. */ AD m_CppADTape; /** * * @return the value of inodeInt */ virtual std::string getTokenNumber(); /** * * @return the value of snodeName */ virtual std::string getTokenName(); /** *

* the following method writes an OSnLNode in * OSiL format, it is used by OSiLWriter to take * an OSInstance and write the corresponding OSiL *

* * @return the OSnLNode and its children as an OSiL string. */ virtual std::string getNonlinearExpressionInXML(); /** *

* Take a vector of OSnLNodes in postfix format and create * an create an OSExpressionTree root node *

* @param nlNodeVec holds a vector of pointers to OSnLNodes * in postfix format * @return a pointer to an OSnLNode which is the root of * and OSExpressionTree. */ OSnLNode* createExpressionTreeFromPostfix(std::vector nlNodeVec); /** *

* Take a vector of OSnLNodes in prefix format and create * an create an OSExpressionTree root node *

* @param nlNodeVec holds a vector of pointers to OSnLNodes * in prefix format * @return a pointer to an OSnLNode which is the root of * and OSExpressionTree. */ OSnLNode* createExpressionTreeFromPrefix(std::vector nlNodeVec); /** *

* Get a vector of pointers to OSnLNodes that correspond to * the OSExpressionTree in prefix format *

* * @return the expression tree as a vector of OSnLNodes in prefix. */ std::vector getPrefixFromExpressionTree(); /** *

* Called by getPrefixFromExpressionTree(). This method calls * itself recursively and * generates a vector of pointers to OSnLNodes in prefix *

* @param a pointer prefixVector to a vector of pointers of OSnLNodes * @return a vector of pointers to OSnLNodes in prefix. */ std::vector preOrderOSnLNodeTraversal( std::vector *prefixVector); /** *

* Get a vector of pointers to OSnLNodes that correspond to * the OSExpressionTree in postfix format *

* * @return the expression tree as a vector of OSnLNodes in postfix. */ std::vector getPostfixFromExpressionTree(); /** *

* Called by getPostfixFromExpressionTree(). This method calls * itself recursively and * generates a vector of pointers to OSnLNodes in postfix *

* @param a pointer postfixVector to a vector of pointers of OSnLNodes * @return a vector of pointers to OSnLNodes in postfix. */ std::vector postOrderOSnLNodeTraversal( std::vector *postfixVector); /** *

* varIdx is a map where the key is the index of an OSnLNodeVariable and * (*varIdx)[ idx] is the kth variable in the map, e.g. * (*varIdx)[ 5] = 2 means that variable indexed by 5 is the second variable * in the OSnLNode and all of its children *

* @param a pointer to a map of the variables in the OSnLNode and its children */ virtual void getVariableIndexMap(std::map *varIdx); /** *

* Calculate the function value given the current variable values. * This is an abstract method which is required to be implemented by the concrete * operator nodes that derive or extend from this OSnLNode class. *

* * @param x holds the values of the variables in a double array. * @return the function value given the current variable values. */ virtual double calculateFunction(double *x) = 0; /** *

* Create the AD tape to be evaluated by CppAD. * This is an abstract method which is required to be implemented by the concrete * operator nodes that derive or extend from this OSnLNode class. *

* * @return the expression tree. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) = 0; /** *

* Create or clone a node of this type. * This is an abstract method which is required to be implemented by the concrete * operator nodes that derive or extend from this OSnLNode class. *

* * @param x holds the values of the variables in a double array. * @return the function value given the current variable values. */ virtual OSnLNode *cloneOSnLNode() = 0; /** * default constructor. */ OSnLNode(); /** * default destructor. */ virtual ~OSnLNode(); };//end OSnLNode /*! \class OSnLNodePlus * \brief The OSnLNodePlus Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodePlus : public OSnLNode{ public: /** * default constructor. */ OSnLNodePlus(); /** * default destructor. */ ~OSnLNodePlus(); /*! \fn double OSnLNodePlus::calculateFunction(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn double OSnLNodePlus::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; };//end OSnLNodePlus /*! \class OSnLNodeSum * \brief The OSnLNodeSum Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeSum : public OSnLNode{ public: /** * default constructor. */ OSnLNodeSum(); /** * default destructor. */ ~OSnLNodeSum(); /*! \fn double OSnLNodeSum::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeSum::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeSum /*! \class OSnLNodeMax * \brief The OSnLNodeMax Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeMax : public OSnLNode{ public: /** * default constructor. */ OSnLNodeMax(); /** * default destructor. */ ~OSnLNodeMax(); /*! \fn double OSnLNodeMax::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeMax::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeMax /*! \class OSnLNodeMin * \brief The OSnLNodeMin Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeMin : public OSnLNode{ public: /** * default constructor. */ OSnLNodeMin(); /** * default destructor. */ ~OSnLNodeMin(); /*! \fn double OSnLNodeMin::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeMin::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeMin /*! \class OSnLNodeMinus * \brief The OSnLNodeMinus Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeMinus : public OSnLNode{ public: /** * default constructor. */ OSnLNodeMinus(); /** * default destructor. */ ~OSnLNodeMinus(); /*! \fn double OSnLNodeMinus::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeMinus::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeMinus /*! \class OSnLNodeNegate * \brief The OSnLNodeNegate Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeNegate : public OSnLNode{ public: /** * default constructor. */ OSnLNodeNegate(); /** * default destructor. */ ~OSnLNodeNegate(); /*! \fn double OSnLNodeNegate::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeNegate::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeNegate /*! \class OSnLNodeTimes * \brief The OSnLNodeTimes Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeTimes : public OSnLNode{ public: /** * default constructor. */ OSnLNodeTimes(); /** * default destructor. */ ~OSnLNodeTimes(); /*! \fn double OSnLNodeTimes::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeNegate::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeTimes /*! \class OSnLNodeDivide * \brief The OSnLNodeDivide Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeDivide : public OSnLNode{ public: /** * default constructor. */ OSnLNodeDivide(); /** * default destructor. */ ~OSnLNodeDivide(); /*! \fn double OSnLNodeDivide::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeDivide::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeDivide /*! \class OSnLNodePower * \brief The OSnLNodePower Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodePower : public OSnLNode{ public: /** * default constructor. */ OSnLNodePower(); /** * default destructor. */ ~OSnLNodePower(); /*! \fn double OSnLNodePower::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodePower::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodePower /*! \class OSnLNodeProduct * \brief The OSnLNodeProduct Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeProduct : public OSnLNode{ public: /** * default constructor. */ OSnLNodeProduct(); /** * default destructor. */ ~OSnLNodeProduct(); /*! \fn double OSnLNodeProduct::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeProduct::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeProduct /*! \class OSnLNodeLn * \brief The OSnLNodeLn Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeLn : public OSnLNode{ public: /** * default constructor. */ OSnLNodeLn(); /** * default destructor. */ ~OSnLNodeLn(); /*! \fn double OSnLNodeLn::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeLn::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeLn /*! \class OSnLNodeSqrt * \brief The OSnLNodeSqrt Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeSqrt : public OSnLNode{ public: /** * default constructor. */ OSnLNodeSqrt(); /** * default destructor. */ ~OSnLNodeSqrt(); /*! \fn double OSnLNodeSqrt::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeSqrt::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeSqrt /*! \class OSnLNodeSquare * \brief The OSnLNodeSquare Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeSquare : public OSnLNode{ public: /** * default constructor. */ OSnLNodeSquare(); /** * default destructor. */ ~OSnLNodeSquare(); /*! \fn double OSnLNodeSquare::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeSquare::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeSquare /*! \class OSnLNodeCos * \brief The OSnLNodeCos Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeCos : public OSnLNode{ public: /** * default constructor. */ OSnLNodeCos(); /** * default destructor. */ ~OSnLNodeCos(); /*! \fn double OSnLNodeCos::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeCos::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeCos /*! \class OSnLNodeSin * \brief The OSnLNodeSin Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeSin : public OSnLNode{ public: /** * default constructor. */ OSnLNodeSin(); /** * default destructor. */ ~OSnLNodeSin(); /*! \fn double OSnLNodeSin::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeSin::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeSin /*! \class OSnLNodeExp * \brief The OSnLNodeExp Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeExp : public OSnLNode{ public: /** * default constructor. */ OSnLNodeExp(); /** * default destructor. */ ~OSnLNodeExp(); /*! \fn double OSnLNodeExp::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn double OSnLNodeExp::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; };//end OSnLNodeExp /*! \class OSnLNodeAbs * \brief The OSnLNodeAbs Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeAbs : public OSnLNode{ public: /** * default constructor. */ OSnLNodeAbs(); /** * default destructor. */ ~OSnLNodeAbs(); /*! \fn double OSnLNodeAbs::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeAbs::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeAbs /*! \class OSnLNodeIf * \brief The OSnLNodeIf Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeIf : public OSnLNode{ public: /** * default constructor. */ OSnLNodeIf(); /** * default destructor. */ ~OSnLNodeIf(); /*! \fn double OSnLNodeIf::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeIf::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeIf /*! \class OSnLNodeNumber * \brief The OSnLNodeNumber Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeNumber : public OSnLNode{ public: /** value is the value of the number */ double value; /** in the C++ type is real */ std::string type; /** later, e.g. stochastic programming, we may wish * to give an id to a number */ std::string id; /** * default constructor. */ OSnLNodeNumber(); /** * default destructor. */ ~OSnLNodeNumber(); /** * * @return a string token that corresponds to the OSnLNode. */ virtual std::string getTokenNumber(); /** * * @return a string token that corresponds to the OSnLNode. */ virtual std::string getTokenName(); /** * * @return the OSiL XML for the number node. */ virtual std::string getNonlinearExpressionInXML(); /*! \fn double OSnLNodeNumber::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeNumber::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeNumber /*! \class OSnLNodeE * \brief The OSnLNodeE Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeE : public OSnLNode{ public: /** * default constructor. */ OSnLNodeE(); /** * default destructor. */ ~OSnLNodeE(); /** * * @return a string token that corresponds to the OSnLNode. */ virtual std::string getTokenNumber(); /** * * @return a string token that corresponds to the OSnLNode. */ virtual std::string getTokenName(); /** * * @return the OSiL XML for the number node. */ virtual std::string getNonlinearExpressionInXML(); /*! \fn double OSnLNodeE::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeE::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeE /*! \class OSnLNodePI * \brief The OSnLNodePI Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodePI : public OSnLNode{ public: /** * default constructor. */ OSnLNodePI(); /** * default destructor. */ ~OSnLNodePI(); /** * * @return a string token that corresponds to the OSnLNode. */ virtual std::string getTokenNumber(); /** * * @return a string token that corresponds to the OSnLNode. */ virtual std::string getTokenName(); /** * * @return the OSiL XML for the number node. */ virtual std::string getNonlinearExpressionInXML(); /*! \fn double OSnLNodePI::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodePI::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodePI /*! \class OSnLNodeVariable * \brief The OSnLNodeVariable Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeVariable : public OSnLNode{ public: /** coef is an option coefficient on the variable, the * default value is 1.o */ double coef; /** idx is the index of the variable */ int idx; /** * default constructor. */ OSnLNodeVariable(); /** * default destructor. */ ~OSnLNodeVariable(); virtual void getVariableIndexMap(std::map *varIdx); /** * * @return a string token that corresponds to the OSnLNode. */ virtual std::string getTokenNumber(); /** * * @return a std::string token that corresponds to the OSnLNode. */ virtual std::string getTokenName(); /** * * @return the OSiL XML for the variable node. */ virtual std::string getNonlinearExpressionInXML(); /*! \fn double OSnLNodeVariable::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeVariable::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeVariable /*! \class OSnLNodeAllDiff * \brief The OSnLNodeAllDiff Class. * * @author Robert Fourer, Jun Ma, Kipp Martin, * @version 1.0, 10/05/2005 * @since OS1.0 * * \remarks * The in-memory representation of the OSnL element * */ class OSnLNodeAllDiff : public OSnLNode{ public: /** * default constructor. */ OSnLNodeAllDiff(); /** * default destructor. */ ~OSnLNodeAllDiff(); /*! \fn double OSnLNodeAllDiff::double(double *x) * \brief The implementation of the virtual functions. * \return a double. */ virtual double calculateFunction( double *x); /*! \fn OSnLNode *cloneOSnLNode(double *x) * \brief The implementation of the virtual functions. * \return a point to a new OSnLNode of the proper type. */ virtual OSnLNode *cloneOSnLNode() ; /*! \fn double OSnLNodeAllDiff::constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD) * \brief The implementation of the virtual functions. * \return a AD. */ virtual AD constructCppADTape(std::map *cppADIdx, CppAD::vector< AD > *XAD); };//end OSnLNodeAllDiff /* TO DO: 1. Allow for a variable node with a child 2. When we create the Expression Tree from postfix, do we check if the coefficient of a variable is 1? */ #endif