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

tree.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------
00002 //               The Motion Strategy Library (MSL)
00003 //----------------------------------------------------------------------
00004 //
00005 // Copyright (c) University of Illinois and Steven M. LaValle.     
00006 // All Rights Reserved.
00007 //
00008 // Permission to use, copy, and distribute this software and its
00009 // documentation is hereby granted free of charge, provided that
00010 // (1) it is not a component of a commercial product, and
00011 // (2) this notice appears in all copies of the software and
00012 //     related documentation.
00013 //
00014 // The University of Illinois and the author make no representations
00015 // about the suitability or fitness of this software for any purpose.
00016 // It is provided "as is" without express or implied warranty.
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   //void ClearInfo() {if (!info) delete (MSLNodeInfo *) info; };
00077   //NOTE: Above incorrect design - shouldn't type the void* here
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(); /*ClearInfo();*/ };
00085 
00086   inline void AddChild(MSLNode *cn) { children.push_back(cn); }
00087 
00088   //friend istream& operator>> (istream& is, MSLNode& n);
00089   friend ostream& operator<< (ostream& os, const MSLNode& n);
00090   //friend istream& operator>> (istream& is, list<MSLNode*> & nl);
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); // Argument is state of root node
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 
Motion Strategy Library


Web page maintained by Steve LaValle