Skip to content

Commit 831d600

Browse files
committed
Apply Copilot recommended changes to key algorithms
Dijkstrat & Bellman-Ford shortest paths
1 parent 16bdfb2 commit 831d600

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

include/graph/algorithm/bellman_ford_shortest_paths.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace graph {
3939
*
4040
* @param g The graph.
4141
* @param predecessor The predecessor range.
42-
* @param cycle_vertex_id A vertex id in the negative weight cycle. IF no negative weight cycle exists
42+
* @param cycle_vertex_id A vertex id in the negative weight cycle. If no negative weight cycle exists
4343
* then there will be no vertex id defined.
4444
* @param out_cycle The output iterator that the vertex ids in the cycle are output to.
4545
*/
@@ -84,9 +84,9 @@ void find_negative_cycle(G& g,
8484
* @tparam Predecessors The predecessor random access range.
8585
* @tparam WF Edge weight function. Defaults to a function that returns 1.
8686
* @tparam Visitor Visitor type with functions called for different events in the algorithm.
87-
* Function calls are removed by the optimizer if not uesd.
87+
* Function calls are removed by the optimizer if not used.
8888
* @tparam Compare Comparison function for Distance values. Defaults to less<DistanceValue>.
89-
* @tparam Combine Combine function for Distance values. Defaults to plus<DistanctValue>.
89+
* @tparam Combine Combine function for Distance values. Defaults to plus<DistanceValue>.
9090
*
9191
* @return optional<vertex_id_t<G>>, where no vertex id is returned if all edges were minimized.
9292
* If an edge was not minimized, the on_edge_not_minimized event is called and a vertex id
@@ -120,7 +120,7 @@ requires convertible_to<range_value_t<Sources>, vertex_id_t<G>> && //
120120
using weight_type = invoke_result_t<WF, edge_reference_t<G>>;
121121
using return_type = optional<vertex_id_t<G>>;
122122

123-
// relxing the target is the function of reducing the distance from the source to the target
123+
// relaxing the target is the function of reducing the distance from the source to the target
124124
auto relax_target = [&g, &predecessor, &distances, &compare, &combine] //
125125
(edge_reference_t<G> e, vertex_id_t<G> uid, const weight_type& w_e) -> bool {
126126
id_type vid = target_id(g, e);
@@ -139,14 +139,14 @@ requires convertible_to<range_value_t<Sources>, vertex_id_t<G>> && //
139139

140140
if (size(distances) < size(vertices(g))) {
141141
throw std::out_of_range(
142-
std::format("bellman_ford_shortest_paths: size of distances is {} is less than the number of vertices {}",
142+
std::format("bellman_ford_shortest_paths: size of distances of {} is less than the number of vertices {}",
143143
size(distances), size(vertices(g))));
144144
}
145145

146146
if constexpr (!is_same_v<Predecessors, _null_range_type>) {
147147
if (size(predecessor) < size(vertices(g))) {
148148
throw std::out_of_range(
149-
std::format("bellman_ford_shortest_paths: size of predecessor is {} is less than the number of vertices {}",
149+
std::format("bellman_ford_shortest_paths: size of predecessor of {} is less than the number of vertices {}",
150150
size(predecessor), size(vertices(g))));
151151
}
152152
}
@@ -259,9 +259,9 @@ requires is_arithmetic_v<range_value_t<Distances>> && //
259259
* @tparam Distances The distance random access range.
260260
* @tparam WF Edge weight function. Defaults to a function that returns 1.
261261
* @tparam Visitor Visitor type with functions called for different events in the algorithm.
262-
* Function calls are removed by the optimizer if not uesd.
262+
* Function calls are removed by the optimizer if not used.
263263
* @tparam Compare Comparison function for Distance values. Defaults to less<DistanceValue>.
264-
* @tparam Combine Combine function for Distance values. Defaults to plus<DistanctValue>.
264+
* @tparam Combine Combine function for Distance values. Defaults to plus<DistanceValue>.
265265
*
266266
* @return optional<vertex_id_t<G>>, where no vertex id is returned if all edges were minimized.
267267
* If an edge was not minimized, the on_edge_not_minimized event is called and a vertex id

include/graph/algorithm/dijkstra_clrs.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ template <class G, class F>
1111
concept edge_weight_function = // e.g. weight(uv)
1212
std::copy_constructible<F> && is_arithmetic_v<invoke_result_t<F, edge_reference_t<G>>>;
1313

14-
15-
//edge_weight_function<G, WF> &&
16-
//strict_weak_order<Compare, range_value_t<Distance>, range_value_t<Distance>> &&
17-
//assignable_from <range_reference_t<Distance>, invoke_result_t <Combine, invoke_result_t<WF, edge_t<G>>,
18-
1914
template <class G, class WF, class Distance, class Compare, class Combine>
2015
concept basic_edge_weight_function2 = // e.g. weight(uv)
2116
is_arithmetic_v<range_value_t<Distance>> &&
@@ -67,8 +62,8 @@ constexpr auto print_types(Ts...) {
6762
* @tparam Distance The distance range type.
6863
* @tparam Predecessor The predecessor range type.
6964
*
70-
* @param graph The graph.
71-
* @param source The source vertex.
65+
* @param g The graph.
66+
* @param seed The source vertex.
7267
* @param distance The distance vector.
7368
* @param predecessor The predecessor vector.
7469
* @param weight The edge weight function.
@@ -159,7 +154,7 @@ void dijkstra_clrs(
159154
WF&& weight = [](edge_identifier_t<G> uv) { return range_value_t<Distance>(1); }) // default weight(uv) -> 1
160155
{
161156
using id_type = vertex_id_t<G>;
162-
using weight_type = invoke_result_t<WF, edge_identifer_t<G>>;
157+
using weight_type = invoke_result_t<WF, edge_identifier_t<G>>;
163158
const id_type seed_id = vertex_id(g, seed);
164159
165160
size_t N(num_vertices(g));

include/graph/algorithm/dijkstra_shortest_paths.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ namespace graph {
2929
/**
3030
* @brief Dijkstra's single-source shortest paths algorithm with a visitor.
3131
*
32-
* The implementation was taken from boost::graph dijkstra_shortes_paths_no_init.
32+
* The implementation was taken from boost::graph dijkstra_shortest_paths_no_init.
3333
*
34-
* Complexity: O(V * E)
34+
* Complexity: O((V + E) log V)
3535
*
3636
* Pre-conditions:
3737
* - 0 <= source < num_vertices(g)
@@ -52,9 +52,9 @@ namespace graph {
5252
* @tparam Predecessors The predecessor random access range.
5353
* @tparam WF Edge weight function. Defaults to a function that returns 1.
5454
* @tparam Visitor Visitor type with functions called for different events in the algorithm.
55-
* Function calls are removed by the optimizer if not uesd.
55+
* Function calls are removed by the optimizer if not used.
5656
* @tparam Compare Comparison function for Distance values. Defaults to less<distance_type>.
57-
* @tparam Combine Combine function for Distance values. Defaults to plus<DistanctValue>.
57+
* @tparam Combine Combine function for Distance values. Defaults to plus<DistanceValue>.
5858
*/
5959
template <index_adjacency_list G,
6060
input_range Sources,
@@ -83,7 +83,7 @@ constexpr void dijkstra_shortest_paths(
8383
using distance_type = range_value_t<Distances>;
8484
using weight_type = invoke_result_t<WF, edge_reference_t<G>>;
8585

86-
// relxing the target is the function of reducing the distance from the source to the target
86+
// relaxing the target is the function of reducing the distance from the source to the target
8787
auto relax_target = [&g, &predecessor, &distances, &compare, &combine] //
8888
(edge_reference_t<G> e, vertex_id_t<G> uid, const weight_type& w_e) -> bool {
8989
const id_type vid = target_id(g, e);
@@ -233,7 +233,7 @@ constexpr void dijkstra_shortest_paths(
233233
}
234234

235235
/**
236-
* @brief Shortest distnaces from a single source using Dijkstra's single-source shortest paths algorithm
236+
* @brief Shortest distances from a single source using Dijkstra's single-source shortest paths algorithm
237237
* with a visitor.
238238
*
239239
* This is identical to dijkstra_shortest_paths() except that it does not require a predecessors range.
@@ -254,9 +254,9 @@ constexpr void dijkstra_shortest_paths(
254254
* @tparam Distances The distance random access range.
255255
* @tparam WF Edge weight function. Defaults to a function that returns 1.
256256
* @tparam Visitor Visitor type with functions called for different events in the algorithm.
257-
* Function calls are removed by the optimizer if not uesd.
257+
* Function calls are removed by the optimizer if not used.
258258
* @tparam Compare Comparison function for Distance values. Defaults to less<distance_type>.
259-
* @tparam Combine Combine function for Distance values. Defaults to plus<DistanctValue>.
259+
* @tparam Combine Combine function for Distance values. Defaults to plus<DistanceValue>.
260260
*/
261261
template <index_adjacency_list G,
262262
input_range Sources,

0 commit comments

Comments
 (0)