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

Go to the documentation of this file.
00001 /* $Id: OSnLNode.h 3488 2010-04-29 20:16:06Z kmartin $ */
00018 #ifndef OSNLNODE_H
00019 #define OSNLNODE_H
00020 #include "OSConfig.h"
00021 #include "OSErrorClass.h"
00022 #include<iostream>
00023 #include<vector>
00024 #include <map> 
00025 
00026 #ifdef COIN_HAS_CPPAD  
00027 #include<cppad/cppad.hpp>
00028 using CppAD::AD;
00029 using CppAD::vector;
00030 typedef AD<double>  ADdouble;
00031 #else
00032 typedef double  ADdouble;
00033 using std::vector;
00034 #endif
00035 
00036 
00037  
00051 class OSnLNode{  
00052 
00053 public: 
00054 
00055         
00056         
00059         unsigned int inumberOfChildren; 
00060 
00062         int inodeInt;
00063 
00067         int inodeType;
00068         
00072         OSnLNode **m_mChildren;
00073         
00077         double m_dFunctionValue;
00078         
00079 
00083         ADdouble m_ADTape;
00084 
00089         virtual std::string getTokenNumber();
00090         
00095         virtual std::string getTokenName() = 0;
00096         
00106         virtual  std::string getNonlinearExpressionInXML();
00107 
00118         OSnLNode* createExpressionTreeFromPostfix(std::vector<OSnLNode*> nlNodeVec);
00119 
00120 
00131         OSnLNode* createExpressionTreeFromPrefix(std::vector<OSnLNode*> nlNodeVec);
00132         
00141         std::vector<OSnLNode*> getPrefixFromExpressionTree();
00142         
00152         std::vector<OSnLNode*> preOrderOSnLNodeTraversal( std::vector<OSnLNode*> *prefixVector);
00153         
00162         std::vector<OSnLNode*> getPostfixFromExpressionTree();
00163 
00173         std::vector<OSnLNode*> postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector);
00174 
00184         virtual void getVariableIndexMap(std::map<int, int> *varIdx);
00185         
00186 
00197         virtual double calculateFunction(double *x) = 0;
00198         
00199                 
00209         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD) = 0;
00210 
00221         virtual OSnLNode *cloneOSnLNode() = 0;
00222         
00223 
00224         
00228         OSnLNode();
00229 
00233         virtual ~OSnLNode();
00234         
00235 };//end OSnLNode
00236 
00249 class OSnLNodePlus : public OSnLNode{  
00250 public:
00254         OSnLNodePlus();
00255 
00259         ~OSnLNodePlus();
00260         
00265         virtual std::string getTokenName();
00266         
00271         virtual double calculateFunction( double *x);
00272         
00277         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00278         
00284         virtual OSnLNode *cloneOSnLNode() ;
00285 
00286 };//end OSnLNodePlus
00287 
00299 class OSnLNodeSum : public OSnLNode{  
00300 public:
00304         OSnLNodeSum();
00305 
00309         ~OSnLNodeSum();
00310         
00315         virtual std::string getTokenName();
00316         
00321         virtual double calculateFunction( double *x);
00322         
00327         virtual OSnLNode *cloneOSnLNode() ;
00328                  
00333         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00334         
00335         
00336 
00337 
00338 };//end OSnLNodeSum
00339 
00351 class OSnLNodeMax : public OSnLNode{  
00352 public:
00356         OSnLNodeMax();
00357 
00361         ~OSnLNodeMax();
00362         
00367         virtual std::string getTokenName();
00368         
00373         virtual double calculateFunction( double *x);
00374         
00379         virtual OSnLNode *cloneOSnLNode() ;
00380         
00385         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00386         
00387 
00388 
00389 };//end OSnLNodeMax
00390 
00402 class OSnLNodeMin : public OSnLNode{  
00403 public:
00407         OSnLNodeMin();
00408 
00412         ~OSnLNodeMin();
00413         
00418         virtual std::string getTokenName();
00419         
00424         virtual double calculateFunction( double *x);
00425         
00430         virtual OSnLNode *cloneOSnLNode() ;
00431         
00436         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00437         
00438 
00439 
00440 };//end OSnLNodeMin
00441 
00442 
00454 class OSnLNodeMinus : public OSnLNode{  
00455 public:
00459         OSnLNodeMinus();
00460 
00464         ~OSnLNodeMinus();
00465         
00466         
00471         virtual std::string getTokenName();
00472         
00477         virtual double calculateFunction( double *x);
00478         
00483         virtual OSnLNode *cloneOSnLNode() ;
00484                  
00489         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00490         
00491 
00492 
00493 };//end OSnLNodeMinus
00494 
00506 class OSnLNodeNegate : public OSnLNode{  
00507 public:
00511         OSnLNodeNegate();
00512 
00516         ~OSnLNodeNegate();
00517         
00522         virtual std::string getTokenName();
00523         
00528         virtual double calculateFunction( double *x);
00529         
00534         virtual OSnLNode *cloneOSnLNode() ;
00535         
00536                  
00541         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00542 
00543 
00544 };//end OSnLNodeNegate
00545 
00546 
00558 class OSnLNodeTimes : public OSnLNode{  
00559 public:
00563         OSnLNodeTimes();
00564 
00568         ~OSnLNodeTimes();
00569         
00574         virtual std::string getTokenName();
00575         
00580         virtual double calculateFunction( double *x);
00581         
00586         virtual OSnLNode *cloneOSnLNode() ;
00587          
00592         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00593         
00594 
00595 
00596 };//end OSnLNodeTimes
00597 
00598 
00610 class OSnLNodeDivide : public OSnLNode{  
00611 public:
00615         OSnLNodeDivide();
00616 
00620         ~OSnLNodeDivide();
00621         
00622         
00627         virtual std::string getTokenName();
00628         
00633         virtual double calculateFunction( double *x);
00634         
00639         virtual OSnLNode *cloneOSnLNode() ;
00640                  
00645         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00646 
00647 };//end OSnLNodeDivide
00648 
00660 class OSnLNodePower : public OSnLNode{  
00661 public:
00665         OSnLNodePower();
00666 
00670         ~OSnLNodePower();
00671         
00676         virtual std::string getTokenName();
00677         
00682         virtual double calculateFunction( double *x);
00683         
00688         virtual OSnLNode *cloneOSnLNode() ;
00689                  
00694         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00695         
00696 
00697 
00698 };//end OSnLNodePower
00699 
00711 class OSnLNodeProduct : public OSnLNode{  
00712 public:
00716         OSnLNodeProduct();
00717 
00721         ~OSnLNodeProduct();
00722         
00727         virtual std::string getTokenName();
00728         
00733         virtual double calculateFunction( double *x);
00734         
00739         virtual OSnLNode *cloneOSnLNode() ;
00740          
00745         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00746         
00747 
00748 
00749 };//end OSnLNodeProduct
00750 
00751 
00763 class OSnLNodeLn : public OSnLNode{  
00764 public:
00768         OSnLNodeLn();
00769 
00773         ~OSnLNodeLn();
00774         
00779         virtual std::string getTokenName();
00780         
00785         virtual double calculateFunction( double *x);
00786         
00791         virtual OSnLNode *cloneOSnLNode() ;
00792                  
00797         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00798         
00799 
00800         
00801 
00802 };//end OSnLNodeLn
00803 
00815 class OSnLNodeSqrt : public OSnLNode{  
00816 public:
00820         OSnLNodeSqrt();
00821 
00825         ~OSnLNodeSqrt();
00826         
00831         virtual std::string getTokenName();
00832         
00837         virtual double calculateFunction( double *x);
00838         
00843         virtual OSnLNode *cloneOSnLNode() ;      
00848         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00849         
00850 
00851         
00852 
00853 };//end OSnLNodeSqrt
00854 
00866 class OSnLNodeSquare : public OSnLNode{  
00867 public:
00871         OSnLNodeSquare();
00872 
00876         ~OSnLNodeSquare();
00877         
00882         virtual std::string getTokenName();
00883         
00888         virtual double calculateFunction( double *x);
00889         
00894         virtual OSnLNode *cloneOSnLNode() ;
00895          
00900         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00901 
00902 };//end OSnLNodeSquare
00903 
00915 class OSnLNodeCos : public OSnLNode{  
00916 public:
00920         OSnLNodeCos();
00921 
00925         ~OSnLNodeCos();
00926         
00931         virtual std::string getTokenName();
00932         
00937         virtual double calculateFunction( double *x);
00938         
00943         virtual OSnLNode *cloneOSnLNode() ;
00944          
00949         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00950 
00951 };//end OSnLNodeCos
00952 
00964 class OSnLNodeSin : public OSnLNode{  
00965 public:
00969         OSnLNodeSin();
00970 
00974         ~OSnLNodeSin();
00975         
00980         virtual std::string getTokenName();
00981         
00986         virtual double calculateFunction( double *x);
00987         
00992         virtual OSnLNode *cloneOSnLNode() ;
00993          
00998         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00999 
01000 };//end OSnLNodeSin
01001 
01013 class OSnLNodeExp : public OSnLNode{  
01014 public:
01018         OSnLNodeExp();
01019 
01023         ~OSnLNodeExp();
01024         
01029         virtual std::string getTokenName();
01030         
01035         virtual double calculateFunction( double *x);
01036         
01041         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01042         
01048         virtual OSnLNode *cloneOSnLNode() ;
01049 
01050 };//end OSnLNodeExp
01051 
01063 class OSnLNodeAbs : public OSnLNode{  
01064 public:
01068         OSnLNodeAbs();
01069 
01073         ~OSnLNodeAbs();
01074         
01079         virtual std::string getTokenName();
01080         
01085         virtual double calculateFunction( double *x);
01086         
01091         virtual OSnLNode *cloneOSnLNode() ;
01092                  
01097         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01098         
01099 
01100 
01101 };//end OSnLNodeAbs
01102 
01103 
01115 class OSnLNodeErf : public OSnLNode{  
01116 public:
01120         OSnLNodeErf();
01121 
01125         ~OSnLNodeErf();
01126         
01131         virtual std::string getTokenName();
01132         
01137         virtual double calculateFunction( double *x);
01138         
01143         virtual OSnLNode *cloneOSnLNode() ;
01144                  
01149         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01150         
01151 };//end OSnLNodeErf
01152 
01153 
01154 
01155 
01167 class OSnLNodeIf : public OSnLNode{  
01168 public:
01172         OSnLNodeIf();
01173 
01177         ~OSnLNodeIf();
01178         
01183         virtual std::string getTokenName();
01184         
01189         virtual double calculateFunction( double *x);
01190         
01195         virtual OSnLNode *cloneOSnLNode() ;
01196                  
01201         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);   
01202         
01203 
01204 
01205 };//end OSnLNodeIf
01206 
01218 class OSnLNodeNumber : public OSnLNode{  
01219 public:
01220         
01222         double value;
01224         std::string type;
01228         std::string id;
01229 
01233         OSnLNodeNumber();
01234 
01238         ~OSnLNodeNumber();
01239         
01244         virtual std::string getTokenName();
01245         
01250         virtual std::string getTokenNumber();
01251         
01256         virtual std::string getNonlinearExpressionInXML();
01257         
01262         virtual double calculateFunction( double *x);
01263         
01268         virtual OSnLNode *cloneOSnLNode() ;
01269         
01270                  
01275         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01276         
01277 
01278 
01279 };//end OSnLNodeNumber
01280 
01281 
01293 class OSnLNodeE : public OSnLNode{  
01294 public:
01295 
01299         OSnLNodeE();
01300 
01304         ~OSnLNodeE();
01305         
01306 
01311         virtual std::string getTokenNumber();
01312         
01313         
01318         virtual std::string getTokenName();
01319         
01324         virtual std::string getNonlinearExpressionInXML();
01325         
01330         virtual double calculateFunction( double *x);
01331         
01336         virtual OSnLNode *cloneOSnLNode() ;
01337         
01338                  
01343         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01344         
01345 
01346 
01347 };//end OSnLNodeE
01348 
01360 class OSnLNodePI : public OSnLNode{  
01361 public:
01362 
01366         OSnLNodePI();
01367 
01371         ~OSnLNodePI();
01372         
01373 
01378         virtual std::string getTokenNumber();
01379         
01380         
01385         virtual std::string getTokenName();
01386         
01391         virtual std::string getNonlinearExpressionInXML();
01392         
01397         virtual double calculateFunction( double *x);
01398         
01403         virtual OSnLNode *cloneOSnLNode() ;
01404         
01405                  
01410         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01411         
01412 
01413 
01414 };//end OSnLNodePI
01415 
01416 
01428 class OSnLNodeVariable : public OSnLNode{  
01429 public:
01430 
01434         double coef;
01435         
01437         int idx;
01438 
01442         OSnLNodeVariable();
01443 
01447         ~OSnLNodeVariable();
01448         
01449 
01450         
01451         virtual void getVariableIndexMap(std::map<int, int> *varIdx);
01452         
01457         virtual std::string getTokenNumber();
01458         
01459         
01464         virtual std::string getTokenName();
01465         
01470         virtual std::string getNonlinearExpressionInXML();
01471         
01476         virtual double calculateFunction( double *x);
01477 
01482         virtual OSnLNode *cloneOSnLNode() ;
01483                  
01488         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);   
01489         
01490 
01491 
01492 };//end OSnLNodeVariable
01493 
01506 class OSnLNodeAllDiff : public OSnLNode{  
01507 public:
01511         OSnLNodeAllDiff();
01512 
01516         ~OSnLNodeAllDiff();
01517         
01522         virtual std::string getTokenName();
01523         
01528         virtual double calculateFunction( double *x);
01529         
01534         virtual OSnLNode *cloneOSnLNode() ;
01535                  
01541         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01542 
01543 
01544 
01545 };//end OSnLNodeAllDiff
01546 
01547 
01548 
01549 /* 
01550 TO DO:
01551 
01552 1.  Allow for a variable node with a child
01553 
01554 2.  When we create the Expression Tree from postfix, do we check if the coefficient of a variable is 1?
01555 */
01556 #endif
01557 
01558 

Generated on Mon May 3 03:05:24 2010 by  doxygen 1.4.7