Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Composants | Déclarations

Graph.h

Aller à la documentation de ce fichier.
00001 /***************************************************************************
00002                           Graph.h  -  description
00003                              -------------------
00004     begin                : sam jui 26 2003
00005     copyright            : (C) 2003 by Michel DUBOIS, Yann Le Guyadec 
00006     email                : Michel.Dubois@univ-ubs.fr, Yann.Le-Guyadec@univ-ubs.fr 
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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 //    void            adjItInit(unsigned int vertexIndex) ;
00077 //    int             adjItBeg() ;
00078 //    int             adjItNext() ;
00079 //    bool            adjItEnd() const;
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 //    int adjItPos;
00095 //    int adjItVertex;
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 class Graph::ConnectedComponent
00115 {
00116   private :
00117     const Graph * G;
00118     int ccnt;
00119     std::vector <int> id;
00120     void ccR(int w)
00121     {
00122       id[w]=ccnt;
00123       Graph::adjIterator it=Graph::adjIterator(G,w);
00124       
00125       for (int v=it.beg();!it.end();v=it.nxt())
00126       {
00127         printf("ccR(%i)->CCID[%i]=%i : info CCID[%i]=%i\n",w,w,id[w],v,id[v]);
00128         if (id[v]==-1)
00129           ccR(v);
00130       }  
00131     }
00132   public :
00133   ConnectedComponent(const Graph * G) : G(G), ccnt(0), id(G->getVertexCount(),-1)
00134   {
00135     for (int v=0; v<G->getVertexCount();v++)
00136       if (id[v]==-1)
00137       {
00138         ccR(v);
00139         ccnt++;
00140       }  
00141   }
00142   int count() const
00143   {
00144       return ccnt;
00145   }
00146   bool connect(int s,int t) const
00147   {
00148     return id[s]==id[t];
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  * Classes de test
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 

Généré le Mon Mar 1 01:29:41 2004 par doxygen 1.3.3