00001
00016 #ifndef OSNLNODE_H
00017 #define OSNLNODE_H
00018
00019 #include "OSConfig.h"
00020 #include "OSErrorClass.h"
00021 #include <iostream>
00022 #include <vector>
00023 #include <map>
00024
00025
00026 #ifdef OS_HAS_CPPAD
00027 #include<cppad/cppad.hpp>
00028 typedef CppAD::AD<double> ADdouble;
00029 typedef CppAD::vector<ADdouble> ADvector;
00030 #else
00031 typedef double ADdouble;
00032 typedef std::vector<ADdouble> ADvector;
00033 #endif
00034
00035
00036
00050 class OSnLNode
00051 {
00052
00053 public:
00054
00055
00056
00060 unsigned int inumberOfChildren;
00061
00063 int inodeInt;
00064
00068 int inodeType;
00069
00073 OSnLNode **m_mChildren;
00074
00078 double m_dFunctionValue;
00079
00080
00084 ADdouble m_ADTape;
00085
00090 virtual std::string getTokenNumber();
00091
00096 virtual std::string getTokenName() = 0;
00097
00107 virtual std::string getNonlinearExpressionInXML();
00108
00119 OSnLNode* createExpressionTreeFromPostfix(std::vector<OSnLNode*> nlNodeVec);
00120
00121
00132 OSnLNode* createExpressionTreeFromPrefix(std::vector<OSnLNode*> nlNodeVec);
00133
00142 std::vector<OSnLNode*> getPrefixFromExpressionTree();
00143
00153 std::vector<OSnLNode*> preOrderOSnLNodeTraversal( std::vector<OSnLNode*> *prefixVector);
00154
00163 std::vector<OSnLNode*> getPostfixFromExpressionTree();
00164
00174 std::vector<OSnLNode*> postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector);
00175
00185 virtual void getVariableIndexMap(std::map<int, int> *varIdx);
00186
00187
00198 virtual double calculateFunction(double *x) = 0;
00199
00200
00210 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) = 0 ;
00221 virtual OSnLNode *cloneOSnLNode() = 0;
00222
00226 OSnLNode();
00227
00231 virtual ~OSnLNode();
00232
00236 bool IsEqual(OSnLNode *that);
00237 };
00238
00250 class OSnLNodePlus : public OSnLNode
00251 {
00252 public:
00256 OSnLNodePlus();
00257
00261 ~OSnLNodePlus();
00262
00267 virtual std::string getTokenName();
00268
00273 virtual double calculateFunction( double *x);
00274
00279 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00280
00286 virtual OSnLNode *cloneOSnLNode() ;
00287
00288 };
00289
00301 class OSnLNodeSum : public OSnLNode
00302 {
00303 public:
00307 OSnLNodeSum();
00308
00312 ~OSnLNodeSum();
00313
00318 virtual std::string getTokenName();
00319
00324 virtual double calculateFunction( double *x);
00325
00330 virtual OSnLNode *cloneOSnLNode() ;
00331
00336 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00337 };
00338
00350 class OSnLNodeMax : public OSnLNode
00351 {
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, ADvector *XAD);
00386 };
00387
00399 class OSnLNodeMin : public OSnLNode
00400 {
00401 public:
00405 OSnLNodeMin();
00406
00410 ~OSnLNodeMin();
00411
00416 virtual std::string getTokenName();
00417
00422 virtual double calculateFunction( double *x);
00423
00428 virtual OSnLNode *cloneOSnLNode() ;
00429
00434 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00435
00436 };
00437
00438
00450 class OSnLNodeMinus : public OSnLNode
00451 {
00452 public:
00456 OSnLNodeMinus();
00457
00461 ~OSnLNodeMinus();
00462
00463
00468 virtual std::string getTokenName();
00469
00474 virtual double calculateFunction( double *x);
00475
00480 virtual OSnLNode *cloneOSnLNode() ;
00481
00486 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00487
00488 };
00489
00501 class OSnLNodeNegate : public OSnLNode
00502 {
00503 public:
00507 OSnLNodeNegate();
00508
00512 ~OSnLNodeNegate();
00513
00518 virtual std::string getTokenName();
00519
00524 virtual double calculateFunction( double *x);
00525
00530 virtual OSnLNode *cloneOSnLNode() ;
00531
00532
00537 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00538 };
00539
00540
00552 class OSnLNodeTimes : public OSnLNode
00553 {
00554 public:
00558 OSnLNodeTimes();
00559
00563 ~OSnLNodeTimes();
00564
00569 virtual std::string getTokenName();
00570
00575 virtual double calculateFunction( double *x);
00576
00581 virtual OSnLNode *cloneOSnLNode() ;
00582
00587 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00588
00589 };
00590
00591
00603 class OSnLNodeDivide : public OSnLNode
00604 {
00605 public:
00609 OSnLNodeDivide();
00610
00614 ~OSnLNodeDivide();
00615
00616
00621 virtual std::string getTokenName();
00622
00627 virtual double calculateFunction( double *x);
00628
00633 virtual OSnLNode *cloneOSnLNode() ;
00634
00639 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00640 };
00641
00653 class OSnLNodePower : public OSnLNode
00654 {
00655 public:
00659 OSnLNodePower();
00660
00664 ~OSnLNodePower();
00665
00670 virtual std::string getTokenName();
00671
00676 virtual double calculateFunction( double *x);
00677
00682 virtual OSnLNode *cloneOSnLNode() ;
00683
00688 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00689
00690 };
00691
00703 class OSnLNodeProduct : public OSnLNode
00704 {
00705 public:
00709 OSnLNodeProduct();
00710
00714 ~OSnLNodeProduct();
00715
00720 virtual std::string getTokenName();
00721
00726 virtual double calculateFunction( double *x);
00727
00732 virtual OSnLNode *cloneOSnLNode() ;
00733
00738 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00739
00740 };
00741
00742
00754 class OSnLNodeLn : public OSnLNode
00755 {
00756 public:
00760 OSnLNodeLn();
00761
00765 ~OSnLNodeLn();
00766
00771 virtual std::string getTokenName();
00772
00777 virtual double calculateFunction( double *x);
00778
00783 virtual OSnLNode *cloneOSnLNode() ;
00784
00789 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00790
00791
00792 };
00793
00805 class OSnLNodeSqrt : public OSnLNode
00806 {
00807 public:
00811 OSnLNodeSqrt();
00812
00816 ~OSnLNodeSqrt();
00817
00822 virtual std::string getTokenName();
00823
00828 virtual double calculateFunction( double *x);
00829
00834 virtual OSnLNode *cloneOSnLNode() ;
00839 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00840
00841
00842 };
00843
00855 class OSnLNodeSquare : public OSnLNode
00856 {
00857 public:
00861 OSnLNodeSquare();
00862
00866 ~OSnLNodeSquare();
00867
00872 virtual std::string getTokenName();
00873
00878 virtual double calculateFunction( double *x);
00879
00884 virtual OSnLNode *cloneOSnLNode() ;
00885
00890 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00891 };
00892
00904 class OSnLNodeCos : public OSnLNode
00905 {
00906 public:
00910 OSnLNodeCos();
00911
00915 ~OSnLNodeCos();
00916
00921 virtual std::string getTokenName();
00922
00927 virtual double calculateFunction( double *x);
00928
00933 virtual OSnLNode *cloneOSnLNode() ;
00934
00939 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00940 };
00941
00953 class OSnLNodeSin : public OSnLNode
00954 {
00955 public:
00959 OSnLNodeSin();
00960
00964 ~OSnLNodeSin();
00965
00970 virtual std::string getTokenName();
00971
00976 virtual double calculateFunction( double *x);
00977
00982 virtual OSnLNode *cloneOSnLNode() ;
00983
00988 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00989 };
00990
01002 class OSnLNodeExp : public OSnLNode
01003 {
01004 public:
01008 OSnLNodeExp();
01009
01013 ~OSnLNodeExp();
01014
01019 virtual std::string getTokenName();
01020
01025 virtual double calculateFunction( double *x);
01026
01031 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01037 virtual OSnLNode *cloneOSnLNode() ;
01038
01039 };
01040
01052 class OSnLNodeAbs : public OSnLNode
01053 {
01054 public:
01058 OSnLNodeAbs();
01059
01063 ~OSnLNodeAbs();
01064
01069 virtual std::string getTokenName();
01070
01075 virtual double calculateFunction( double *x);
01076
01081 virtual OSnLNode *cloneOSnLNode() ;
01082
01087 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01088
01089 };
01090
01091
01103 class OSnLNodeErf : public OSnLNode
01104 {
01105 public:
01109 OSnLNodeErf();
01110
01114 ~OSnLNodeErf();
01115
01120 virtual std::string getTokenName();
01121
01126 virtual double calculateFunction( double *x);
01127
01132 virtual OSnLNode *cloneOSnLNode() ;
01133
01138 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01139 };
01140
01141
01142
01143
01155 class OSnLNodeIf : public OSnLNode
01156 {
01157 public:
01161 OSnLNodeIf();
01162
01166 ~OSnLNodeIf();
01167
01172 virtual std::string getTokenName();
01173
01178 virtual double calculateFunction( double *x);
01179
01184 virtual OSnLNode *cloneOSnLNode() ;
01185
01190 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01191
01192 };
01193
01205 class OSnLNodeNumber : public OSnLNode
01206 {
01207 public:
01208
01210 double value;
01212 std::string type;
01216 std::string id;
01217
01221 OSnLNodeNumber();
01222
01226 ~OSnLNodeNumber();
01227
01232 virtual std::string getTokenName();
01233
01238 virtual std::string getTokenNumber();
01239
01244 virtual std::string getNonlinearExpressionInXML();
01245
01250 virtual double calculateFunction( double *x);
01251
01256 virtual OSnLNode *cloneOSnLNode() ;
01257
01258
01263 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01264
01265
01266 };
01267
01268
01280 class OSnLNodeE : public OSnLNode
01281 {
01282 public:
01283
01287 OSnLNodeE();
01288
01292 ~OSnLNodeE();
01293
01294
01299 virtual std::string getTokenNumber();
01300
01301
01306 virtual std::string getTokenName();
01307
01312 virtual std::string getNonlinearExpressionInXML();
01313
01318 virtual double calculateFunction( double *x);
01319
01324 virtual OSnLNode *cloneOSnLNode() ;
01325
01326
01331 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01332
01333
01334 };
01335
01347 class OSnLNodePI : public OSnLNode
01348 {
01349 public:
01350
01354 OSnLNodePI();
01355
01359 ~OSnLNodePI();
01360
01361
01366 virtual std::string getTokenNumber();
01367
01368
01373 virtual std::string getTokenName();
01374
01379 virtual std::string getNonlinearExpressionInXML();
01380
01385 virtual double calculateFunction( double *x);
01386
01391 virtual OSnLNode *cloneOSnLNode() ;
01392
01393
01398 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01399
01400
01401 };
01402
01403
01415 class OSnLNodeVariable : public OSnLNode
01416 {
01417 public:
01418
01422 double coef;
01423
01425 int idx;
01426
01430 OSnLNodeVariable();
01431
01435 ~OSnLNodeVariable();
01436
01437
01438
01439 virtual void getVariableIndexMap(std::map<int, int> *varIdx);
01440
01445 virtual std::string getTokenNumber();
01446
01447
01452 virtual std::string getTokenName();
01453
01458 virtual std::string getNonlinearExpressionInXML();
01459
01464 virtual double calculateFunction( double *x);
01465
01470 virtual OSnLNode *cloneOSnLNode() ;
01471
01476 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01477
01478
01479 };
01480
01493 class OSnLNodeAllDiff : public OSnLNode
01494 {
01495 public:
01499 OSnLNodeAllDiff();
01500
01504 ~OSnLNodeAllDiff();
01505
01510 virtual std::string getTokenName();
01511
01516 virtual double calculateFunction( double *x);
01517
01522 virtual OSnLNode *cloneOSnLNode() ;
01523
01528 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01529
01530 };
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541 #endif
01542
01543