Main Page   Class Hierarchy   Compound List   File List   Compound Members  

Grafo.h

00001 #ifndef GRAFO_H
00002 #define GRAFO_H 1
00003 
00004 #include <vector>
00005 #include <string>
00006 #include <utility>
00007 #include <stdexcept>
00008 
00009 
00010 typedef std::pair<int,int> Aresta;
00011 typedef int Vertice;                            // Ma' nem pens'em redefini'ssa'qui
00012 typedef std::vector<Vertice> ListaVertices;
00013 typedef std::vector<Aresta> ListaArestas;
00014 typedef std::vector<Vertice>::const_iterator ListaVerticesCIterator;
00015 typedef std::vector<Aresta>::const_iterator ListaArestasCIterator;
00016 typedef std::vector<std::vector<bool> > MatrizBool;
00017 typedef std::vector<std::vector<int> > MatrizInt;
00018 
00019 enum CorVertice {branco,cinza,preto};
00020 
00022 class ErroGrafo{
00023         std::string descricao;  
00024 public:
00026 
00029         ErroGrafo(const std::string descricao="Erro na operação com grafos"){
00030                 this->descricao = descricao;
00031         }
00032         const std::string& getDescription(){ return descricao;}
00033 };
00034 
00035 class ArestaDuplicada: public ErroGrafo {
00036         public:
00037         ArestaDuplicada(const std::string descricao="Aresta Duplicada"): ErroGrafo(descricao){};
00038 };
00039 
00040 class ArestaDesconhecida: public ErroGrafo {
00041         public:
00042         ArestaDesconhecida(const std::string descricao="Aresta Desconhecida"): ErroGrafo(descricao){};
00043 };
00044 
00045 class VerticeDesconhecido: public ErroGrafo {
00046         public:
00047         VerticeDesconhecido(const std::string descricao="Vértice Desconhecido"): ErroGrafo(descricao){};
00048 
00049 };
00050 
00051 
00052         
00054 
00058 class Grafo {
00059 
00060         int n;
00061         MatrizBool matriz_adj;  // matriz de adj. - eta complicação
00062         MatrizInt matriz_pesos; // matriz com o peso das arestas
00063         std::vector<CorVertice> cores;             // vetor com as cores dos vertices
00064 
00068         const Aresta mapeiaTriangular(Vertice u, Vertice v);
00069         const Aresta mapeiaTriangular(Aresta e);
00070         
00072         void insAresta(Vertice u, Vertice v) throw (VerticeDesconhecido);
00073 
00075         void delAresta(Vertice u, Vertice v) throw (VerticeDesconhecido);
00076 
00077         
00078         
00080 
00084         int getAresta(Vertice u, Vertice v) throw(ArestaDesconhecida,VerticeDesconhecido);
00085 
00087 
00091         void setAresta(Vertice u, Vertice v,int peso) throw (ArestaDesconhecida,VerticeDesconhecido);
00092 public:
00093         
00095 
00098         Grafo(int n=10);
00099         
00101         int numeroVertices();
00102 
00104 
00110         bool existeAresta(Vertice u, Vertice v) throw (VerticeDesconhecido);
00111 
00113 
00118         bool existeAresta(Aresta e) throw (VerticeDesconhecido);
00119 
00120 
00121         /* 
00122         ListaVerticesCIterator listaVertices(){
00123                 return this.m
00124         }*/
00125         
00127         ListaVertices& listaAdjacencia(Vertice vertice);
00128         
00130         ListaArestas& listaArestas();
00131         
00133 
00138         void insereAresta(Vertice u, Vertice v, int peso=1) throw(ArestaDuplicada,VerticeDesconhecido) ;
00139 
00140         
00142 
00147         void removeAresta(Vertice u, Vertice v) throw (ArestaDuplicada,VerticeDesconhecido);
00148 
00149         
00151         /*
00152             Caso ela não exista, uma exception é lancada.
00153          */
00154         int obtemAresta(Vertice u, Vertice v)  throw(ArestaDesconhecida,VerticeDesconhecido);   
00156 
00160         void modificaAresta(Vertice u, Vertice v, int peso) throw(ArestaDesconhecida,VerticeDesconhecido);                      
00161         
00163         void setCor(Vertice vertice,CorVertice cor) throw (VerticeDesconhecido);
00164 
00166         const CorVertice getCor(Vertice vertice) throw (VerticeDesconhecido);
00167 
00169         void imprimeMatrizAdj();
00170         
00171         /*
00173         def copy(self):
00174                 g=Grafo(self.__n)
00175                 for e in self.listaArestas():
00176                         u,v=e
00177                         g.insereAresta(u,v,self.obtemAresta(u,v))
00178                 return g
00179         
00181         +*  E se não existir aresta nenhuma?!
00182         def obtemMaiorAresta(self):
00183                 
00184                 arestas=self.listaArestas()
00185                 maior=None
00186                 
00187                 if len(arestas) == 0 :
00188                         return None
00189 
00190                 # Obtem um valor inicial para 'maior'
00191                 e=arestas.pop()
00192                 u,v=e
00193                 maior=self.obtemAresta(u,v)
00194                 
00195                 for e in arestas:
00196                         u,v=e
00197                         valor=self.obtemAresta(u,v)
00198                         if valor > maior:
00199                                 maior = valor
00200 
00201                 return maior
00202         */      
00203                 
00204                 
00205 };      
00206 
00207 
00208 #endif

Generated on Tue Jun 24 09:16:23 2003 for Trabalho #2 de PAA by doxygen1.2.18