From: Jonathan Zheng Date: Thu, 16 Jan 2020 00:19:18 +0000 (+0000) Subject: made dijkstra clearer X-Git-Tag: stable_release_2.44.0~12^2~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=269faa348076a1c85507f2b115ee3eda6be3ce67;p=graphviz made dijkstra clearer --- diff --git a/lib/neatogen/sgd.c b/lib/neatogen/sgd.c index 9b794c255..ed63756bc 100644 --- a/lib/neatogen/sgd.c +++ b/lib/neatogen/sgd.c @@ -22,7 +22,8 @@ float calculate_stress(term *terms, int n_terms) { void fisheryates_shuffle(term *terms, int n_terms) { int i; for (i=n_terms-1; i>=1; i--) { - int j = (int)(drand48() * (i+1)); // TODO: better rng? + // srand48() is called in neatoinit.c, so no need to seed here + int j = (int)(drand48() * (i+1)); term temp = terms[i]; terms[i] = terms[j]; @@ -31,7 +32,8 @@ void fisheryates_shuffle(term *terms, int n_terms) { } // single source shortest paths that also builds terms as it goes // mostly copied from from stuff.c -void dijkstra_single_source(graph_t *G, node_t *source, term *terms, int *offset) { +// returns the number of terms built +int dijkstra_single_source(graph_t *G, node_t *source, term *terms) { int t; node_t *v, *u; for (t = 0; (v = GD_neato_nlist(G)[t]); t++) { @@ -40,19 +42,19 @@ void dijkstra_single_source(graph_t *G, node_t *source, term *terms, int *offset } ND_dist(source) = 0; - ND_hops(source) = 0; neato_enqueue(G, source); edge_t *e; + int offset = 0; while ((v = neato_dequeue(G))) { // if the target is fixed then always create a term as shortest paths are not calculated from there // if not fixed then only create a term if the target index is lower if (isFixed(v) || ND_id(v)= 0) { heapup(G, u); } else { - ND_hops(u) = ND_hops(v) + 1; neato_enqueue(G, u); } } } } + return offset; } void sgd(graph_t *G, /* input graph */ @@ -96,7 +98,7 @@ void sgd(graph_t *G, /* input graph */ // calculate term values through shortest paths int offset = 0; - GD_heap(G) = N_NEW(n + 1, node_t *); + GD_heap(G) = N_NEW(n, node_t *); GD_heapsize(G) = 0; if (Verbose) { fprintf(stderr, "calculating shortest paths:"); @@ -104,8 +106,9 @@ void sgd(graph_t *G, /* input graph */ } for (i=0; i