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

Go to the documentation of this file.
00001 /* $Id: OSnLNode.h 3815 2010-11-03 23:46:16Z Gassmann $ */
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         
00062         unsigned int inumberOfChildren; 
00063 
00065         int inodeInt;
00066 
00070         int inodeType;
00071         
00075         OSnLNode **m_mChildren;
00076         
00080         double m_dFunctionValue;
00081         
00082 
00086         ADdouble m_ADTape;
00087 
00092         virtual std::string getTokenNumber();
00093         
00098         virtual std::string getTokenName() = 0;
00099         
00109         virtual  std::string getNonlinearExpressionInXML();
00110 
00121         OSnLNode* createExpressionTreeFromPostfix(std::vector<OSnLNode*> nlNodeVec);
00122 
00123 
00134         OSnLNode* createExpressionTreeFromPrefix(std::vector<OSnLNode*> nlNodeVec);
00135         
00144         std::vector<OSnLNode*> getPrefixFromExpressionTree();
00145         
00155         std::vector<OSnLNode*> preOrderOSnLNodeTraversal( std::vector<OSnLNode*> *prefixVector);
00156         
00165         std::vector<OSnLNode*> getPostfixFromExpressionTree();
00166 
00176         std::vector<OSnLNode*> postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector);
00177 
00187         virtual void getVariableIndexMap(std::map<int, int> *varIdx);
00188         
00189 
00200         virtual double calculateFunction(double *x) = 0;
00201         
00202                 
00212 #ifdef COIN_HAS_CPPAD
00213         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) = 0 ;
00214 #else
00215         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) = 0;
00216 #endif
00217 
00227         virtual OSnLNode *cloneOSnLNode() = 0;
00228         
00232         OSnLNode();
00233 
00237         virtual ~OSnLNode();
00238 
00242         bool IsEqual(OSnLNode *that);
00243 };//end OSnLNode
00244 
00256 class OSnLNodePlus : public OSnLNode{  
00257 public:
00261         OSnLNodePlus();
00262 
00266         ~OSnLNodePlus();
00267         
00272         virtual std::string getTokenName();
00273         
00278         virtual double calculateFunction( double *x);
00279         
00284 #ifdef COIN_HAS_CPPAD
00285         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00286 #else
00287         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00288 #endif
00289         
00295         virtual OSnLNode *cloneOSnLNode() ;
00296 
00297 };//end OSnLNodePlus
00298 
00310 class OSnLNodeSum : public OSnLNode{  
00311 public:
00315         OSnLNodeSum();
00316 
00320         ~OSnLNodeSum();
00321         
00326         virtual std::string getTokenName();
00327         
00332         virtual double calculateFunction( double *x);
00333         
00338         virtual OSnLNode *cloneOSnLNode() ;
00339                  
00344 #ifdef COIN_HAS_CPPAD
00345         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00346 #else
00347         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00348 #endif  
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 };//end OSnLNodeMax
00402 
00414 class OSnLNodeMin : public OSnLNode{  
00415 public:
00419         OSnLNodeMin();
00420 
00424         ~OSnLNodeMin();
00425         
00430         virtual std::string getTokenName();
00431         
00436         virtual double calculateFunction( double *x);
00437         
00442         virtual OSnLNode *cloneOSnLNode() ;
00443         
00448 #ifdef COIN_HAS_CPPAD
00449         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00450 #else
00451         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00452 #endif
00453 
00454 };//end OSnLNodeMin
00455 
00456 
00468 class OSnLNodeMinus : public OSnLNode{  
00469 public:
00473         OSnLNodeMinus();
00474 
00478         ~OSnLNodeMinus();
00479         
00480         
00485         virtual std::string getTokenName();
00486         
00491         virtual double calculateFunction( double *x);
00492         
00497         virtual OSnLNode *cloneOSnLNode() ;
00498                  
00503 #ifdef COIN_HAS_CPPAD
00504         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00505 #else
00506         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00507 #endif
00508 
00509 };//end OSnLNodeMinus
00510 
00522 class OSnLNodeNegate : public OSnLNode{  
00523 public:
00527         OSnLNodeNegate();
00528 
00532         ~OSnLNodeNegate();
00533         
00538         virtual std::string getTokenName();
00539         
00544         virtual double calculateFunction( double *x);
00545         
00550         virtual OSnLNode *cloneOSnLNode() ;
00551         
00552                  
00557 #ifdef COIN_HAS_CPPAD
00558         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00559 #else
00560         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00561 #endif
00562 };//end OSnLNodeNegate
00563 
00564 
00576 class OSnLNodeTimes : public OSnLNode{  
00577 public:
00581         OSnLNodeTimes();
00582 
00586         ~OSnLNodeTimes();
00587         
00592         virtual std::string getTokenName();
00593         
00598         virtual double calculateFunction( double *x);
00599         
00604         virtual OSnLNode *cloneOSnLNode() ;
00605          
00610 #ifdef COIN_HAS_CPPAD
00611         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD) ;
00612 #else
00613         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD) ;
00614 #endif
00615 
00616 };//end OSnLNodeTimes
00617 
00618 
00630 class OSnLNodeDivide : public OSnLNode{  
00631 public:
00635         OSnLNodeDivide();
00636 
00640         ~OSnLNodeDivide();
00641         
00642         
00647         virtual std::string getTokenName();
00648         
00653         virtual double calculateFunction( double *x);
00654         
00659         virtual OSnLNode *cloneOSnLNode() ;
00660                  
00665 #ifdef COIN_HAS_CPPAD
00666         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00667 #else
00668         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00669 #endif
00670 };//end OSnLNodeDivide
00671 
00683 class OSnLNodePower : public OSnLNode{  
00684 public:
00688         OSnLNodePower();
00689 
00693         ~OSnLNodePower();
00694         
00699         virtual std::string getTokenName();
00700         
00705         virtual double calculateFunction( double *x);
00706         
00711         virtual OSnLNode *cloneOSnLNode() ;
00712                  
00717 #ifdef COIN_HAS_CPPAD
00718         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00719 #else
00720         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00721 #endif
00722 
00723 };//end OSnLNodePower
00724 
00736 class OSnLNodeProduct : public OSnLNode{  
00737 public:
00741         OSnLNodeProduct();
00742 
00746         ~OSnLNodeProduct();
00747         
00752         virtual std::string getTokenName();
00753         
00758         virtual double calculateFunction( double *x);
00759         
00764         virtual OSnLNode *cloneOSnLNode() ;
00765          
00770 #ifdef COIN_HAS_CPPAD
00771         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00772 #else
00773         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00774 #endif
00775 
00776 };//end OSnLNodeProduct
00777 
00778 
00790 class OSnLNodeLn : public OSnLNode{  
00791 public:
00795         OSnLNodeLn();
00796 
00800         ~OSnLNodeLn();
00801         
00806         virtual std::string getTokenName();
00807         
00812         virtual double calculateFunction( double *x);
00813         
00818         virtual OSnLNode *cloneOSnLNode() ;
00819                  
00824 #ifdef COIN_HAS_CPPAD
00825         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00826 #else
00827         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00828 #endif
00829         
00830 
00831 };//end OSnLNodeLn
00832 
00844 class OSnLNodeSqrt : public OSnLNode{  
00845 public:
00849         OSnLNodeSqrt();
00850 
00854         ~OSnLNodeSqrt();
00855         
00860         virtual std::string getTokenName();
00861         
00866         virtual double calculateFunction( double *x);
00867         
00872         virtual OSnLNode *cloneOSnLNode() ;      
00877 #ifdef COIN_HAS_CPPAD
00878         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00879 #else
00880         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00881 #endif
00882         
00883 
00884 };//end OSnLNodeSqrt
00885 
00897 class OSnLNodeSquare : public OSnLNode{  
00898 public:
00902         OSnLNodeSquare();
00903 
00907         ~OSnLNodeSquare();
00908         
00913         virtual std::string getTokenName();
00914         
00919         virtual double calculateFunction( double *x);
00920         
00925         virtual OSnLNode *cloneOSnLNode() ;
00926          
00931 #ifdef COIN_HAS_CPPAD
00932         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00933 #else
00934         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00935 #endif
00936 };//end OSnLNodeSquare
00937 
00949 class OSnLNodeCos : public OSnLNode{  
00950 public:
00954         OSnLNodeCos();
00955 
00959         ~OSnLNodeCos();
00960         
00965         virtual std::string getTokenName();
00966         
00971         virtual double calculateFunction( double *x);
00972         
00977         virtual OSnLNode *cloneOSnLNode() ;
00978          
00983 #ifdef COIN_HAS_CPPAD
00984         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
00985 #else
00986         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
00987 #endif
00988 };//end OSnLNodeCos
00989 
01001 class OSnLNodeSin : public OSnLNode{  
01002 public:
01006         OSnLNodeSin();
01007 
01011         ~OSnLNodeSin();
01012         
01017         virtual std::string getTokenName();
01018         
01023         virtual double calculateFunction( double *x);
01024         
01029         virtual OSnLNode *cloneOSnLNode() ;
01030          
01035 #ifdef COIN_HAS_CPPAD
01036         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01037 #else
01038         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01039 #endif
01040 };//end OSnLNodeSin
01041 
01053 class OSnLNodeExp : public OSnLNode{  
01054 public:
01058         OSnLNodeExp();
01059 
01063         ~OSnLNodeExp();
01064         
01069         virtual std::string getTokenName();
01070         
01075         virtual double calculateFunction( double *x);
01076         
01081 #ifdef COIN_HAS_CPPAD
01082         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01083 #else
01084         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01085 #endif  
01086 
01091         virtual OSnLNode *cloneOSnLNode() ;
01092 
01093 };//end OSnLNodeExp
01094 
01106 class OSnLNodeAbs : public OSnLNode{  
01107 public:
01111         OSnLNodeAbs();
01112 
01116         ~OSnLNodeAbs();
01117         
01122         virtual std::string getTokenName();
01123         
01128         virtual double calculateFunction( double *x);
01129         
01134         virtual OSnLNode *cloneOSnLNode() ;
01135                  
01140 #ifdef COIN_HAS_CPPAD
01141         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01142 #else
01143         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01144 #endif
01145 
01146 };//end OSnLNodeAbs
01147 
01148 
01160 class OSnLNodeErf : public OSnLNode{  
01161 public:
01165         OSnLNodeErf();
01166 
01170         ~OSnLNodeErf();
01171         
01176         virtual std::string getTokenName();
01177         
01182         virtual double calculateFunction( double *x);
01183         
01188         virtual OSnLNode *cloneOSnLNode() ;
01189                  
01194 #ifdef COIN_HAS_CPPAD
01195         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01196 #else
01197         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01198 #endif  
01199 };//end OSnLNodeErf
01200 
01201 
01202 
01203 
01215 class OSnLNodeIf : public OSnLNode{  
01216 public:
01220         OSnLNodeIf();
01221 
01225         ~OSnLNodeIf();
01226         
01231         virtual std::string getTokenName();
01232         
01237         virtual double calculateFunction( double *x);
01238         
01243         virtual OSnLNode *cloneOSnLNode() ;
01244                  
01249 #ifdef COIN_HAS_CPPAD
01250         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01251 #else
01252         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01253 #endif
01254 
01255 };//end OSnLNodeIf
01256 
01268 class OSnLNodeNumber : public OSnLNode{  
01269 public:
01270         
01272         double value;
01274         std::string type;
01278         std::string id;
01279 
01283         OSnLNodeNumber();
01284 
01288         ~OSnLNodeNumber();
01289         
01294         virtual std::string getTokenName();
01295         
01300         virtual std::string getTokenNumber();
01301         
01306         virtual std::string getNonlinearExpressionInXML();
01307         
01312         virtual double calculateFunction( double *x);
01313         
01318         virtual OSnLNode *cloneOSnLNode() ;
01319         
01320                  
01325 #ifdef COIN_HAS_CPPAD
01326         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01327 #else
01328         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01329 #endif  
01330 
01331 
01332 };//end OSnLNodeNumber
01333 
01334 
01346 class OSnLNodeE : public OSnLNode{  
01347 public:
01348 
01352         OSnLNodeE();
01353 
01357         ~OSnLNodeE();
01358         
01359 
01364         virtual std::string getTokenNumber();
01365         
01366         
01371         virtual std::string getTokenName();
01372         
01377         virtual std::string getNonlinearExpressionInXML();
01378         
01383         virtual double calculateFunction( double *x);
01384         
01389         virtual OSnLNode *cloneOSnLNode() ;
01390         
01391                  
01396 #ifdef COIN_HAS_CPPAD
01397         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01398 #else
01399         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01400 #endif
01401 
01402 
01403 };//end OSnLNodeE
01404 
01416 class OSnLNodePI : public OSnLNode{  
01417 public:
01418 
01422         OSnLNodePI();
01423 
01427         ~OSnLNodePI();
01428         
01429 
01434         virtual std::string getTokenNumber();
01435         
01436         
01441         virtual std::string getTokenName();
01442         
01447         virtual std::string getNonlinearExpressionInXML();
01448         
01453         virtual double calculateFunction( double *x);
01454         
01459         virtual OSnLNode *cloneOSnLNode() ;
01460         
01461                  
01466 #ifdef COIN_HAS_CPPAD
01467         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01468 #else
01469         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01470 #endif  
01471 
01472 
01473 };//end OSnLNodePI
01474 
01475 
01487 class OSnLNodeVariable : public OSnLNode{  
01488 public:
01489 
01493         double coef;
01494         
01496         int idx;
01497 
01501         OSnLNodeVariable();
01502 
01506         ~OSnLNodeVariable();
01507         
01508 
01509         
01510         virtual void getVariableIndexMap(std::map<int, int> *varIdx);
01511         
01516         virtual std::string getTokenNumber();
01517         
01518         
01523         virtual std::string getTokenName();
01524         
01529         virtual std::string getNonlinearExpressionInXML();
01530         
01535         virtual double calculateFunction( double *x);
01536 
01541         virtual OSnLNode *cloneOSnLNode() ;
01542                  
01547 #ifdef COIN_HAS_CPPAD
01548         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01549 #else
01550         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01551 #endif
01552 
01553 
01554 };//end OSnLNodeVariable
01555 
01568 class OSnLNodeAllDiff : public OSnLNode{  
01569 public:
01573         OSnLNodeAllDiff();
01574 
01578         ~OSnLNodeAllDiff();
01579         
01584         virtual std::string getTokenName();
01585         
01590         virtual double calculateFunction( double *x);
01591         
01596         virtual OSnLNode *cloneOSnLNode() ;
01597                  
01602 #ifdef COIN_HAS_CPPAD
01603         virtual ADdouble constructADTape(std::map<int, int> *ADIdx, CppAD::vector< ADdouble > *XAD);
01604 #else
01605         virtual double constructADTape(std::map<int, int> *ADIdx, std::vector< double > *XAD);
01606 #endif
01607 
01608 };//end OSnLNodeAllDiff
01609 
01610 
01611 
01612 /* 
01613 TO DO:
01614 
01615 1.  Allow for a variable node with a child
01616 
01617 2.  When we create the Expression Tree from postfix, do we check if the coefficient of a variable is 1?
01618 */
01619 #endif
01620 
01621 

Generated on Thu Mar 31 03:12:51 2011 by  doxygen 1.4.7