Skip to content

Commit

Permalink
Merge branch 'master' into bfs
Browse files Browse the repository at this point in the history
# Conflicts:
#	include/graph/detail/graph_cpo.hpp
  • Loading branch information
pratzl committed Sep 4, 2024
2 parents 3898097 + 2ae7e97 commit a556d38
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 117 deletions.
2 changes: 1 addition & 1 deletion example/CppCon2021/include/dijkstra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <tuple>
#include <vector>

template <adjacency_list Graph,
template <adjacency_list Graph,
invocable<inner_value_t<Graph>> WeightFunction =
std::function<std::tuple_element_t<1, inner_value_t<Graph>>(const inner_value_t<Graph>&)>>
auto dijkstra(
Expand Down
10 changes: 5 additions & 5 deletions example/CppCon2021/include/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ auto make_index_edges(M& map, const E& edges) {
*/
template <std::ranges::random_access_range V,
std::ranges::random_access_range E,
graph::basic_adjacency_list Graph = std::vector<std::vector<size_t>>>
graph::basic_adjacency_list Graph = std::vector<std::vector<size_t>>>
auto make_plain_graph(const V& vertices, const E& edges, bool directed = true, size_t idx = 0) {
auto vertex_map = make_index_map(vertices);
auto index_edges = make_plain_edges(vertex_map, edges);
Expand All @@ -167,7 +167,7 @@ auto make_plain_graph(const V& vertices, const E& edges, bool directed = true, s
*/
template <std::ranges::random_access_range V,
std::ranges::random_access_range E,
graph::basic_adjacency_list Graph = std::vector<std::vector<std::tuple<size_t, size_t>>>>
graph::basic_adjacency_list Graph = std::vector<std::vector<std::tuple<size_t, size_t>>>>
auto make_index_graph(const V& vertices, const E& edges, bool directed = true, size_t idx = 0) {

auto vertex_map = make_index_map(vertices);
Expand All @@ -185,7 +185,7 @@ auto make_index_graph(const V& vertices, const E& edges, bool directed = true, s
*/
template <std::ranges::random_access_range V,
std::ranges::forward_range E,
graph::basic_adjacency_list Graph =
graph::basic_adjacency_list Graph =
std::vector<std::vector<decltype(std::tuple_cat(std::make_tuple(size_t{}), props(*(begin(E{})))))>>>
auto make_property_graph(const V& vertices, const E& edges, bool directed = true, size_t idx = 0) {

Expand Down Expand Up @@ -226,7 +226,7 @@ auto data_to_graph_edge_list(const V& left_vertices, const V& right_vertices, co
template <std::ranges::random_access_range V1,
std::ranges::random_access_range V2,
std::ranges::random_access_range E,
graph::basic_adjacency_list Graph =
graph::basic_adjacency_list Graph =
std::vector<std::vector<decltype(std::tuple_cat(std::make_tuple(size_t{}), props(*(begin(E{})))))>>>
auto make_plain_bipartite_graph(const V1& left_vertices, const V2& right_vertices, const E& edges, size_t idx = 0) {

Expand Down Expand Up @@ -273,7 +273,7 @@ auto make_bipartite_graph(const V& left_vertices, const V& right_vertices, const

template <std::ranges::random_access_range V,
std::ranges::random_access_range E,
graph::basic_adjacency_list Graph =
graph::basic_adjacency_list Graph =
std::vector<std::vector<decltype(std::tuple_cat(std::make_tuple(size_t{}), props(*(begin(E{})))))>>>
auto make_bipartite_graphs(const V& left_vertices, const V& right_vertices, const E& edges) {

Expand Down
4 changes: 2 additions & 2 deletions example/CppCon2022/germany_routes_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ TEST_CASE("Germany Routes Presentation", "[presentation][germany][routes][shorte
vertex_reference_t<G> frankfurt = *find_vertex(g, frankfurt_id);

cout << "Traverse the vertices & outgoing edges" << endl;
for (auto&& [uid, u] : vertexlist(g)) { // [id,vertex&]
cout << city_id(g, uid) << endl; // city name [id]
for (auto&& [uid, u] : vertexlist(g)) { // [id,vertex&]
cout << city_id(g, uid) << endl; // city name [id]
for (auto&& [vid, uv] : graph::views::incidence(g, uid)) { // [target_id,edge&]
cout << " --> " << city_id(g, vid) << endl;
// "--> "target city" [target_id]
Expand Down
4 changes: 2 additions & 2 deletions example/CppCon2022/graphviz_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ void output_routes_graphviz_adjlist(

template <class G>
void output_routes_graphviz_dfs_vertices(
G& g,
std::string_view filename,
G& g,
std::string_view filename,
graph::vertex_id_t<G> seed,
std::string_view bgcolor = std::string_view() // "transparent" or see http://graphviz.org/docs/attr-types/color/
) {
Expand Down
4 changes: 2 additions & 2 deletions example/CppCon2022/rr_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class rr_adaptor {
using edge_type = std::ranges::range_value_t<edges_range>; //
using vertex_id_type = std::remove_cv_t<std::tuple_element_t<0, to_tuple_t<edge_type>>>;
using edge_value_type = std::conditional_t<(std::tuple_size_v<to_tuple_t<edge_type>> <= 1),
void,
std::tuple_element_t<1, to_tuple_t<edge_type>>>;
void,
std::tuple_element_t<1, to_tuple_t<edge_type>>>;
using vertex_value_type = std::ranges::range_value_t<VVR>;

public:
Expand Down
5 changes: 3 additions & 2 deletions include/graph/algorithm/connected_components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "graph/graph.hpp"
#include "graph/views/incidence.hpp"
#include "graph/views/vertexlist.hpp"
#include "graph/views/breadth_first_search.hpp"
#include "graph/views/depth_first_search.hpp"
#include <stack>

Expand Down Expand Up @@ -102,8 +103,8 @@ void connected_components(G&& g, // graph
}
visited[uid] = true;
component[uid] = cid;
vertices_depth_first_search_view<G, void> dfs(g, uid);
for (auto&& [vid, v] : dfs) {
vertices_breadth_first_search_view<G, void> bfs(g, uid);
for (auto&& [vid, v] : bfs) {
component[vid] = cid;
visited[vid] = true;
}
Expand Down
14 changes: 7 additions & 7 deletions include/graph/algorithm/depth_first_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ inline void init_dfs(Distances& distances, Predecessors& predecessors) {
*/

// C++
inline void
depth_first_search(const Graph& g, const Source& source, Distances& distances, Predecessors& predecessors) {}
inline void depth_first_search(const Graph& g, const Source& source, Distances& distances, Predecessors& predecessors) {
}

// C
inline void depth_first_search(const Graph* g,
const Source source,
const size_t distances_len,
Distances* distances,
const size_t predecessors_len,
Predecessors* predecessors) {}
const Source source,
const size_t distances_len,
Distances* distances,
const size_t predecessors_len,
Predecessors* predecessors) {}


} // namespace graph
Expand Down
16 changes: 8 additions & 8 deletions include/graph/container/compressed_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class csr_row_values<EV, void, GV, VId, EIndex, Alloc> {
using value_type = void;
using size_type = size_t; //VId;

public: // Properties
public: // Properties
[[nodiscard]] constexpr size_type size() const noexcept { return 0; }
[[nodiscard]] constexpr bool empty() const noexcept { return true; }
[[nodiscard]] constexpr size_type capacity() const noexcept { return 0; }
Expand Down Expand Up @@ -345,7 +345,7 @@ class csr_col_values<void, VV, GV, VId, EIndex, Alloc> {
using value_type = void;
using size_type = size_t; //VId;

public: // Properties
public: // Properties
[[nodiscard]] constexpr size_type size() const noexcept { return 0; }
[[nodiscard]] constexpr bool empty() const noexcept { return true; }
[[nodiscard]] constexpr size_type capacity() const noexcept { return 0; }
Expand Down Expand Up @@ -519,7 +519,7 @@ class compressed_graph_base
}

public:
public: // Operations
public: // Operations
void reserve_vertices(size_type count) {
row_index_.reserve(count + 1); // +1 for terminating row
row_values_base::reserve(count);
Expand Down Expand Up @@ -813,13 +813,13 @@ class compressed_graph_base
private: // CPO properties
friend constexpr vertices_type vertices(compressed_graph_base& g) {
if (g.row_index_.empty())
return vertices_type(g.row_index_); // really empty
return vertices_type(g.row_index_); // really empty
else
return vertices_type(g.row_index_.begin(), g.row_index_.end() - 1); // don't include terminating row
}
friend constexpr const_vertices_type vertices(const compressed_graph_base& g) {
if (g.row_index_.empty())
return const_vertices_type(g.row_index_); // really empty
return const_vertices_type(g.row_index_); // really empty
else
return const_vertices_type(g.row_index_.begin(), g.row_index_.end() - 1); // don't include terminating row
}
Expand All @@ -836,15 +836,15 @@ class compressed_graph_base
friend constexpr edges_type edges(graph_type& g, vertex_type& u) {
static_assert(contiguous_range<row_index_vector>, "row_index_ must be a contiguous range to get next row");
vertex_type* u2 = &u + 1;
assert(static_cast<size_t>(u2 - &u) < g.row_index_.size()); // in row_index_ bounds?
assert(static_cast<size_t>(u2 - &u) < g.row_index_.size()); // in row_index_ bounds?
assert(static_cast<size_t>(u.index) <= g.col_index_.size() &&
static_cast<size_t>(u2->index) <= g.col_index_.size()); // in col_index_ bounds?
return edges_type(g.col_index_.begin() + u.index, g.col_index_.begin() + u2->index);
}
friend constexpr const_edges_type edges(const graph_type& g, const vertex_type& u) {
static_assert(contiguous_range<row_index_vector>, "row_index_ must be a contiguous range to get next row");
const vertex_type* u2 = &u + 1;
assert(static_cast<size_t>(u2 - &u) < g.row_index_.size()); // in row_index_ bounds?
assert(static_cast<size_t>(u2 - &u) < g.row_index_.size()); // in row_index_ bounds?
assert(static_cast<size_t>(u.index) <= g.col_index_.size() &&
static_cast<size_t>(u2->index) <= g.col_index_.size()); // in col_index_ bounds?
return const_edges_type(g.col_index_.begin() + u.index, g.col_index_.begin() + u2->index);
Expand All @@ -853,7 +853,7 @@ class compressed_graph_base
friend constexpr edges_type edges(graph_type& g, const vertex_id_type uid) {
assert(static_cast<size_t>(uid + 1) < g.row_index_.size()); // in row_index_ bounds?
assert(static_cast<size_t>(g.row_index_[static_cast<size_t>(uid) + 1].index) <=
g.col_index_.size()); // in col_index_ bounds?
g.col_index_.size()); // in col_index_ bounds?
return edges_type(g.col_index_.begin() + g.row_index_[static_cast<size_type>(uid)].index,
g.col_index_.begin() + g.row_index_[static_cast<size_type>(uid + 1)].index);
}
Expand Down
8 changes: 4 additions & 4 deletions include/graph/container/dynamic_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ class dynamic_graph_base {
constexpr typename vertices_type::value_type& operator[](size_type i) noexcept { return vertices_[i]; }
constexpr const typename vertices_type::value_type& operator[](size_type i) const noexcept { return vertices_[i]; }

public: // Operations
public: // Operations
void reserve_vertices(size_type count) {
if constexpr (reservable<vertices_type>) // reserve if we can; otherwise ignored
vertices_.reserve(count);
Expand All @@ -1273,13 +1273,13 @@ class dynamic_graph_base {
// ignored for this graph; may be meaningful for another data structure like CSR
}

private: // Member Variables
private: // Member Variables
vertices_type vertices_;
partition_vector partition_; // partition_[n] holds the first vertex id for each partition n
// holds +1 extra terminating partition
size_t edge_count_ = 0; // total number of edges in the graph

private: // CPO properties
private: // CPO properties
friend constexpr vertices_type& vertices(dynamic_graph_base& g) { return g.vertices_; }
friend constexpr const vertices_type& vertices(const dynamic_graph_base& g) { return g.vertices_; }

Expand Down Expand Up @@ -1735,7 +1735,7 @@ class dynamic_graph : public dynamic_graph_base<EV, VV, GV, VId, Sourced, Traits
private:
value_type value_; ///< Graph value

private: // CPO properties
private: // CPO properties
friend constexpr value_type& graph_value(graph_type& g) { return g.value_; }
friend constexpr const value_type& graph_value(const graph_type& g) { return g.value_; }
};
Expand Down
Loading

0 comments on commit a556d38

Please sign in to comment.