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 public:
00053
00057 unsigned int inumberOfChildren;
00058
00060 int inodeInt;
00061
00065 int inodeType;
00066
00070 OSnLNode **m_mChildren;
00071
00075 double m_dFunctionValue;
00076
00080 ADdouble m_ADTape;
00081
00085 virtual std::string getTokenNumber();
00086
00090 virtual std::string getTokenName() = 0;
00091
00101 virtual std::string getNonlinearExpressionInXML();
00102
00113 OSnLNode* createExpressionTreeFromPostfix(std::vector<OSnLNode*> nlNodeVec);
00114
00115
00126 OSnLNode* createExpressionTreeFromPrefix(std::vector<OSnLNode*> nlNodeVec);
00127
00136 std::vector<OSnLNode*> getPrefixFromExpressionTree();
00137
00147 std::vector<OSnLNode*> preOrderOSnLNodeTraversal( std::vector<OSnLNode*> *prefixVector);
00148
00157 std::vector<OSnLNode*> getPostfixFromExpressionTree();
00158
00168 std::vector<OSnLNode*> postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector);
00169
00179 virtual void getVariableIndexMap(std::map<int, int> *varIdx);
00180
00181
00192 virtual double calculateFunction(double *x) = 0;
00193
00194
00204 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) = 0;
00205
00211 OSnLNode* copyNodeAndDescendants();
00212
00223 virtual OSnLNode *cloneOSnLNode() = 0;
00224
00228 OSnLNode();
00229
00233 virtual ~OSnLNode();
00234
00238 bool IsEqual(OSnLNode *that);
00239 };
00240
00252 class OSnLNodePlus : public OSnLNode
00253 {
00254 public:
00258 OSnLNodePlus();
00259
00263 ~OSnLNodePlus();
00264
00269 virtual std::string getTokenName();
00270
00275 virtual double calculateFunction( double *x);
00276
00281 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00282
00288 virtual OSnLNode *cloneOSnLNode() ;
00289
00290 };
00291
00303 class OSnLNodeSum : public OSnLNode
00304 {
00305 public:
00309 OSnLNodeSum();
00310
00314 ~OSnLNodeSum();
00315
00320 virtual std::string getTokenName();
00321
00326 virtual double calculateFunction( double *x);
00327
00332 virtual OSnLNode *cloneOSnLNode() ;
00333
00338 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00339 };
00340
00352 class OSnLNodeMax : public OSnLNode
00353 {
00354 public:
00358 OSnLNodeMax();
00359
00363 ~OSnLNodeMax();
00364
00369 virtual std::string getTokenName();
00370
00375 virtual double calculateFunction( double *x);
00376
00381 virtual OSnLNode *cloneOSnLNode() ;
00382
00387 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00388 };
00389
00401 class OSnLNodeMin : public OSnLNode
00402 {
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, ADvector *XAD) ;
00437
00438 };
00439
00440
00452 class OSnLNodeMinus : public OSnLNode
00453 {
00454 public:
00458 OSnLNodeMinus();
00459
00463 ~OSnLNodeMinus();
00464
00465
00470 virtual std::string getTokenName();
00471
00476 virtual double calculateFunction( double *x);
00477
00482 virtual OSnLNode *cloneOSnLNode() ;
00483
00488 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00489
00490 };
00491
00503 class OSnLNodeNegate : public OSnLNode
00504 {
00505 public:
00509 OSnLNodeNegate();
00510
00514 ~OSnLNodeNegate();
00515
00520 virtual std::string getTokenName();
00521
00526 virtual double calculateFunction( double *x);
00527
00532 virtual OSnLNode *cloneOSnLNode() ;
00533
00534
00539 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00540 };
00541
00542
00554 class OSnLNodeTimes : public OSnLNode
00555 {
00556 public:
00560 OSnLNodeTimes();
00561
00565 ~OSnLNodeTimes();
00566
00571 virtual std::string getTokenName();
00572
00577 virtual double calculateFunction( double *x);
00578
00583 virtual OSnLNode *cloneOSnLNode() ;
00584
00589 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD) ;
00590
00591 };
00592
00593
00605 class OSnLNodeDivide : public OSnLNode
00606 {
00607 public:
00611 OSnLNodeDivide();
00612
00616 ~OSnLNodeDivide();
00617
00618
00623 virtual std::string getTokenName();
00624
00629 virtual double calculateFunction( double *x);
00630
00635 virtual OSnLNode *cloneOSnLNode() ;
00636
00641 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00642 };
00643
00655 class OSnLNodePower : public OSnLNode
00656 {
00657 public:
00661 OSnLNodePower();
00662
00666 ~OSnLNodePower();
00667
00672 virtual std::string getTokenName();
00673
00678 virtual double calculateFunction( double *x);
00679
00684 virtual OSnLNode *cloneOSnLNode() ;
00685
00690 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00691
00692 };
00693
00705 class OSnLNodeProduct : public OSnLNode
00706 {
00707 public:
00711 OSnLNodeProduct();
00712
00716 ~OSnLNodeProduct();
00717
00722 virtual std::string getTokenName();
00723
00728 virtual double calculateFunction( double *x);
00729
00734 virtual OSnLNode *cloneOSnLNode() ;
00735
00740 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00741
00742 };
00743
00744
00756 class OSnLNodeLn : public OSnLNode
00757 {
00758 public:
00762 OSnLNodeLn();
00763
00767 ~OSnLNodeLn();
00768
00773 virtual std::string getTokenName();
00774
00779 virtual double calculateFunction( double *x);
00780
00785 virtual OSnLNode *cloneOSnLNode() ;
00786
00791 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00792
00793
00794 };
00795
00807 class OSnLNodeSqrt : public OSnLNode
00808 {
00809 public:
00813 OSnLNodeSqrt();
00814
00818 ~OSnLNodeSqrt();
00819
00824 virtual std::string getTokenName();
00825
00830 virtual double calculateFunction( double *x);
00831
00836 virtual OSnLNode *cloneOSnLNode() ;
00841 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00842
00843
00844 };
00845
00857 class OSnLNodeSquare : public OSnLNode
00858 {
00859 public:
00863 OSnLNodeSquare();
00864
00868 ~OSnLNodeSquare();
00869
00874 virtual std::string getTokenName();
00875
00880 virtual double calculateFunction( double *x);
00881
00886 virtual OSnLNode *cloneOSnLNode() ;
00887
00892 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00893 };
00894
00906 class OSnLNodeCos : public OSnLNode
00907 {
00908 public:
00912 OSnLNodeCos();
00913
00917 ~OSnLNodeCos();
00918
00923 virtual std::string getTokenName();
00924
00929 virtual double calculateFunction( double *x);
00930
00935 virtual OSnLNode *cloneOSnLNode() ;
00936
00941 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00942 };
00943
00955 class OSnLNodeSin : public OSnLNode
00956 {
00957 public:
00961 OSnLNodeSin();
00962
00966 ~OSnLNodeSin();
00967
00972 virtual std::string getTokenName();
00973
00978 virtual double calculateFunction( double *x);
00979
00984 virtual OSnLNode *cloneOSnLNode() ;
00985
00990 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
00991 };
00992
01004 class OSnLNodeExp : public OSnLNode
01005 {
01006 public:
01010 OSnLNodeExp();
01011
01015 ~OSnLNodeExp();
01016
01021 virtual std::string getTokenName();
01022
01027 virtual double calculateFunction( double *x);
01028
01033 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01039 virtual OSnLNode *cloneOSnLNode() ;
01040
01041 };
01042
01054 class OSnLNodeAbs : public OSnLNode
01055 {
01056 public:
01060 OSnLNodeAbs();
01061
01065 ~OSnLNodeAbs();
01066
01071 virtual std::string getTokenName();
01072
01077 virtual double calculateFunction( double *x);
01078
01083 virtual OSnLNode *cloneOSnLNode() ;
01084
01089 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01090
01091 };
01092
01093
01105 class OSnLNodeErf : public OSnLNode
01106 {
01107 public:
01111 OSnLNodeErf();
01112
01116 ~OSnLNodeErf();
01117
01122 virtual std::string getTokenName();
01123
01128 virtual double calculateFunction( double *x);
01129
01134 virtual OSnLNode *cloneOSnLNode() ;
01135
01140 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01141 };
01142
01143
01144
01145
01157 class OSnLNodeIf : public OSnLNode
01158 {
01159 public:
01163 OSnLNodeIf();
01164
01168 ~OSnLNodeIf();
01169
01174 virtual std::string getTokenName();
01175
01180 virtual double calculateFunction( double *x);
01181
01186 virtual OSnLNode *cloneOSnLNode() ;
01187
01192 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01193
01194 };
01195
01207 class OSnLNodeNumber : public OSnLNode
01208 {
01209 public:
01210
01212 double value;
01214 std::string type;
01218 std::string id;
01219
01223 OSnLNodeNumber();
01224
01228 ~OSnLNodeNumber();
01229
01234 virtual std::string getTokenName();
01235
01240 virtual std::string getTokenNumber();
01241
01246 virtual std::string getNonlinearExpressionInXML();
01247
01252 virtual double calculateFunction( double *x);
01253
01258 virtual OSnLNode *cloneOSnLNode() ;
01259
01260
01265 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01266
01267
01268 };
01269
01270
01282 class OSnLNodeE : public OSnLNode
01283 {
01284 public:
01285
01289 OSnLNodeE();
01290
01294 ~OSnLNodeE();
01295
01296
01301 virtual std::string getTokenNumber();
01302
01303
01308 virtual std::string getTokenName();
01309
01314 virtual std::string getNonlinearExpressionInXML();
01315
01320 virtual double calculateFunction( double *x);
01321
01326 virtual OSnLNode *cloneOSnLNode() ;
01327
01328
01333 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01334
01335
01336 };
01337
01349 class OSnLNodePI : public OSnLNode
01350 {
01351 public:
01352
01356 OSnLNodePI();
01357
01361 ~OSnLNodePI();
01362
01363
01368 virtual std::string getTokenNumber();
01369
01370
01375 virtual std::string getTokenName();
01376
01381 virtual std::string getNonlinearExpressionInXML();
01382
01387 virtual double calculateFunction( double *x);
01388
01393 virtual OSnLNode *cloneOSnLNode() ;
01394
01395
01400 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01401
01402
01403 };
01404
01405
01417 class OSnLNodeVariable : public OSnLNode
01418 {
01419 public:
01420
01424 double coef;
01425
01427 int idx;
01428
01432 OSnLNodeVariable();
01433
01437 ~OSnLNodeVariable();
01438
01439
01440
01441 virtual void getVariableIndexMap(std::map<int, int> *varIdx);
01442
01447 virtual std::string getTokenNumber();
01448
01449
01454 virtual std::string getTokenName();
01455
01460 virtual std::string getNonlinearExpressionInXML();
01461
01466 virtual double calculateFunction( double *x);
01467
01472 virtual OSnLNode *cloneOSnLNode() ;
01473
01478 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01479
01480
01481 };
01482
01495 class OSnLNodeAllDiff : public OSnLNode
01496 {
01497 public:
01501 OSnLNodeAllDiff();
01502
01506 ~OSnLNodeAllDiff();
01507
01512 virtual std::string getTokenName();
01513
01518 virtual double calculateFunction( double *x);
01519
01524 virtual OSnLNode *cloneOSnLNode() ;
01525
01530 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, ADvector *XAD);
01531
01532 };
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543 #endif
01544
01545