00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #
00019 #ifndef MSL_TREE_H
00020 #define MSL_TREE_H
00021
00022 #include <list>
00023 #include <string>
00024 using namespace std;
00025
00026
00027 #include "vector.h"
00028 #include "mslio.h"
00029
00030 class MSLTree;
00031
00032 class MSLNode {
00033 private:
00034 MSLVector state;
00035 MSLVector input;
00036 MSLNode* parent;
00037 list<MSLNode*> children;
00038 double time;
00039 double cost;
00040 int id;
00041
00042 void* info;
00043
00044 public:
00046 MSLVector State() const {return state; };
00047
00049 inline MSLVector Input() const {return input; };
00050
00051 inline MSLNode* Parent() {return parent; };
00052 inline list<MSLNode*> const Children() {return children; };
00053
00055 inline double Time() const {return time; };
00056
00058 inline double Cost() const {return cost; };
00059
00061 inline void SetCost(const double &x) {cost = x; };
00062
00064 inline void SetID(const int &i) {id = i; };
00065
00067 inline int ID() const {return id; };
00068
00070 void* GetInfo() {return info; };
00071
00073 void SetInfo(void* in) {info = in; };
00074
00076
00077
00078
00079 MSLNode();
00080 MSLNode(void* pninfo);
00081 MSLNode(MSLNode* pn, const MSLVector &x, const MSLVector &u);
00082 MSLNode(MSLNode* pn, const MSLVector &x, const MSLVector &u, double t);
00083 MSLNode(MSLNode* pn, const MSLVector &x, const MSLVector &u, double t, void* pninfo);
00084 ~MSLNode() { children.clear(); };
00085
00086 inline void AddChild(MSLNode *cn) { children.push_back(cn); }
00087
00088
00089 friend ostream& operator<< (ostream& os, const MSLNode& n);
00090
00091 friend ostream& operator<< (ostream& os, const list<MSLNode*> & nl);
00092
00093 friend class MSLTree;
00094 };
00095
00096
00098 class MSLNodeLess {
00099 public:
00100 bool operator() (MSLNode* p, MSLNode* q) const {
00101 return p->Cost() < q->Cost();
00102 }
00103 };
00104
00105
00107 class MSLNodeGreater {
00108 public:
00109 bool operator() (MSLNode* p, MSLNode* q) const {
00110 return p->Cost() > q->Cost();
00111 }
00112 };
00113
00114
00115 class MSLTree {
00116 private:
00117 list<MSLNode*> nodes;
00118 MSLNode* root;
00119 int size;
00120 public:
00121
00122 MSLTree();
00123 MSLTree(const MSLVector &x);
00124 MSLTree(const MSLVector &x, void* nodeinfo);
00125 ~MSLTree();
00126
00127 void MakeRoot(const MSLVector &x);
00128 MSLNode* Extend(MSLNode *parent, const MSLVector &x, const MSLVector &u);
00129 MSLNode* Extend(MSLNode *parent, const MSLVector &x, const MSLVector &u,
00130 double time);
00131 MSLNode* Extend(MSLNode *parent, const MSLVector &x, const MSLVector &u,
00132 double time, void* pninfo);
00133
00134 list<MSLNode*> PathToRoot(MSLNode *n);
00135 MSLNode* FindNode(int nid);
00136 inline list<MSLNode*> Nodes() const { return nodes; };
00137 inline MSLNode* Root() {return root; };
00138 inline int Size() {return size;}
00139
00140 void Clear();
00141
00142 friend istream& operator>> (istream& is, MSLTree& n);
00143 friend ostream& operator<< (ostream& os, const MSLTree& n);
00144 };
00145
00146 #endif
00147