projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix bug in shortest path implementation
[tinc]
/
src
/
graph.c
diff --git
a/src/graph.c
b/src/graph.c
index
5a7a16a
..
5bec2c1
100644
(file)
--- a/
src/graph.c
+++ b/
src/graph.c
@@
-141,6
+141,7
@@
void sssp_bfs(void) {
myself->prevedge = NULL;
myself->via = myself;
myself->distance = 0;
myself->prevedge = NULL;
myself->via = myself;
myself->distance = 0;
+ myself->weighted_distance = 0;
list_insert_head(todo_list, myself);
/* Loop while todo_list is filled */
list_insert_head(todo_list, myself);
/* Loop while todo_list is filled */
@@
-178,14
+179,15
@@
void sssp_bfs(void) {
if(e->to->status.visited
&& (!e->to->status.indirect || indirect)
if(e->to->status.visited
&& (!e->to->status.indirect || indirect)
- && (e->to->distance != n->distance + 1 || e->
weight >= e->to->prevedg
e->weight)) {
+ && (e->to->distance != n->distance + 1 || e->
to->weighted_distance <= n->weighted_distance +
e->weight)) {
continue;
}
// Only update nexthop if it doesn't increase the path length
continue;
}
// Only update nexthop if it doesn't increase the path length
- if(!e->to->status.visited || (e->to->distance == n->distance + 1 && e->
weight < e->to->prevedg
e->weight)) {
+ if(!e->to->status.visited || (e->to->distance == n->distance + 1 && e->
to->weighted_distance > n->weighted_distance +
e->weight)) {
e->to->nexthop = (n->nexthop == myself) ? e->to : n->nexthop;
e->to->nexthop = (n->nexthop == myself) ? e->to : n->nexthop;
+ e->to->weighted_distance = n->weighted_distance + e->weight;
}
e->to->status.visited = true;
}
e->to->status.visited = true;