Skip to content
Snippets Groups Projects
Commit f79f11ac authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Add função para imprimir grafo em formato .dot

parent 7179a2d3
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -7,3 +7,4 @@ test ...@@ -7,3 +7,4 @@ test
tests/*.txt tests/*.txt
tests/*.png tests/*.png
massif.out* massif.out*
*.out
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "lista.h" #include "lista.h"
#include "vertice.h" #include "vertice.h"
#include "tabuleiro.h" #include "tabuleiro.h"
#include <stdio.h>
Grafo criaGrafo() { Grafo criaGrafo() {
Grafo g = malloc(sizeof(struct Grafo)); Grafo g = malloc(sizeof(struct Grafo));
...@@ -117,3 +118,23 @@ void destroiGrafo(Grafo g) { ...@@ -117,3 +118,23 @@ void destroiGrafo(Grafo g) {
g = NULL; g = NULL;
return; 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");
}
#ifndef _GRAFO_ #ifndef _GRAFO_
#define _GRAFO_ #define _GRAFO_
#include "tabuleiro.h" #include "tabuleiro.h"
#include <stdio.h>
struct Grafo { struct Grafo {
Lista vertices; Lista vertices;
...@@ -18,4 +19,6 @@ void tabuleiroParaGrafo(Tblr t, Grafo g); ...@@ -18,4 +19,6 @@ void tabuleiroParaGrafo(Tblr t, Grafo g);
void destroiGrafo(Grafo g); void destroiGrafo(Grafo g);
void grafoParaDot(Grafo g, Lista grupo, FILE* fp);
#endif #endif
...@@ -26,9 +26,17 @@ int main() { ...@@ -26,9 +26,17 @@ int main() {
// Desaloca tabuleiro // Desaloca tabuleiro
destroiTblr(t); destroiTblr(t);
// printf("Número de grupos: %d\n", tamanhoLista(g->vertices));
Lista jogadas = constroiLista(); 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); destroiLista(jogadas, NULL);
// Desaloca lista do grupo // Desaloca lista do grupo
destroiLista(grupo, NULL); destroiLista(grupo, NULL);
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
tempo_max=10000 #10s tempo_max=10000 #10s
# tamanhos do tabuleiro # 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 # lista de cores
cores=(2 3 4 5 6 7 8 10 16 32) cores=(2 4 8 16 32)
#-- Cores do terminal #-- Cores do terminal
RED='\033[0;31m' RED='\033[0;31m'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment