diff --git a/src/algorithms.rs b/src/algorithms.rs index 0a7a963..01a6c31 100644 --- a/src/algorithms.rs +++ b/src/algorithms.rs @@ -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, }); }