00001
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
00040 enum OP_CODES{
00041 OS_PLUS = 1001,
00042 OS_SUM = 1002,
00043 OS_MINUS = 1003,
00044 OS_NEGATE = 1004,
00045 OS_TIMES = 1005,
00046 OS_DIVIDE = 1006,
00047 OS_POWER = 1009,
00048 OS_PRODUCT = 1010,
00049 OS_ABS = 2001,
00050 OS_SQUARE = 2005,
00051 OS_SQRT = 2006,
00052 OS_LN = 2007,
00053 OS_EXP = 2010,
00054 OS_SIN = 3001,
00055 OS_COS = 3002,
00056 OS_MIN = 4010,
00057 OS_MAX = 4011,
00058 OS_ERF = 4625,
00059 OS_NUMBER = 5001,
00060 OS_PI = 5003,
00061 OS_E = 5004,
00062 OS_VARIABLE = 6001,
00063 OS_IF = 7001,
00064 OS_ALLDIF = 7016
00065 };
00066
00080 class OSnLNode{
00081
00082 public:
00083
00084
00086 std::string snodeName;
00087
00089 unsigned int inumberOfChildren;
00090
00092 int inodeInt;
00093
00097 int inodeType;
00098
00102 OSnLNode **m_mChildren;
00103
00107 double m_dFunctionValue;
00108
00109
00113 ADdouble m_ADTape;
00114
00119 virtual std::string getTokenNumber();
00120
00125 virtual std::string getTokenName();
00126
00136 virtual std::string getNonlinearExpressionInXML();
00137
00148 OSnLNode* createExpressionTreeFromPostfix(std::vector<OSnLNode*> nlNodeVec);
00149
00150
00161 OSnLNode* createExpressionTreeFromPrefix(std::vector<OSnLNode*> nlNodeVec);
00162
00171 std::vector<OSnLNode*> getPrefixFromExpressionTree();
00172
00182 std::vector<OSnLNode*> preOrderOSnLNodeTraversal( std::vector<OSnLNode*> *prefixVector);
00183
00192 std::vector<OSnLNode*> getPostfixFromExpressionTree();
00193
00203 std::vector<OSnLNode*> postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector);
00204
00214 virtual void getVariableIndexMap(std::map<int, int> *varIdx);
00215
00216
00227 virtual double calculateFunction(double *x) = 0;
00228
00229
00239 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD) = 0;
00240
00251 virtual OSnLNode *cloneOSnLNode() = 0;
00252
00253
00254
00258 OSnLNode();
00259
00263 virtual ~OSnLNode();
00264
00265 };
00266
00279 class OSnLNodePlus : public OSnLNode{
00280 public:
00284 OSnLNodePlus();
00285
00289 ~OSnLNodePlus();
00290
00295 virtual double calculateFunction( double *x);
00296
00301 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00302
00308 virtual OSnLNode *cloneOSnLNode() ;
00309
00310 };
00311
00323 class OSnLNodeSum : public OSnLNode{
00324 public:
00328 OSnLNodeSum();
00329
00333 ~OSnLNodeSum();
00334
00339 virtual double calculateFunction( double *x);
00340
00345 virtual OSnLNode *cloneOSnLNode() ;
00346
00351 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00352
00353
00354
00355
00356 };
00357
00369 class OSnLNodeMax : public OSnLNode{
00370 public:
00374 OSnLNodeMax();
00375
00379 ~OSnLNodeMax();
00380
00385 virtual double calculateFunction( double *x);
00386
00391 virtual OSnLNode *cloneOSnLNode() ;
00392
00397 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00398
00399
00400
00401 };
00402
00414 class OSnLNodeMin : public OSnLNode{
00415 public:
00419 OSnLNodeMin();
00420
00424 ~OSnLNodeMin();
00425
00430 virtual double calculateFunction( double *x);
00431
00436 virtual OSnLNode *cloneOSnLNode() ;
00437
00442 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00443
00444
00445
00446 };
00447
00448
00460 class OSnLNodeMinus : public OSnLNode{
00461 public:
00465 OSnLNodeMinus();
00466
00470 ~OSnLNodeMinus();
00471
00476 virtual double calculateFunction( double *x);
00477
00482 virtual OSnLNode *cloneOSnLNode() ;
00483
00488 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00489
00490
00491
00492 };
00493
00505 class OSnLNodeNegate : public OSnLNode{
00506 public:
00510 OSnLNodeNegate();
00511
00515 ~OSnLNodeNegate();
00516
00521 virtual double calculateFunction( double *x);
00522
00527 virtual OSnLNode *cloneOSnLNode() ;
00528
00529
00534 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00535
00536
00537 };
00538
00539
00551 class OSnLNodeTimes : public OSnLNode{
00552 public:
00556 OSnLNodeTimes();
00557
00561 ~OSnLNodeTimes();
00562
00567 virtual double calculateFunction( double *x);
00568
00573 virtual OSnLNode *cloneOSnLNode() ;
00574
00579 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00580
00581
00582
00583 };
00584
00585
00597 class OSnLNodeDivide : public OSnLNode{
00598 public:
00602 OSnLNodeDivide();
00603
00607 ~OSnLNodeDivide();
00608
00613 virtual double calculateFunction( double *x);
00614
00619 virtual OSnLNode *cloneOSnLNode() ;
00620
00625 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00626
00627 };
00628
00640 class OSnLNodePower : public OSnLNode{
00641 public:
00645 OSnLNodePower();
00646
00650 ~OSnLNodePower();
00651
00656 virtual double calculateFunction( double *x);
00657
00662 virtual OSnLNode *cloneOSnLNode() ;
00663
00668 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00669
00670
00671
00672 };
00673
00685 class OSnLNodeProduct : public OSnLNode{
00686 public:
00690 OSnLNodeProduct();
00691
00695 ~OSnLNodeProduct();
00696
00701 virtual double calculateFunction( double *x);
00702
00707 virtual OSnLNode *cloneOSnLNode() ;
00708
00713 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00714
00715
00716
00717 };
00718
00719
00731 class OSnLNodeLn : public OSnLNode{
00732 public:
00736 OSnLNodeLn();
00737
00741 ~OSnLNodeLn();
00742
00747 virtual double calculateFunction( double *x);
00748
00753 virtual OSnLNode *cloneOSnLNode() ;
00754
00759 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00760
00761
00762
00763
00764 };
00765
00777 class OSnLNodeSqrt : public OSnLNode{
00778 public:
00782 OSnLNodeSqrt();
00783
00787 ~OSnLNodeSqrt();
00788
00793 virtual double calculateFunction( double *x);
00794
00799 virtual OSnLNode *cloneOSnLNode() ;
00804 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00805
00806
00807
00808
00809 };
00810
00822 class OSnLNodeSquare : public OSnLNode{
00823 public:
00827 OSnLNodeSquare();
00828
00832 ~OSnLNodeSquare();
00833
00838 virtual double calculateFunction( double *x);
00839
00844 virtual OSnLNode *cloneOSnLNode() ;
00845
00850 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00851
00852 };
00853
00865 class OSnLNodeCos : public OSnLNode{
00866 public:
00870 OSnLNodeCos();
00871
00875 ~OSnLNodeCos();
00876
00881 virtual double calculateFunction( double *x);
00882
00887 virtual OSnLNode *cloneOSnLNode() ;
00888
00893 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00894
00895 };
00896
00908 class OSnLNodeSin : public OSnLNode{
00909 public:
00913 OSnLNodeSin();
00914
00918 ~OSnLNodeSin();
00919
00924 virtual double calculateFunction( double *x);
00925
00930 virtual OSnLNode *cloneOSnLNode() ;
00931
00936 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00937
00938 };
00939
00951 class OSnLNodeExp : public OSnLNode{
00952 public:
00956 OSnLNodeExp();
00957
00961 ~OSnLNodeExp();
00962
00967 virtual double calculateFunction( double *x);
00968
00973 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
00974
00980 virtual OSnLNode *cloneOSnLNode() ;
00981
00982 };
00983
00995 class OSnLNodeAbs : public OSnLNode{
00996 public:
01000 OSnLNodeAbs();
01001
01005 ~OSnLNodeAbs();
01006
01011 virtual double calculateFunction( double *x);
01012
01017 virtual OSnLNode *cloneOSnLNode() ;
01018
01023 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01024
01025
01026
01027 };
01028
01029
01041 class OSnLNodeErf : public OSnLNode{
01042 public:
01046 OSnLNodeErf();
01047
01051 ~OSnLNodeErf();
01052
01057 virtual double calculateFunction( double *x);
01058
01063 virtual OSnLNode *cloneOSnLNode() ;
01064
01069 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01070
01071 };
01072
01073
01074
01075
01087 class OSnLNodeIf : public OSnLNode{
01088 public:
01092 OSnLNodeIf();
01093
01097 ~OSnLNodeIf();
01098
01103 virtual double calculateFunction( double *x);
01104
01109 virtual OSnLNode *cloneOSnLNode() ;
01110
01115 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01116
01117
01118
01119 };
01120
01132 class OSnLNodeNumber : public OSnLNode{
01133 public:
01134
01136 double value;
01138 std::string type;
01142 std::string id;
01143
01147 OSnLNodeNumber();
01148
01152 ~OSnLNodeNumber();
01153
01158 virtual std::string getTokenNumber();
01159
01160
01165 virtual std::string getTokenName();
01166
01171 virtual std::string getNonlinearExpressionInXML();
01172
01177 virtual double calculateFunction( double *x);
01178
01183 virtual OSnLNode *cloneOSnLNode() ;
01184
01185
01190 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01191
01192
01193
01194 };
01195
01196
01208 class OSnLNodeE : public OSnLNode{
01209 public:
01210
01214 OSnLNodeE();
01215
01219 ~OSnLNodeE();
01220
01225 virtual std::string getTokenNumber();
01226
01227
01232 virtual std::string getTokenName();
01233
01238 virtual std::string getNonlinearExpressionInXML();
01239
01244 virtual double calculateFunction( double *x);
01245
01250 virtual OSnLNode *cloneOSnLNode() ;
01251
01252
01257 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01258
01259
01260
01261 };
01262
01274 class OSnLNodePI : public OSnLNode{
01275 public:
01276
01280 OSnLNodePI();
01281
01285 ~OSnLNodePI();
01286
01291 virtual std::string getTokenNumber();
01292
01293
01298 virtual std::string getTokenName();
01299
01304 virtual std::string getNonlinearExpressionInXML();
01305
01310 virtual double calculateFunction( double *x);
01311
01316 virtual OSnLNode *cloneOSnLNode() ;
01317
01318
01323 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01324
01325
01326
01327 };
01328
01329
01341 class OSnLNodeVariable : public OSnLNode{
01342 public:
01343
01347 double coef;
01348
01350 int idx;
01351
01355 OSnLNodeVariable();
01356
01360 ~OSnLNodeVariable();
01361
01362 virtual void getVariableIndexMap(std::map<int, int> *varIdx);
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
01399 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01400
01401
01402
01403 };
01404
01417 class OSnLNodeAllDiff : public OSnLNode{
01418 public:
01422 OSnLNodeAllDiff();
01423
01427 ~OSnLNodeAllDiff();
01428
01433 virtual double calculateFunction( double *x);
01434
01439 virtual OSnLNode *cloneOSnLNode() ;
01440
01446 virtual ADdouble constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD);
01447
01448
01449
01450 };
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461 #endif
01462
01463