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() {
|
||||
for adjacent in graph.adjacent_vertices(v.vertex) {
|
||||
// TODO: Use custom edge weights in Dijkstra's algorithm.
|
||||
let edge_weight = 1;
|
||||
let new_distance = distances[v.vertex].unwrap() + edge_weight;
|
||||
if match distances[adjacent] {
|
||||
for incidence in graph.incidences(v.vertex) {
|
||||
let new_distance = distances[v.vertex].unwrap() + weight(incidence.1);
|
||||
if match distances[incidence.0] {
|
||||
None => true,
|
||||
Some(old_distance) if old_distance > new_distance => true,
|
||||
_ => false,
|
||||
} {
|
||||
distances[adjacent] = Some(new_distance);
|
||||
on_relax(adjacent, v.vertex);
|
||||
distances[incidence.0] = Some(new_distance);
|
||||
on_relax(incidence.0, v.vertex);
|
||||
heap.push(DistanceOrderedVertex {
|
||||
vertex: adjacent,
|
||||
vertex: incidence.0,
|
||||
distance: new_distance,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user