00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef GRAPH_H
00019 #define GRAPH_H
00020
00021 #include "nommgr.h"
00022 #include <vector>
00023 #include "mmgr.h"
00024
00030 class Graph;
00031 class Edge;
00032 class Connection;
00033 class Vertex;
00034
00035 class Graph {
00036 friend class Edge;
00037 friend class Connection;
00038 private:
00039 public:
00040 Graph();
00041 virtual ~Graph();
00042
00043 public:
00044 unsigned int getVertexCount() const;
00045 Vertex * getVertex(unsigned int index) const;
00046 int getVertexIndex (Vertex * aVertex) const;
00047 unsigned int getConnectionCount() const;
00048 unsigned int getConnectionCount(unsigned int index1,unsigned int index2) const;
00049 Connection * getConnection(unsigned int index1,unsigned int index2) const;
00050 Connection * getConnection(unsigned int index1,unsigned int index2,unsigned int index3) const;
00051 Connection * getConnection(unsigned int index) const;
00052 int getConnectionIndex (Connection * aConnection) const;
00053 unsigned int getEdgeCount() const;
00054 Edge * getEdge(unsigned int index1,unsigned int index2) const;
00055 Edge * getEdge(unsigned int index) const;
00056 int getEdgeIndex (Edge * anEdge) const;
00057
00058 void virtual printVertices() const;
00059 void virtual printEdges() const;
00060 void virtual printConnections() const;
00061 void virtual printAdjacencyMatrix() const;
00062 void virtual printConnectedComponentID() const;
00063 void virtual print();
00064
00065 void addVertex (Vertex * aVertex);
00066 void removeVertex (Vertex * aVertex);
00067 void insertConnection (Connection* Connection);
00068 void removeConnection (Connection* Connection);
00069
00070 void computeConnectedComponent();
00071 void computeConnectedComponent(unsigned int vertexIndex);
00072 void setBaseConnectedComponent(unsigned int vertexIndex);
00073 unsigned int getConnectedComponentCount() const;
00074 bool isConnected(unsigned int vertexIndex, unsigned int anotherVertexIndex) const;
00075 unsigned int getConnectedComponentCard(unsigned int connectedComponentIndex) const;
00076
00077
00078
00079
00080 bool hasMultipleConnections() const;
00081 virtual void destroyGraph(Graph * aGraph)=0;
00082 virtual Graph * createGraph ()=0;
00083 class adjIterator;
00084 class ConnectedComponent;
00085
00086 protected:
00087 std::vector<Vertex *> vertices;
00088 unsigned int vertexCount;
00089 std::vector<std::vector <Connection *> > adj;
00090 unsigned int connectionCount;
00091 unsigned int edgeCount;
00092 std::vector<int> connectedComponentID;
00093 int connectedComponentCount;
00094
00095
00096 friend class Graph::adjIterator;
00097
00098 };
00099
00100 class Graph::adjIterator
00101 {
00102 private :
00103 const Graph * G;
00104 int i,v;
00105 public :
00106 adjIterator(const Graph * G, int v);
00107 int beg ();
00108 int nxt ();
00109 bool end ();
00110
00111 };
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 class Connection {
00155 class Edge;
00156 friend class Edge;
00157 friend class Graph;
00158 protected :
00159 Graph * graph;
00160 Vertex * vertex1;
00161 Vertex * vertex2;
00162 public :
00163 Connection(Vertex * aVertex, Vertex * anotherVertex);
00164 virtual ~Connection();
00165 virtual unsigned int getConnectionCount() const;
00166 virtual int getConnectionIndex (Connection * aConnection) const;
00167 virtual void print() const;
00168 virtual Connection * getConnection(unsigned int index);
00169 virtual void swap()=0;
00170 Graph * getGraph() const;
00171 Vertex * getVertex1() const;
00172 Vertex * getVertex2() const;
00173 protected:
00174 void setGraph(Graph * aGraph);
00175 };
00176
00177 class Edge : public Connection {
00178 friend class Graph;
00179 friend class Connection;
00180 public:
00181 Edge(Vertex * aVertex, Vertex * anotherVertex);
00182 ~Edge();
00183 Vertex * vertex1;
00184 Vertex * vertex2;
00185 Graph * graph;
00186 std::vector<Connection*> connections;
00187 Connection * getConnection(unsigned int index);
00188 int getConnectionIndex (Connection * aConnection) const;
00189 unsigned int getConnectionCount() const;
00190 void addConnection(Connection * aConnection);
00191 void removeConnection(Connection * Connection);
00192 void print() const;
00193 void swap();
00194 };
00195
00196
00197 class Vertex {
00198 friend class Graph;
00199 friend class Connection;
00200 protected :
00201 Graph * graph;
00202 public :
00203 Vertex();
00204 Graph * getGraph() const;
00205 void setGraph(Graph * aGraph);
00206 virtual ~Vertex();
00207 virtual void print()=0;
00208 };
00209
00210
00211
00212
00213
00214 class TestC;
00215 class TestV;
00216 class TestG;
00217
00218 class TestV : public Vertex
00219 {
00220 public :
00221 int ID;
00222 std::vector<TestC *> testCs;
00223
00224 TestV();
00225 ~TestV();
00226
00227 void print() ;
00228 void connect(TestV * aTestV);
00229 void disconnect();
00230 };
00231
00232 class TestC : public Connection
00233 {
00234 public :
00235 int ID;
00236 TestC(TestV * t1, TestV * t2);
00237 void print() const ;
00238 void swap();
00239 };
00240
00241 class TestG : public Graph
00242 {
00243 public :
00244 int ID;
00245 TestG();
00246 ~TestG();
00247 virtual void destroyGraph(Graph * aGraph);
00248 virtual Graph * createGraph () ;
00249 void print() ;
00250 };
00251
00252 #endif
00253