From 41773c52a88ca186df6031248a63dda3c9c29e05 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sat, 4 Jan 2020 08:58:20 +0100 Subject: Made dijkstra work with new ref implementation --- sem1/algo/workshop2/dijkstra/graph.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'sem1/algo/workshop2/dijkstra/graph.c') diff --git a/sem1/algo/workshop2/dijkstra/graph.c b/sem1/algo/workshop2/dijkstra/graph.c index 8b84c75..8f62981 100644 --- a/sem1/algo/workshop2/dijkstra/graph.c +++ b/sem1/algo/workshop2/dijkstra/graph.c @@ -166,13 +166,13 @@ int graph_to_dot(FILE *f, graph_t *g) { // Label all nodes vertex_t *v = vertex_next(g, NULL); while( v ) { - fprintf(f, "%s [label=\"%s\"];\n", v->ref, v->ref); + fprintf(f, "%s [label=\"%s(%d)\"];\n", v->ref, v->ref, v->dist); v = vertex_next(g, v); } // Print all the edges edge_t *e = edge_next(g, NULL); while( e ) { - fprintf(f, "%s -> %s [label = %d];\n", e->from->ref, e->to->ref, e->weight); + fprintf(f, "%s -> %s [label = %d%s];\n", e->from->ref, e->to->ref, e->weight, e->to->p == e->from ? " color=blue" : ""); e = edge_next(g, e); } @@ -190,19 +190,26 @@ int graph_from_dot(FILE *f, graph_t *g) { *from = 0; *to = 0; weight = 0; - int c = fscanf(f, "%s -> %s [label = %d];", from, to, &weight); + int c = fscanf(f, "%s -> %s [label=%d];", from, to, &weight); if( c <= 0 ) { break; } if( *from == 0 || *to == 0 ) { continue; } + // Sorry i just want it to work + int tolen = strlen(to); + if( to[tolen-1] == ';' ) { + to[tolen-1] = 0; + } weight = weight ? weight : 1; - printf("Creating edge from %s to %s with w: %d\n", from, to, weight); - - + //printf("Creating edge from %s to %s with w: %d\n", from, to, weight); graph_edge(g, from, to, weight); } } + +vertex_t *graph_vertex(graph_t *g, char *ref) { + return table_lookup(g, ref); +} -- cgit v1.2.3