From f79f11ac9ed01dc85b2e8e3f4c7574c79e5170ee Mon Sep 17 00:00:00 2001 From: Vytor Calixto <vytorcalixto@gmail.com> Date: Mon, 15 May 2017 09:59:47 -0300 Subject: [PATCH] =?UTF-8?q?Add=20fun=C3=A7=C3=A3o=20para=20imprimir=20graf?= =?UTF-8?q?o=20em=20formato=20.dot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + libs/grafo.c | 21 +++++++++++++++++++++ libs/grafo.h | 3 +++ main.c | 10 +++++++++- tests/runTests.sh | 4 ++-- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index fb87ea4..0b30b8a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ test tests/*.txt tests/*.png massif.out* +*.out diff --git a/libs/grafo.c b/libs/grafo.c index d3f4729..45d0ad8 100644 --- a/libs/grafo.c +++ b/libs/grafo.c @@ -3,6 +3,7 @@ #include "lista.h" #include "vertice.h" #include "tabuleiro.h" +#include <stdio.h> Grafo criaGrafo() { Grafo g = malloc(sizeof(struct Grafo)); @@ -117,3 +118,23 @@ void destroiGrafo(Grafo g) { g = NULL; return; } + +void grafoParaDot(Grafo g, Lista grupo, FILE* fp) { + fprintf(fp, "strict graph g {\n"); + // Pinta os nós que estão no grupo de vermelho + for(No n = primeiroNoLista(grupo); n; n = getSucessorNo(n)) { + Vertice v = (Vertice) getConteudo(n); + fprintf(fp, "\t\"%p\" [color=red];\n", v); + } + // Imprime o grafo + for(No n = primeiroNoLista(g->vertices); n; n = getSucessorNo(n)) { + Vertice pai = (Vertice) getConteudo(n); + fprintf(fp, "\t\"%p\" [label=\"cor=%d,peso=%d\"];\n", pai, pai->cor, pai->peso); + for(No m = primeiroNoLista(pai->filhos); m; m = getSucessorNo(m)) { + Vertice filho = (Vertice) getConteudo(m); + fprintf(fp, "\t\"%p\" [label=\"cor=%d,peso=%d\"];\n", filho, filho->cor, filho->peso); + fprintf(fp, "\t\"%p\" -- \"%p\";\n", pai, filho); + } + } + fprintf(fp, "}\n"); +} diff --git a/libs/grafo.h b/libs/grafo.h index cd6a6ab..90f1489 100644 --- a/libs/grafo.h +++ b/libs/grafo.h @@ -1,6 +1,7 @@ #ifndef _GRAFO_ #define _GRAFO_ #include "tabuleiro.h" +#include <stdio.h> struct Grafo { Lista vertices; @@ -18,4 +19,6 @@ void tabuleiroParaGrafo(Tblr t, Grafo g); void destroiGrafo(Grafo g); +void grafoParaDot(Grafo g, Lista grupo, FILE* fp); + #endif diff --git a/main.c b/main.c index c9b43ff..50c6c7f 100644 --- a/main.c +++ b/main.c @@ -26,9 +26,17 @@ int main() { // Desaloca tabuleiro destroiTblr(t); - // printf("Número de grupos: %d\n", tamanhoLista(g->vertices)); Lista jogadas = constroiLista(); + // PARA DEBUGAR: Imprime o grafo tabuleiro em formato dot com os vértices já + // "consumidos" pintados de vermelho + printf("Número de grupos: %d\n", tamanhoLista(g->vertices)); + FILE* debug = fopen("./debug.out", "w+"); + if(debug) { + grafoParaDot(g, grupo, debug); + } + fclose(debug); + destroiLista(jogadas, NULL); // Desaloca lista do grupo destroiLista(grupo, NULL); diff --git a/tests/runTests.sh b/tests/runTests.sh index 47eee75..359beed 100755 --- a/tests/runTests.sh +++ b/tests/runTests.sh @@ -4,10 +4,10 @@ tempo_max=10000 #10s # tamanhos do tabuleiro -tams=(4 8 16 25 32 50 64 75 100 128) +tams=(4 8 16 32 64 128 256) # lista de cores -cores=(2 3 4 5 6 7 8 10 16 32) +cores=(2 4 8 16 32) #-- Cores do terminal RED='\033[0;31m' -- GitLab