From ce6b9809201b9ec245fff3376a8c13a7616c5f5f Mon Sep 17 00:00:00 2001 From: Jonathan Zheng Date: Sat, 22 Feb 2020 14:06:38 +0000 Subject: [PATCH] fixed weighted shortest paths calculation --- lib/neatogen/dijkstra.c | 4 ++-- lib/neatogen/sgd.c | 17 ++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/neatogen/dijkstra.c b/lib/neatogen/dijkstra.c index 198523556..0fec6482a 100644 --- a/lib/neatogen/dijkstra.c +++ b/lib/neatogen/dijkstra.c @@ -412,7 +412,7 @@ int dijkstra_sgd(graph_sgd *graph, int source, term_sgd *terms) { dists[source] = 0; for (i=graph->sources[source]; isources[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]; isources[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); } } diff --git a/lib/neatogen/sgd.c b/lib/neatogen/sgd.c index 67c9ce01e..f70f576a9 100644 --- a/lib/neatogen/sgd.c +++ b/lib/neatogen/sgd.c @@ -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; } -- 2.40.0