Skip to content

Commit 453bdc8

Browse files
authored
Merge pull request #183 from stdgraph/copilot
2 parents 320c8d8 + 831d600 commit 453bdc8

14 files changed

+179
-132
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,

include/graph/container/compressed_graph.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ class compressed_graph_base
532532

533533
void resize_vertices(size_type count) {
534534
row_index_.resize(count + 1); // +1 for terminating row
535-
row_values_resize(count);
535+
row_values_base::resize(count);
536536
}
537537
void resize_edges(size_type count) {
538538
col_index_.reserve(count);
@@ -562,7 +562,7 @@ class compressed_graph_base
562562
/**
563563
* Load vertex values, callable either before or after @c load_edges(erng,eproj).
564564
*
565-
* If @c load_edges(vrng,vproj) has been called before this, the @c row_values_ vector will be
565+
* If @c load_vertices(vrng,vproj) has been called before this, the @c row_values_ vector will be
566566
* extended to match the number of @c row_index_.size()-1 to avoid out-of-bounds errors when
567567
* accessing vertex values.
568568
*
@@ -703,7 +703,7 @@ class compressed_graph_base
703703
std::string msg = std::format(
704704
"source id of {} on line {} of the data input is not ordered after source id of {} on the previous line",
705705
edge.source_id, debug_count, last_uid);
706-
std::cout << std::format("\n{}\n", msg);
706+
//std::cout << std::format("\n{}\n", msg);
707707
assert(false);
708708
throw graph_error(move(msg));
709709
}
@@ -736,7 +736,7 @@ class compressed_graph_base
736736
* See @c load_edges() and @c load_vertices() for more information.
737737
*
738738
* @tparam EProj Edge Projection Function type
739-
* @tparam VProj Vertex Projectiong Function type
739+
* @tparam VProj Vertex Projection Function type
740740
* @tparam ERng Edge Range type
741741
* @tparam VRng Vertex Range type
742742
* @tparam PartRng Range of starting vertex Ids for each partition
@@ -824,7 +824,7 @@ class compressed_graph_base
824824
}
825825
friend constexpr bool has_edge(const compressed_graph_base& g) { return g.col_index_.size() > 0; }
826826

827-
friend vertex_id_type vertex_id(const compressed_graph_base& g, const_iterator ui) {
827+
friend constexpr vertex_id_type vertex_id(const compressed_graph_base& g, const_iterator ui) {
828828
return static_cast<vertex_id_type>(ui - g.row_index_.begin());
829829
}
830830

@@ -881,7 +881,7 @@ class compressed_graph_base
881881

882882
friend constexpr auto num_vertices(const compressed_graph_base& g, partition_id_type pid) {
883883
assert(static_cast<size_t>(pid) < g.partition_.size() - 1);
884-
g.partition_[pid + 1] - g.partition_[pid];
884+
return g.partition_[pid + 1] - g.partition_[pid];
885885
}
886886

887887
friend constexpr auto vertices(const compressed_graph_base& g, partition_id_type pid) {

include/graph/container/dynamic_graph.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ using dynamic_adjacency_graph = dynamic_graph<typename Traits::edge_value_type,
190190
* This is one of three composable classes used to define properties for a @c dynamic_edge, the
191191
* others being dynamic_edge_source for the source id and dynamic_edge_value for an edge value.
192192
*
193-
* Unlike the other composable edge property classes, this class doesn't have an open for not
193+
* Unlike the other composable edge property classes, this class doesn't have an option for not
194194
* existing. The target id always exists. It could easily be merged into the dynamic_edge class,
195-
* but was kept separate for design symmatry with the other property classes.
195+
* but was kept separate for design symmetry with the other property classes.
196196
*
197197
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
198198
* calls to @c edge_value(g,uv) will generate a compile error.
@@ -299,7 +299,7 @@ class dynamic_edge_source {
299299
friend constexpr vertex_type& source(graph_type& g, edge_type& uv) noexcept {
300300
return begin(vertices(g))[uv.source_id_];
301301
}
302-
friend constexpr const vertex_type& source_fn(const graph_type& g, const edge_type& uv) noexcept {
302+
friend constexpr const vertex_type& source(const graph_type& g, const edge_type& uv) noexcept {
303303
return begin(vertices(g))[uv.source_id_];
304304
}
305305
};
@@ -356,7 +356,7 @@ class dynamic_edge_value {
356356
using value_type = EV;
357357
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, Traits>;
358358
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, Traits>;
359-
using edge_type = dynamic_edge_value<EV, VV, GV, VId, Sourced, Traits>;
359+
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, Traits>;
360360

361361
public:
362362
constexpr dynamic_edge_value(const value_type& value) : value_(value) {}
@@ -815,7 +815,7 @@ class dynamic_vertex<EV, void, GV, VId, Sourced, Traits>
815815
* No additional space is used if the edge value type (EV) or vertex value type (VV) is void.
816816
*
817817
* The partition function is intended to determine the partition id for a vertex id on constructors.
818-
* It has been added to assure the same interface as the compresssed_graph, but is not implemented
818+
* It has been added to assure the same interface as the compressed_graph, but is not implemented
819819
* at this time.
820820
*
821821
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
@@ -1283,10 +1283,10 @@ class dynamic_graph_base {
12831283
friend constexpr vertices_type& vertices(dynamic_graph_base& g) { return g.vertices_; }
12841284
friend constexpr const vertices_type& vertices(const dynamic_graph_base& g) { return g.vertices_; }
12851285

1286-
friend auto num_edges(const dynamic_graph_base& g) { return g.edge_count_; }
1287-
friend bool has_edge(const dynamic_graph_base& g) { return g.edge_count_ > 0; }
1286+
friend constexpr auto num_edges(const dynamic_graph_base& g) { return g.edge_count_; }
1287+
friend constexpr bool has_edge(const dynamic_graph_base& g) { return g.edge_count_ > 0; }
12881288

1289-
friend vertex_id_type vertex_id(const dynamic_graph_base& g, typename vertices_type::const_iterator ui) {
1289+
friend constexpr vertex_id_type vertex_id(const dynamic_graph_base& g, typename vertices_type::const_iterator ui) {
12901290
return static_cast<vertex_id_type>(ui - g.vertices_.begin());
12911291
}
12921292

@@ -1308,7 +1308,7 @@ class dynamic_graph_base {
13081308

13091309
friend constexpr auto num_vertices(const dynamic_graph_base& g, partition_id_type pid) {
13101310
assert(static_cast<size_t>(pid) < g.partition_.size() - 1);
1311-
g.partition_[pid + 1] - g.partition_[pid];
1311+
return g.partition_[pid + 1] - g.partition_[pid];
13121312
}
13131313

13141314
friend constexpr auto vertices(const dynamic_graph_base& g, partition_id_type pid) {
@@ -1340,7 +1340,7 @@ class dynamic_graph_base {
13401340
* used as a key to find a vertex in the vertices container.
13411341
*
13421342
* The partition function is intended to determine the partition id for a vertex id on constructors.
1343-
* It has been added to assure the same interface as the compresssed_graph, but is not implemented
1343+
* It has been added to assure the same interface as the compressed_graph, but is not implemented
13441344
* at this time.
13451345
*
13461346
* @tparam EV @showinitializer =void The edge value type. If "void" is used no user value is stored on the edge
@@ -1521,14 +1521,14 @@ class dynamic_graph : public dynamic_graph_base<EV, VV, GV, VId, Sourced, Traits
15211521
*/
15221522
template <class ERng, class EProj, class VRng, forward_range PartRng, class VProj = identity>
15231523
requires convertible_to<range_value_t<PartRng>, VId>
1524-
dynamic_graph(const ERng& erng,
1524+
dynamic_graph(GV&& gv,
1525+
const ERng& erng,
15251526
const VRng& vrng,
15261527
EProj eproj,
15271528
VProj vproj,
1528-
GV&& gv,
15291529
const PartRng& partition_start_ids = std::vector<VId>(),
15301530
allocator_type alloc = allocator_type())
1531-
: base_type(erng, vrng, eproj, vproj, partition_start_ids, alloc), value_(move(gv)) {}
1531+
: base_type(erng, vrng, eproj, vproj, partition_start_ids, alloc), value_(std::move(gv)) {}
15321532

15331533

15341534
// max_vertex_id, erng, eproj, alloc
@@ -1539,7 +1539,7 @@ class dynamic_graph : public dynamic_graph_base<EV, VV, GV, VId, Sourced, Traits
15391539
* @brief Construct the graph given the maximum vertex id and edge data range.
15401540
*
15411541
* The vertices container is pre-extended to accomodate the number of vertices referenced by edges and avoids
1542-
* the need to scan the edges to determine the maximum vertex id.
1542+
* the need to scan the edges to determine the maximum vertex id.
15431543
*
15441544
* The graph value is default-constructed.
15451545
*
@@ -1752,7 +1752,7 @@ class dynamic_graph : public dynamic_graph_base<EV, VV, GV, VId, Sourced, Traits
17521752
* See the dynamic_graph description for more information about this class.
17531753
*
17541754
* The partition function is intended to determine the partition id for a vertex id on constructors.
1755-
* It has been added to assure the same interface as the compresssed_graph, but is not implemented
1755+
* It has been added to assure the same interface as the compressed_graph, but is not implemented
17561756
* at this time.
17571757
*
17581758
* @tparam EV @showinitializer =void The edge value type. If "void" is used no user value is stored on the edge

include/graph/detail/graph_cpo.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ concept _el_index_tuple_edge = _el_tuple_edge<_E> && //
9797
integral<tuple_element_t<0, _E>>;
9898

9999
//
100-
// Suport the use of edge_info for edgelist edge definitions
100+
// Support the use of edge_info for edgelist edge definitions
101101
// (Only types and values needed from edge_info are used and there is no
102102
// explicit use of edge_info. This is deemed more flexible and no
103103
// functionality is compromised for it.)
@@ -1319,9 +1319,9 @@ namespace _Source {
13191319
* Complexity: O(1)
13201320
*
13211321
* Default implementation: *(begin(vertices(g)) + source_id(g, uv)),
1322-
# if @source_id(g,uv) is defined for G and random_access_range<vertex_range_t<G>>
1322+
* if @source_id(g,uv) is defined for G and random_access_range<vertex_range_t<G>>
13231323
*
1324-
* Not all graphs support a source on an edge. The existance of @c source_id(g,uv) function
1324+
* Not all graphs support a source on an edge. The existence of @c source_id(g,uv) function
13251325
* for a graph type G determines if it is considered a "sourced" edge or not. If it is,
13261326
* @c source(g,uv) will also exist.
13271327
*
@@ -2561,7 +2561,7 @@ namespace _HasEdge {
25612561
return has_edge(__g); // intentional ADL
25622562
} else if constexpr (_Strat_id == _St_ref::_Auto_eval) {
25632563
for (auto&& u : vertices(__g))
2564-
if (empty(edges(__g, u)))
2564+
if (!empty(edges(__g, u)))
25652565
return true;
25662566
return false;
25672567
} else {

include/graph/detail/graph_using.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include <tuple>
66
#include <functional>
77
#include <optional>
8+
#include <type_traits>
9+
#include <iterator>
10+
#include <algorithm>
11+
#include <memory>
812

913
namespace graph {
1014
// Containers are not included to avoid potential conflicts: vector, list, string, etc.
@@ -19,6 +23,8 @@ using std::forward_iterator_tag;
1923
using std::declval;
2024
using std::allocator;
2125
using std::allocator_traits;
26+
using std::unique_ptr;
27+
using std::shared_ptr;
2228

2329
using std::iter_difference_t;
2430
using std::iter_value_t;
@@ -40,7 +46,6 @@ using std::is_arithmetic_v;
4046
using std::is_convertible_v;
4147
using std::is_same_v;
4248
using std::is_invocable_v;
43-
using std::is_arithmetic_v;
4449
using std::is_void_v;
4550
using std::is_lvalue_reference_v;
4651
using std::is_signed_v;
@@ -52,6 +57,7 @@ using std::remove_reference_t;
5257
using std::remove_pointer_t;
5358
using std::remove_cvref_t;
5459
using std::invoke_result_t;
60+
using std::decay_t;
5561

5662
using std::false_type;
5763
using std::true_type;
@@ -62,6 +68,7 @@ using std::convertible_to;
6268
using std::integral;
6369
using std::invocable;
6470
using std::regular_invocable;
71+
using std::predicate;
6572

6673
// range concepts
6774
using std::ranges::range;
@@ -110,4 +117,6 @@ using std::ranges::empty;
110117
using std::tuple_cat;
111118
using std::max;
112119
using std::min;
120+
using std::swap;
121+
using std::is_sorted;
113122
} // namespace graph

0 commit comments

Comments
 (0)