]> granicus.if.org Git - graphviz/commitdiff
fixed weighted shortest paths calculation
authorJonathan Zheng <jonathanzheng@hotmail.co.uk>
Sat, 22 Feb 2020 14:06:38 +0000 (14:06 +0000)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Sun, 5 Apr 2020 20:18:29 +0000 (22:18 +0200)
lib/neatogen/dijkstra.c
lib/neatogen/sgd.c

index 198523556c71c1f4a4ea5be561da89825995bfdc..0fec6482a8db5e2c70d17ecb7af5b98492e82b82 100644 (file)
@@ -412,7 +412,7 @@ int dijkstra_sgd(graph_sgd *graph, int source, term_sgd *terms) {
     dists[source] = 0;
     for (i=graph->sources[source]; i<graph->sources[source+1]; i++) {
         int target = graph->targets[i];
-        dists[target] = graph->weights[target];
+        dists[target] = graph->weights[i];
     }
     initHeap_f(&h, source, indices, dists, graph->n);
 
@@ -433,7 +433,7 @@ int dijkstra_sgd(graph_sgd *graph, int source, term_sgd *terms) {
         }
         for (i=graph->sources[closest]; i<graph->sources[closest+1]; i++) {
             int target = graph->targets[i];
-            int weight = graph->weights[i];
+            float weight = graph->weights[i];
             increaseKey_f(&h, target, d+weight, indices, dists);
         }
     }
index 67c9ce01e439e6cdcb146c9ba1b8d125ac3ef441..f70f576a9f8523729ff73d0f0f89973c525aa6d6 100644 (file)
@@ -66,16 +66,7 @@ graph_sgd * extract_adjacency(graph_t *G, int model) {
             node_t *target = (agtail(ep) == np) ? aghead(ep) : agtail(ep); // in case edge is reversed
             graph->targets[n_edges] = ND_id(target);
             graph->weights[n_edges] = ED_dist(ep);
-            if (model == MODEL_SHORTPATH) {
-                graph->weights[n_edges] = 1;
-            } else if (model == MODEL_MDS) {
-                assert(ED_dist(ep) > 0);
-                graph->weights[n_edges] = ED_dist(ep);
-            } else if (model == MODEL_SUBSET) {
-                // perform reweighting later
-            } else {
-                assert(false); // circuit model not supported
-            }
+            assert(graph->weights[n_edges] > 0);
             n_edges++;
         }
         n_nodes++;
@@ -84,7 +75,9 @@ graph_sgd * extract_adjacency(graph_t *G, int model) {
     assert(n_edges == graph->sources[graph->n]);
     graph->sources[n_nodes] = n_edges;
 
-    if (model == MODEL_SUBSET) {
+    if (model == MODEL_SHORTPATH || model == MODEL_MDS) {
+        // TODO: fix MDS
+    } else if (model == MODEL_SUBSET) {
         // i,j,k refer to actual node indices, while x,y refer to edge indices in graph->targets
         int i;
         bool *neighbours_i = N_NEW(graph->n, bool);
@@ -132,6 +125,8 @@ graph_sgd * extract_adjacency(graph_t *G, int model) {
         }
         free(neighbours_i);
         free(neighbours_j);
+    } else {
+        assert(false); // circuit model not supported
     }
     return graph;
 }