Esta página mostra as diferenças entre as duas revisões da página.
| Ambos os lados da revisão anterior Revisão anterior Próxima revisão | Revisão anterior | ||
|
inf05504:2012-2-trabalhos [2012/10/22 13:38] marcus [Trabalho 3 (Fluxo s-t máximo)] |
inf05504:2012-2-trabalhos [2013/01/13 09:01] (Actual) marcus [Entregas] |
||
|---|---|---|---|
| Linha 1: | Linha 1: | ||
| ==== Entregas ==== | ==== Entregas ==== | ||
| - | Atualizado: 02/10/2012 | + | Atualizado: 13/01/2012 |
| ^ No. ^ T1 ^ T2 ^ T3 ^ T4 ^ T5 ^ | ^ No. ^ T1 ^ T2 ^ T3 ^ T4 ^ T5 ^ | ||
| | 118489 | - | - | - | - | - | | | 118489 | - | - | - | - | - | | ||
| - | | 136830 | - | - | - | - | - | | + | | 136830 | P | - | - | - | - | |
| - | | 150821 | - | - | - | - | - | | + | | 150821 | P | - | P | - | P | |
| - | | 152985 | - | - | - | - | - | | + | | 152985 | P | P | P | P | P | |
| - | | 159847 | P | - | - | - | - | | + | | 159847 | P | P | P | R | P | |
| - | | 160636 | P | - | - | - | - | | + | | 160636 | P | P | P | - | P | |
| - | | 173362 | P | - | - | - | - | | + | | 173362 | P | R | - | - | P | |
| | 180190 | - | - | - | - | - | | | 180190 | - | - | - | - | - | | ||
| | 181026 | - | - | - | - | - | | | 181026 | - | - | - | - | - | | ||
| Linha 134: | Linha 134: | ||
| === Observações === | === Observações === | ||
| - | * Para poder utilizar a árvore de van Emde Boas em grafos com distâncias grandes (que são as prioridades), vocês tem que implementar a versão "esparsa" descrito no livro do Cormen, no exercício 20.1, que substitui o vetor "cluster" por uma tabela hash e precisa memoria proporcional ao número de elementos inseridos. (Em C++ vocês podem usar um unordered_map para e tabela hash.) | + | * Para poder utilizar a árvore de van Emde Boas em grafos com distâncias grandes (que são as prioridades), vocês tem que implementar a versão "esparsa" descrito no livro do Cormen, no exercício 20.1, que substitui o vetor "cluster" (chamado "bottom" nas notas de aula) por uma tabela hash e precisa memoria proporcional ao número de elementos inseridos. (Em C++ vocês podem usar um unordered_map para e tabela hash.) |
| Linha 200: | Linha 200: | ||
| /** | /** | ||
| * \file maxflow.cpp | * \file maxflow.cpp | ||
| - | * \author Marcus Ritt <mrpritt@inf.ufrgs.br> | + | * \author Marcus Ritt <mrpritt@inf.ufrgs.br> |
| * \version $Id: emacs 2872 2009-01-31 01:46:50Z ritt $ | * \version $Id: emacs 2872 2009-01-31 01:46:50Z ritt $ | ||
| - | * \date Time-stamp: <2009-03-23 17:52:25 ritt> | + | * \date Time-stamp: <2012-12-06 17:10:05 ritt> |
| * | * | ||
| * Read a maximum flow problem in DIMACS format and output the maximum flow. | * Read a maximum flow problem in DIMACS format and output the maximum flow. | ||
| Linha 213: | Linha 213: | ||
| #include <boost/graph/adjacency_list.hpp> | #include <boost/graph/adjacency_list.hpp> | ||
| #include <boost/graph/read_dimacs.hpp> | #include <boost/graph/read_dimacs.hpp> | ||
| - | #include <boost/graph/edmunds_karp_max_flow.hpp> | + | #include <boost/graph/edmonds_karp_max_flow.hpp> |
| + | #include <boost/graph/push_relabel_max_flow.hpp> | ||
| using namespace boost; | using namespace boost; | ||
| + | |||
| + | // graph element descriptors | ||
| + | typedef adjacency_list_traits<vecS,vecS,directedS>::vertex_descriptor DiNode; | ||
| + | typedef adjacency_list_traits<vecS,vecS,directedS>::edge_descriptor Edge; | ||
| // a directed graph with reverse edges | // a directed graph with reverse edges | ||
| struct VertexInformation {}; | struct VertexInformation {}; | ||
| - | struct EdgeInformation; | ||
| - | |||
| - | typedef adjacency_list<vecS,vecS,directedS,VertexInformation,EdgeInformation> DiGraph; | ||
| - | typedef graph_traits<DiGraph>::edge_descriptor Edge; | ||
| - | typedef graph_traits<DiGraph>::vertex_descriptor DiNode; | ||
| - | |||
| typedef unsigned Capacity; | typedef unsigned Capacity; | ||
| struct EdgeInformation { | struct EdgeInformation { | ||
| Linha 231: | Linha 229: | ||
| Edge reverse_edge; | Edge reverse_edge; | ||
| }; | }; | ||
| + | |||
| + | typedef adjacency_list<vecS,vecS,directedS,VertexInformation,EdgeInformation> DiGraph; | ||
| int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | ||
| Linha 237: | Linha 237: | ||
| DiGraph g; | DiGraph g; | ||
| DiNode s,t; | DiNode s,t; | ||
| + | | ||
| read_dimacs_max_flow(g, | read_dimacs_max_flow(g, | ||
| get(&EdgeInformation::edge_capacity,g), | get(&EdgeInformation::edge_capacity,g), | ||
| get(&EdgeInformation::reverse_edge,g), | get(&EdgeInformation::reverse_edge,g), | ||
| s, t); | s, t); | ||
| + | | ||
| // (1) determine maximum flow | // (1) determine maximum flow | ||
| - | cout << edmonds_karp_max_flow(g, s, t, | + | cout << push_relabel_max_flow(g, s, t, |
| capacity_map(get(&EdgeInformation::edge_capacity,g)). | capacity_map(get(&EdgeInformation::edge_capacity,g)). | ||
| residual_capacity_map(get(&EdgeInformation::edge_residual_capacity,g)). | residual_capacity_map(get(&EdgeInformation::edge_residual_capacity,g)). | ||
| Linha 252: | Linha 252: | ||
| + | |||
| + | |||
| + | ==== Trabalho 4 (Emparelhamentos) ==== | ||
| + | |||
| + | Entrega: 16/11/2009 | ||
| + | |||
| + | === Objetivos === | ||
| + | * Implementar o algoritmo de Hopcroft/Karp que resolve o problema do emparelhamento máximo em grafos bi-partidos. | ||
| + | * Documentar a implementação, em particular as estruturas de dados para a representação do problema. | ||
| + | * Conduzir testes, que demonstram que a complexidade do algoritmo é O(sqrt(n)m). | ||
| + | |||
| + | === Casos de teste === | ||
| + | * Gerar grafos bi-partidos randômicas com probabilidade de uma aresta 0 <= p <= 1. | ||
| + | |||
| + | === Convenções === | ||
| + | * As implementações do algoritmo devem aceitar um grafo bi-partido não-direcionado no formato [[http://prolland.free.fr/works/research/dsat/dimacs.html|DIMACS]] na entrada padrão (stdin) e imprimir a cardinalidade de um emparelhamento máximo na saída padrão (stdout). | ||
| + | |||
| + | === Códigos disponíveis === | ||
| + | * Gerador de casos de teste no formato DIMACS + verificação. | ||
| + | * Para compilar: Usar C++ e Boost. | ||
| + | <code c++> | ||
| + | #include <iostream> | ||
| + | #include <cassert> | ||
| + | using namespace std; | ||
| + | |||
| + | #include <boost/graph/adjacency_list.hpp> | ||
| + | #include <boost/graph/max_cardinality_matching.hpp> | ||
| + | using namespace boost; | ||
| + | |||
| + | // graph element descriptors | ||
| + | typedef adjacency_list_traits<vecS,vecS,undirectedS>::vertex_descriptor Node; | ||
| + | typedef adjacency_list_traits<vecS,vecS,undirectedS>::edge_descriptor Edge; | ||
| + | |||
| + | // information stored in vertices | ||
| + | struct VertexInformation { | ||
| + | Node mate; // partner or graph_traits<Graph>::null_vertex() | ||
| + | }; | ||
| + | // information stored in edges | ||
| + | struct EdgeInformation {}; | ||
| + | |||
| + | // graph is an adjacency list represented by vectors | ||
| + | typedef adjacency_list<vecS,vecS,undirectedS,VertexInformation,EdgeInformation> Graph; | ||
| + | |||
| + | int main(int argc, char *argv[]) { | ||
| + | assert(argc == 3); | ||
| + | unsigned n = atoi(argv[1]); | ||
| + | double p = atof(argv[2]); | ||
| + | |||
| + | srand48(time(0)); | ||
| + | | ||
| + | // (1) generate random bi-partite graph | ||
| + | Graph g; | ||
| + | | ||
| + | for(unsigned i=0; i<2*n; i++) | ||
| + | add_vertex(g); | ||
| + | | ||
| + | for(unsigned i=0; i<n; i++) | ||
| + | for(unsigned j=n; j<2*n; j++) | ||
| + | if (drand48() < p) { | ||
| + | Edge e = add_edge(i,j,g).first; | ||
| + | } | ||
| + | |||
| + | // (2) get maximum matching | ||
| + | edmonds_maximum_cardinality_matching(g, get(&VertexInformation::mate,g)); | ||
| + | unsigned card = 0; | ||
| + | graph_traits<Graph>::vertex_iterator vb, ve; | ||
| + | for ( tie(vb, ve)=vertices(g); vb != ve; vb++) | ||
| + | if (g[*vb].mate != graph_traits<Graph>::null_vertex()) | ||
| + | card++; | ||
| + | //cout << "The cardinality of a maximum matching is " << card/2 << "." << endl; | ||
| + | | ||
| + | // (3) print out in DIMACS format | ||
| + | cout << "c Bi-partite graph" << endl << endl; | ||
| + | cout << "p edge " << num_vertices(g) << " " << num_edges(g) << endl; | ||
| + | graph_traits<Graph>::edge_iterator eb, ee; | ||
| + | for ( tie(eb, ee)=edges(g); eb != ee; eb++) | ||
| + | cout << "e " << source(*eb,g)+1 << " " << target(*eb, g)+1 << endl; | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | |||
| + | ==== Trabalho 5 (Hashing) ==== | ||
| + | |||
| + | Entrega: 12/12/2012 | ||
| + | |||
| + | === Objetivos === | ||
| + | * Implementar tabelas hash com resolução de colisões com encadeamento, com endereçamento aberto e com cuco hashing. | ||
| + | * Escolher funções hash adequadas. | ||
| + | * Conduzir testes, que determinam a complexidade média (amortizada) das operações insert e lookup para diferentes fatores de ocupação. | ||
| + | |||
| + | === Casos de teste === | ||
| + | * Conjuntos de chaves aleatórias. | ||
| + | |||
| + | === Convenções === | ||
| + | * As implementações do algoritmo devem aceitar um arquivo na entrada padrão (stdin) que informa na primeira linha | ||
| + | <code> | ||
| + | n m | ||
| + | </code> | ||
| + | o número de inserções n e o número de consultas m, seguido por n linhas que contém um número inteiro que | ||
| + | representa uma chave a inserir e m linhas que contém um número inteiro que representa uma consulta. O algoritmo deve imprimir na saida padrão (stdout) m linhas que contém o resultado dos m lookups: 0 para uma chave que não pertence a tabela hash, e 1 caso contrário. | ||