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

graph.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 
00020 #ifndef MSL_GRAPH_H
00021 #define MSL_GRAPH_H
00022 
00023 //#include <list.h>
00024 //#include <string>
00025 
00026 #include "vector.h"
00027 #include "mslio.h"
00028 
00029 class MSLEdge;
00030 
00031 class MSLVertex {
00032  private:
00033   MSLVector state;
00034   double cost;
00035   list<MSLEdge*> edges;
00036   int id;
00037   bool mark;
00038 
00039  public:
00041   MSLVector State() const {return state; };
00042 
00044   inline list<MSLEdge*> Edges() const {return edges; };
00045 
00047   inline double Cost() const {return cost; };
00048 
00050   inline void SetCost(const double &x) {cost = x; };
00051 
00053   inline void SetID(const int &i) {id = i; };
00054 
00056   inline int ID() const {return id; };
00057 
00059   inline void Mark() {mark = true; };
00060 
00062   inline void Unmark() {mark = false; };
00063 
00065   inline bool IsMarked() const {return mark; };
00066 
00067   MSLVertex();
00068   MSLVertex(const MSLVector &x);
00069   ~MSLVertex();
00070 
00071   //MSLVertex& operator=(const MSLVertex& n);
00072   friend istream& operator>> (istream& is, MSLVertex& n) { return is; };
00073   friend ostream& operator<< (ostream& os, const MSLVertex& n);
00074   //friend istream& operator>> (istream& is, list<MSLVertex*> & nl);
00075   //friend ostream& operator<< (ostream& os, const list<MSLVertex*> & nl);
00076 
00077   friend class MSLEdge;
00078   friend class MSLGraph;
00079 };
00080 
00081 //istream& operator>> (istream& is, MSLVertex& n) { return is; };
00082 //ostream& operator<< (ostream& os, const MSLVertex& n);
00083 
00084 
00085 class MSLEdge {
00086  private:
00087   MSLVector input;
00088   MSLVertex* source;
00089   MSLVertex* target;
00090   double time;
00091   double cost;
00092  public:
00093   MSLEdge();
00094   MSLEdge(MSLVertex* v1, MSLVertex* v2, 
00095           const MSLVector &u, double t);
00096   MSLEdge(MSLVertex* v1, MSLVertex* v2, double t);
00097   MSLEdge(MSLVertex* v1, MSLVertex* v2);
00098   ~MSLEdge() {};
00099 
00101   inline double Time() const {return time; };
00102 
00104   inline double Cost() const {return cost; };
00105 
00107   inline void SetCost(const double &x) {cost = x; };
00108 
00110   inline MSLVector Input() const {return input; };
00111 
00113   inline MSLVertex* Source() const {return source; };
00114 
00116   inline MSLVertex* Target() const {return target; };
00117 
00118   //MSLEdge& operator=(const MSLEdge& n);
00119   friend istream& operator>> (istream& is, MSLEdge& e) { return is; };
00120   friend ostream& operator<< (ostream& os, const MSLEdge& e);
00121 };
00122 
00123 ostream& operator<< (ostream& os, const MSLEdge& e);
00124 
00125 
00127 class MSLVertexLess {
00128  public:
00129   bool operator() (MSLVertex* p, MSLVertex* q) const {
00130     return p->Cost() < q->Cost();
00131   }
00132 };
00133 
00134 
00136 class MSLVertexGreater {
00137  public:
00138   bool operator() (MSLVertex* p, MSLVertex* q) const {
00139     return p->Cost() > q->Cost();
00140   }
00141 };
00142 
00143 
00144 class MSLGraph {
00145  private:
00146   list<MSLVertex*> vertices;
00147   list<MSLEdge*> edges;
00148   int numvertices;
00149   int numedges;
00150  public:
00151 
00152   MSLGraph();
00153   virtual ~MSLGraph();
00154 
00155   MSLVertex* AddVertex(const MSLVector &x);
00156   MSLEdge* AddEdge(MSLVertex* v1, MSLVertex* v2);
00157   MSLEdge* AddEdge(MSLVertex* v1, MSLVertex* v2, double time);
00158   MSLEdge* AddEdge(MSLVertex* v1, MSLVertex* v2, 
00159                    const MSLVector &u, double time);
00160   bool IsEdge(MSLVertex* v1, MSLVertex* v2);
00161   MSLVertex* FindVertex(int nid);
00162   inline list<MSLVertex*> Vertices() const { return vertices; };
00163   inline list<MSLEdge*> Edges() const { return edges; };
00164   inline int Size() {return numvertices+numedges;}
00165   inline int NumVertices() const {return numvertices;}
00166   inline int NumEdges() const {return numedges;}
00167 
00168   void Clear();
00169 
00170   //MSLGraph& operator=(const MSLGraph& n);
00171   friend istream& operator>> (istream& is, MSLGraph& n);
00172   friend ostream& operator<< (ostream& os, const MSLGraph& n);
00173 };
00174 
00175 istream& operator>> (istream& is, MSLGraph& n);
00176 ostream& operator<< (ostream& os, const MSLGraph& n);
00177 
00178 #endif
Motion Strategy Library


Web page maintained by Steve LaValle