00001 #ifndef MSL_GRAPH_H 00002 #define MSL_GRAPH_H 00003 00004 #include <list.h> 00005 #include <string> 00006 00007 #include "graph.h" 00008 #include "vector.h" 00009 00010 class MSLEdge; 00011 00012 class MSLVertex { 00013 private: 00014 MSLVector state; 00015 double cost; 00016 list<MSLEdge*> edges; 00017 int id; 00018 bool mark; 00019 00020 public: 00022 MSLVector State() const {return state; }; 00023 00025 inline list<MSLEdge*> const Edges() {return edges; }; 00026 00028 inline double Cost() const {return cost; }; 00029 00031 inline void SetCost(const double &x) {cost = x; }; 00032 00034 inline void SetID(const int &i) {id = i; }; 00035 00037 inline int ID() const {return id; }; 00038 00040 inline void Mark() {mark = true; }; 00041 00043 inline void Unmark() {mark = false; }; 00044 00046 inline bool IsMarked() {return mark; }; 00047 00048 MSLVertex(); 00049 MSLVertex(const MSLVector &x); 00050 ~MSLVertex(); 00051 00052 friend istream& operator>> (istream& is, MSLVertex& n) { return is; }; 00053 friend ostream& operator<< (ostream& os, const MSLVertex& n); 00054 friend istream& operator>> (istream& is, list<MSLVertex*> & nl); 00055 friend ostream& operator<< (ostream& os, const list<MSLVertex*> & nl); 00056 00057 friend class MSLEdge; 00058 friend class MSLGraph; 00059 }; 00060 00061 00062 00063 class MSLEdge { 00064 private: 00065 MSLVector input; 00066 MSLVertex* source; 00067 MSLVertex* target; 00068 double time; 00069 double cost; 00070 public: 00071 MSLEdge(); 00072 MSLEdge(MSLVertex* v1, MSLVertex* v2, 00073 const MSLVector &u, double t); 00074 MSLEdge(MSLVertex* v1, MSLVertex* v2, double t); 00075 MSLEdge(MSLVertex* v1, MSLVertex* v2); 00076 ~MSLEdge() {}; 00077 00079 inline double Time() {return time; }; 00080 00082 inline double Cost() {return cost; }; 00083 00085 inline void SetCost(const double &x) {cost = x; }; 00086 00088 inline MSLVector Input() {return input; }; 00089 00091 inline MSLVertex* Source() {return source; }; 00092 00094 inline MSLVertex* Target() {return target; }; 00095 00096 friend istream& operator>> (istream& is, MSLEdge& e) { return is; }; 00097 friend ostream& operator<< (ostream& os, const MSLEdge& e); 00098 }; 00099 00100 00102 class MSLVertexLess { 00103 public: 00104 bool operator() (MSLVertex* p, MSLVertex* q) const { 00105 return p->Cost() < q->Cost(); 00106 } 00107 }; 00108 00109 00111 class MSLVertexGreater { 00112 public: 00113 bool operator() (MSLVertex* p, MSLVertex* q) const { 00114 return p->Cost() > q->Cost(); 00115 } 00116 }; 00117 00118 00119 class MSLGraph { 00120 private: 00121 list<MSLVertex*> vertices; 00122 list<MSLEdge*> edges; 00123 int numvertices; 00124 int numedges; 00125 public: 00126 00127 MSLGraph(); 00128 ~MSLGraph(); 00129 00130 MSLVertex* AddVertex(const MSLVector &x); 00131 MSLEdge* AddEdge(MSLVertex* v1, MSLVertex* v2); 00132 MSLEdge* AddEdge(MSLVertex* v1, MSLVertex* v2, double time); 00133 MSLEdge* AddEdge(MSLVertex* v1, MSLVertex* v2, 00134 const MSLVector &u, double time); 00135 bool IsEdge(MSLVertex* v1, MSLVertex* v2); 00136 MSLVertex* FindVertex(int nid); 00137 inline list<MSLVertex*> const Vertices() { return vertices; }; 00138 inline list<MSLEdge*> const Edges() { return edges; }; 00139 inline int Size() {return numvertices+numedges;} 00140 inline int NumVertices() {return numvertices;} 00141 inline int NumEdges() {return numedges;} 00142 00143 void Clear(); 00144 00145 friend istream& operator>> (istream& is, MSLGraph& n); 00146 friend ostream& operator<< (ostream& os, const MSLGraph& n); 00147 }; 00148 00149 #endif 00150