Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

tree.h

Go to the documentation of this file.
00001 #ifndef MSL_TREE_H
00002 #define MSL_TREE_H
00003 
00004 #include <list.h>
00005 #include <string>
00006 
00007 #include "vector.h"
00008 
00009 class MSLTree;
00010 
00011 class MSLNode {
00012  private:
00013   MSLVector state;
00014   MSLVector input;
00015   MSLNode* parent;
00016   list<MSLNode*> children;
00017   double time;
00018   double cost;
00019   int id;
00020 
00021  public:
00023   MSLVector State() const {return state; };
00024 
00026   inline MSLVector Input() const {return input; };
00027 
00028   inline MSLNode* Parent() {return parent; };
00029   inline list<MSLNode*> const Children() {return children; };
00030   
00032   inline double Time() const {return time; };
00033 
00035   inline double Cost() const {return cost; };
00036 
00038   inline void SetCost(const double &x) {cost = x; };
00039 
00041   inline void SetID(const int &i) {id = i; };
00042 
00044   inline int ID() const {return id; };
00045 
00046   MSLNode();
00047   MSLNode(MSLNode *pn, const MSLVector &x, const MSLVector &u);
00048   MSLNode(MSLNode *pn, const MSLVector &x, const MSLVector &u, double t);
00049   ~MSLNode() { children.clear(); };
00050 
00051   inline void AddChild(MSLNode *cn) { children.push_back(cn); }
00052 
00053   //friend istream& operator>> (istream& is, MSLNode& n);
00054   friend ostream& operator<< (ostream& os, const MSLNode& n);
00055   //friend istream& operator>> (istream& is, list<MSLNode*> & nl);
00056   friend ostream& operator<< (ostream& os, const list<MSLNode*> & nl);
00057 
00058   friend class MSLTree;
00059 };
00060 
00061 
00063 class MSLNodeLess {
00064  public:
00065   bool operator() (MSLNode* p, MSLNode* q) const {
00066     return p->Cost() < q->Cost();
00067   }
00068 };
00069 
00070 
00072 class MSLNodeGreater {
00073  public:
00074   bool operator() (MSLNode* p, MSLNode* q) const {
00075     return p->Cost() > q->Cost();
00076   }
00077 };
00078 
00079 
00080 class MSLTree {
00081  private:
00082   list<MSLNode*> nodes;
00083   MSLNode* root;
00084   int size;
00085  public:
00086 
00087   MSLTree();
00088   MSLTree(const MSLVector &x); // Argument is state of root node
00089   ~MSLTree();
00090 
00091   void MakeRoot(const MSLVector &x);
00092   MSLNode* Extend(MSLNode *parent, const MSLVector &x, const MSLVector &u);
00093   MSLNode* Extend(MSLNode *parent, const MSLVector &x, const MSLVector &u, 
00094                   double time);
00095   list<MSLNode*> PathToRoot(MSLNode *n);
00096   MSLNode* FindNode(int nid);
00097   inline list<MSLNode*> Nodes() const { return nodes; };
00098   inline MSLNode* Root() {return root; };
00099   inline int Size() {return size;}
00100 
00101   void Clear();
00102 
00103   friend istream& operator>> (istream& is, MSLTree& n);
00104   friend ostream& operator<< (ostream& os, const MSLTree& n);
00105 };
00106 
00107 #endif
00108 
Motion Strategy Library


Web page maintained by Steve LaValle
Partial support provided by NSF CAREER Award IRI-970228 (LaValle), Honda Research, and Iowa State University.
Contributors: Anna Atramentov, Peng Cheng, James Kuffner, Steve LaValle, and Libo Yang.