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;
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;
00062 MatrizInt matriz_pesos;
00063 std::vector<CorVertice> cores;
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
00123
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
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
00174
00175
00176
00177
00178
00179
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 };
00206
00207
00208 #endif