/home/coin/SVN-release/OS-2.2.0/OS/src/OSCommonInterfaces/OSnLNode.h

Go to the documentation of this file.
00001 /* $Id: OSnLNode.h 3603 2010-08-01 18:39:02Z kmartin $ */
00018 #ifndef OSNLNODE_H
00019 #define OSNLNODE_H
00020 
00021 #include "OSConfig.h"
00022 #include "OSErrorClass.h"
00023 #include<iostream>
00024 #include<vector>
00025 #include <map> 
00026 
00027 
00028 #ifdef COIN_HAS_CPPAD  
00029 #include<cppad/cppad.hpp>
00030 using CppAD::AD;
00031 //using CppAD::vector;
00032 typedef AD<double>  ADdouble;
00033 #else
00034 typedef double  ADdouble;
00035 //using std::vector;
00036 #endif
00037 
00038 
00039  
00053 class OSnLNode{  
00054 
00055 public: 
00056 
00057         
00058         
00061         unsigned int inumberOfChildren; 
00062 
00064         int inodeInt;
00065 
00069         int inodeType;
00070         
00074         OSnLNode **m_mChildren;
00075         
00079         double m_dFunctionValue;
00080         
00081 
00085         ADdouble m_ADTape;
00086 
00091         virtual std::string getTokenNumber();
00092         
00097         virtual std::string getTokenName() = 0;
00098         
00108         virtual  std::string getNonlinearExpressionInXML();
00109 
00120         OSnLNode* createExpressionTreeFromPostfix(std::vector<OSnLNode*> nlNodeVec);
00121 
00122 
00133         OSnLNode* createExpressionTreeFromPrefix(std::vector<OSnLNode*> nlNodeVec);
00134         
00143         std::vector<OSnLNode*> getPrefixFromExpressionTree();
00144         
00154         std::vector<OSnLNode*> preOrderOSnLNodeTraversal( std::vector<OSnLNode*> *prefixVector);
00155         
00164         std::vector<OSnLNode*> getPostfixFromExpressionTree();
00165 
00175         std::vector<OSnLNode*> postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector);
00176 
00186         virtual void getVariableIndexMap(std::map<int, int> *varIdx);
00187         
00188 
00199         virtual double calculateFunction(double *x) = 0;
00200         
00201                 
00211 #ifdef COIN_HAS_CPPAD
00212         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) = 0 ;
00213 #else
00214         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) = 0;
00215 #endif
00216 
00226         virtual OSnLNode *cloneOSnLNode() = 0;
00227         
00228 
00229         
00233         OSnLNode();
00234 
00238         virtual ~OSnLNode();
00239         
00240 };//end OSnLNode
00241 
00254 class OSnLNodePlus : public OSnLNode{  
00255 public:
00259         OSnLNodePlus();
00260 
00264         ~OSnLNodePlus();
00265         
00270         virtual std::string getTokenName();
00271         
00276         virtual double calculateFunction( double *x);
00277         
00282 #ifdef COIN_HAS_CPPAD
00283         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00284 #else
00285         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00286 #endif
00287         
00293         virtual OSnLNode *cloneOSnLNode() ;
00294 
00295 };//end OSnLNodePlus
00296 
00308 class OSnLNodeSum : public OSnLNode{  
00309 public:
00313         OSnLNodeSum();
00314 
00318         ~OSnLNodeSum();
00319         
00324         virtual std::string getTokenName();
00325         
00330         virtual double calculateFunction( double *x);
00331         
00336         virtual OSnLNode *cloneOSnLNode() ;
00337                  
00342 #ifdef COIN_HAS_CPPAD
00343         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00344 #else
00345         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00346 #endif  
00347 
00348 
00349 };//end OSnLNodeSum
00350 
00362 class OSnLNodeMax : public OSnLNode{  
00363 public:
00367         OSnLNodeMax();
00368 
00372         ~OSnLNodeMax();
00373         
00378         virtual std::string getTokenName();
00379         
00384         virtual double calculateFunction( double *x);
00385         
00390         virtual OSnLNode *cloneOSnLNode() ;
00391         
00396 #ifdef COIN_HAS_CPPAD
00397         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00398 #else
00399         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00400 #endif
00401 
00402 };//end OSnLNodeMax
00403 
00415 class OSnLNodeMin : public OSnLNode{  
00416 public:
00420         OSnLNodeMin();
00421 
00425         ~OSnLNodeMin();
00426         
00431         virtual std::string getTokenName();
00432         
00437         virtual double calculateFunction( double *x);
00438         
00443         virtual OSnLNode *cloneOSnLNode() ;
00444         
00449 #ifdef COIN_HAS_CPPAD
00450         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00451 #else
00452         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00453 #endif
00454 
00455 };//end OSnLNodeMin
00456 
00457 
00469 class OSnLNodeMinus : public OSnLNode{  
00470 public:
00474         OSnLNodeMinus();
00475 
00479         ~OSnLNodeMinus();
00480         
00481         
00486         virtual std::string getTokenName();
00487         
00492         virtual double calculateFunction( double *x);
00493         
00498         virtual OSnLNode *cloneOSnLNode() ;
00499                  
00504 #ifdef COIN_HAS_CPPAD
00505         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00506 #else
00507         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00508 #endif
00509 
00510 };//end OSnLNodeMinus
00511 
00523 class OSnLNodeNegate : public OSnLNode{  
00524 public:
00528         OSnLNodeNegate();
00529 
00533         ~OSnLNodeNegate();
00534         
00539         virtual std::string getTokenName();
00540         
00545         virtual double calculateFunction( double *x);
00546         
00551         virtual OSnLNode *cloneOSnLNode() ;
00552         
00553                  
00558 #ifdef COIN_HAS_CPPAD
00559         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00560 #else
00561         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00562 #endif
00563 };//end OSnLNodeNegate
00564 
00565 
00577 class OSnLNodeTimes : public OSnLNode{  
00578 public:
00582         OSnLNodeTimes();
00583 
00587         ~OSnLNodeTimes();
00588         
00593         virtual std::string getTokenName();
00594         
00599         virtual double calculateFunction( double *x);
00600         
00605         virtual OSnLNode *cloneOSnLNode() ;
00606          
00611 #ifdef COIN_HAS_CPPAD
00612         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00613 #else
00614         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00615 #endif
00616 
00617 };//end OSnLNodeTimes
00618 
00619 
00631 class OSnLNodeDivide : public OSnLNode{  
00632 public:
00636         OSnLNodeDivide();
00637 
00641         ~OSnLNodeDivide();
00642         
00643         
00648         virtual std::string getTokenName();
00649         
00654         virtual double calculateFunction( double *x);
00655         
00660         virtual OSnLNode *cloneOSnLNode() ;
00661                  
00666 #ifdef COIN_HAS_CPPAD
00667         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00668 #else
00669         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00670 #endif
00671 };//end OSnLNodeDivide
00672 
00684 class OSnLNodePower : public OSnLNode{  
00685 public:
00689         OSnLNodePower();
00690 
00694         ~OSnLNodePower();
00695         
00700         virtual std::string getTokenName();
00701         
00706         virtual double calculateFunction( double *x);
00707         
00712         virtual OSnLNode *cloneOSnLNode() ;
00713                  
00718 #ifdef COIN_HAS_CPPAD
00719         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00720 #else
00721         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00722 #endif
00723 
00724 };//end OSnLNodePower
00725 
00737 class OSnLNodeProduct : public OSnLNode{  
00738 public:
00742         OSnLNodeProduct();
00743 
00747         ~OSnLNodeProduct();
00748         
00753         virtual std::string getTokenName();
00754         
00759         virtual double calculateFunction( double *x);
00760         
00765         virtual OSnLNode *cloneOSnLNode() ;
00766          
00771 #ifdef COIN_HAS_CPPAD
00772         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00773 #else
00774         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00775 #endif
00776 
00777 };//end OSnLNodeProduct
00778 
00779 
00791 class OSnLNodeLn : public OSnLNode{  
00792 public:
00796         OSnLNodeLn();
00797 
00801         ~OSnLNodeLn();
00802         
00807         virtual std::string getTokenName();
00808         
00813         virtual double calculateFunction( double *x);
00814         
00819         virtual OSnLNode *cloneOSnLNode() ;
00820                  
00825 #ifdef COIN_HAS_CPPAD
00826         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00827 #else
00828         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00829 #endif
00830         
00831 
00832 };//end OSnLNodeLn
00833 
00845 class OSnLNodeSqrt : public OSnLNode{  
00846 public:
00850         OSnLNodeSqrt();
00851 
00855         ~OSnLNodeSqrt();
00856         
00861         virtual std::string getTokenName();
00862         
00867         virtual double calculateFunction( double *x);
00868         
00873         virtual OSnLNode *cloneOSnLNode() ;      
00878 #ifdef COIN_HAS_CPPAD
00879         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00880 #else
00881         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00882 #endif
00883         
00884 
00885 };//end OSnLNodeSqrt
00886 
00898 class OSnLNodeSquare : public OSnLNode{  
00899 public:
00903         OSnLNodeSquare();
00904 
00908         ~OSnLNodeSquare();
00909         
00914         virtual std::string getTokenName();
00915         
00920         virtual double calculateFunction( double *x);
00921         
00926         virtual OSnLNode *cloneOSnLNode() ;
00927          
00932 #ifdef COIN_HAS_CPPAD
00933         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00934 #else
00935         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00936 #endif
00937 };//end OSnLNodeSquare
00938 
00950 class OSnLNodeCos : public OSnLNode{  
00951 public:
00955         OSnLNodeCos();
00956 
00960         ~OSnLNodeCos();
00961         
00966         virtual std::string getTokenName();
00967         
00972         virtual double calculateFunction( double *x);
00973         
00978         virtual OSnLNode *cloneOSnLNode() ;
00979          
00984 #ifdef COIN_HAS_CPPAD
00985         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00986 #else
00987         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00988 #endif
00989 };//end OSnLNodeCos
00990 
01002 class OSnLNodeSin : public OSnLNode{  
01003 public:
01007         OSnLNodeSin();
01008 
01012         ~OSnLNodeSin();
01013         
01018         virtual std::string getTokenName();
01019         
01024         virtual double calculateFunction( double *x);
01025         
01030         virtual OSnLNode *cloneOSnLNode() ;
01031          
01036 #ifdef COIN_HAS_CPPAD
01037         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01038 #else
01039         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01040 #endif
01041 };//end OSnLNodeSin
01042 
01054 class OSnLNodeExp : public OSnLNode{  
01055 public:
01059         OSnLNodeExp();
01060 
01064         ~OSnLNodeExp();
01065         
01070         virtual std::string getTokenName();
01071         
01076         virtual double calculateFunction( double *x);
01077         
01082 #ifdef COIN_HAS_CPPAD
01083         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01084 #else
01085         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01086 #endif  
01087 
01092         virtual OSnLNode *cloneOSnLNode() ;
01093 
01094 };//end OSnLNodeExp
01095 
01107 class OSnLNodeAbs : public OSnLNode{  
01108 public:
01112         OSnLNodeAbs();
01113 
01117         ~OSnLNodeAbs();
01118         
01123         virtual std::string getTokenName();
01124         
01129         virtual double calculateFunction( double *x);
01130         
01135         virtual OSnLNode *cloneOSnLNode() ;
01136                  
01141 #ifdef COIN_HAS_CPPAD
01142         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01143 #else
01144         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01145 #endif
01146 
01147 };//end OSnLNodeAbs
01148 
01149 
01161 class OSnLNodeErf : public OSnLNode{  
01162 public:
01166         OSnLNodeErf();
01167 
01171         ~OSnLNodeErf();
01172         
01177         virtual std::string getTokenName();
01178         
01183         virtual double calculateFunction( double *x);
01184         
01189         virtual OSnLNode *cloneOSnLNode() ;
01190                  
01195 #ifdef COIN_HAS_CPPAD
01196         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01197 #else
01198         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01199 #endif  
01200 };//end OSnLNodeErf
01201 
01202 
01203 
01204 
01216 class OSnLNodeIf : public OSnLNode{  
01217 public:
01221         OSnLNodeIf();
01222 
01226         ~OSnLNodeIf();
01227         
01232         virtual std::string getTokenName();
01233         
01238         virtual double calculateFunction( double *x);
01239         
01244         virtual OSnLNode *cloneOSnLNode() ;
01245                  
01250 #ifdef COIN_HAS_CPPAD
01251         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01252 #else
01253         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01254 #endif
01255 
01256 };//end OSnLNodeIf
01257 
01269 class OSnLNodeNumber : public OSnLNode{  
01270 public:
01271         
01273         double value;
01275         std::string type;
01279         std::string id;
01280 
01284         OSnLNodeNumber();
01285 
01289         ~OSnLNodeNumber();
01290         
01295         virtual std::string getTokenName();
01296         
01301         virtual std::string getTokenNumber();
01302         
01307         virtual std::string getNonlinearExpressionInXML();
01308         
01313         virtual double calculateFunction( double *x);
01314         
01319         virtual OSnLNode *cloneOSnLNode() ;
01320         
01321                  
01326 #ifdef COIN_HAS_CPPAD
01327         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01328 #else
01329         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01330 #endif  
01331 
01332 
01333 };//end OSnLNodeNumber
01334 
01335 
01347 class OSnLNodeE : public OSnLNode{  
01348 public:
01349 
01353         OSnLNodeE();
01354 
01358         ~OSnLNodeE();
01359         
01360 
01365         virtual std::string getTokenNumber();
01366         
01367         
01372         virtual std::string getTokenName();
01373         
01378         virtual std::string getNonlinearExpressionInXML();
01379         
01384         virtual double calculateFunction( double *x);
01385         
01390         virtual OSnLNode *cloneOSnLNode() ;
01391         
01392                  
01397 #ifdef COIN_HAS_CPPAD
01398         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01399 #else
01400         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01401 #endif
01402 
01403 
01404 };//end OSnLNodeE
01405 
01417 class OSnLNodePI : public OSnLNode{  
01418 public:
01419 
01423         OSnLNodePI();
01424 
01428         ~OSnLNodePI();
01429         
01430 
01435         virtual std::string getTokenNumber();
01436         
01437         
01442         virtual std::string getTokenName();
01443         
01448         virtual std::string getNonlinearExpressionInXML();
01449         
01454         virtual double calculateFunction( double *x);
01455         
01460         virtual OSnLNode *cloneOSnLNode() ;
01461         
01462                  
01467 #ifdef COIN_HAS_CPPAD
01468         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01469 #else
01470         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01471 #endif  
01472 
01473 
01474 };//end OSnLNodePI
01475 
01476 
01488 class OSnLNodeVariable : public OSnLNode{  
01489 public:
01490 
01494         double coef;
01495         
01497         int idx;
01498 
01502         OSnLNodeVariable();
01503 
01507         ~OSnLNodeVariable();
01508         
01509 
01510         
01511         virtual void getVariableIndexMap(std::map<int, int> *varIdx);
01512         
01517         virtual std::string getTokenNumber();
01518         
01519         
01524         virtual std::string getTokenName();
01525         
01530         virtual std::string getNonlinearExpressionInXML();
01531         
01536         virtual double calculateFunction( double *x);
01537 
01542         virtual OSnLNode *cloneOSnLNode() ;
01543                  
01548 #ifdef COIN_HAS_CPPAD
01549         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01550 #else
01551         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01552 #endif
01553 
01554 
01555 };//end OSnLNodeVariable
01556 
01569 class OSnLNodeAllDiff : public OSnLNode{  
01570 public:
01574         OSnLNodeAllDiff();
01575 
01579         ~OSnLNodeAllDiff();
01580         
01585         virtual std::string getTokenName();
01586         
01591         virtual double calculateFunction( double *x);
01592         
01597         virtual OSnLNode *cloneOSnLNode() ;
01598                  
01603 #ifdef COIN_HAS_CPPAD
01604         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01605 #else
01606         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01607 #endif
01608 
01609 };//end OSnLNodeAllDiff
01610 
01611 
01612 
01613 /* 
01614 TO DO:
01615 
01616 1.  Allow for a variable node with a child
01617 
01618 2.  When we create the Expression Tree from postfix, do we check if the coefficient of a variable is 1?
01619 */
01620 #endif
01621 
01622 

Generated on Thu Aug 5 03:02:58 2010 by  doxygen 1.4.7