Update Dijkstra's to use incidences instead of neighbors, and with it custom edge weights
This commit is contained in:
+6
-8
@@ -92,19 +92,17 @@ where
|
|||||||
});
|
});
|
||||||
|
|
||||||
while let Some(v) = heap.pop() {
|
while let Some(v) = heap.pop() {
|
||||||
for adjacent in graph.adjacent_vertices(v.vertex) {
|
for incidence in graph.incidences(v.vertex) {
|
||||||
// TODO: Use custom edge weights in Dijkstra's algorithm.
|
let new_distance = distances[v.vertex].unwrap() + weight(incidence.1);
|
||||||
let edge_weight = 1;
|
if match distances[incidence.0] {
|
||||||
let new_distance = distances[v.vertex].unwrap() + edge_weight;
|
|
||||||
if match distances[adjacent] {
|
|
||||||
None => true,
|
None => true,
|
||||||
Some(old_distance) if old_distance > new_distance => true,
|
Some(old_distance) if old_distance > new_distance => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
} {
|
} {
|
||||||
distances[adjacent] = Some(new_distance);
|
distances[incidence.0] = Some(new_distance);
|
||||||
on_relax(adjacent, v.vertex);
|
on_relax(incidence.0, v.vertex);
|
||||||
heap.push(DistanceOrderedVertex {
|
heap.push(DistanceOrderedVertex {
|
||||||
vertex: adjacent,
|
vertex: incidence.0,
|
||||||
distance: new_distance,
|
distance: new_distance,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user