Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make adjacency_matrix implement BidirectionalGraph concept #403

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion include/boost/graph/adjacency_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ struct adj_matrix_traversal_tag : public virtual adjacency_matrix_tag,
public virtual vertex_list_graph_tag,
public virtual incidence_graph_tag,
public virtual adjacency_graph_tag,
public virtual edge_list_graph_tag
public virtual edge_list_graph_tag,
public virtual bidirectional_graph_tag
{
};

Expand Down Expand Up @@ -826,6 +827,26 @@ typename adjacency_matrix< D, VP, EP, GP, A >::degree_size_type in_degree(
return n;
}

// degree
template < typename VP, typename EP, typename GP, typename A >
typename adjacency_matrix< directedS, VP, EP, GP, A >::degree_size_type
degree(
typename adjacency_matrix< directedS, VP, EP, GP, A >::vertex_descriptor u,
const adjacency_matrix< directedS, VP, EP, GP, A >& g)
{
return in_degree(u, g) + out_degree(u, g);
}

template < typename VP, typename EP, typename GP, typename A >
typename adjacency_matrix< undirectedS, VP, EP, GP, A >::degree_size_type
degree(
typename adjacency_matrix< undirectedS, VP, EP, GP, A >::vertex_descriptor
u,
const adjacency_matrix< undirectedS, VP, EP, GP, A >& g)
{
return out_degree(u, g);
}

//=========================================================================
// Functions required by the AdjacencyGraph concept

Expand Down
4 changes: 4 additions & 0 deletions test/adj_matrix_cc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ int main(int, char*[])
BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((AdjacencyGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((MutableGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept< Graph >));
}
Expand All @@ -30,6 +31,7 @@ int main(int, char*[])
BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((AdjacencyGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((MutableGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept< Graph >));
}
Expand All @@ -44,6 +46,7 @@ int main(int, char*[])
BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((AdjacencyGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept< Graph >));
BOOST_CONCEPT_ASSERT((VertexMutablePropertyGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((EdgeMutablePropertyGraphConcept< Graph >));
Expand All @@ -64,6 +67,7 @@ int main(int, char*[])
BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((AdjacencyGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept< Graph >));
BOOST_CONCEPT_ASSERT((VertexMutablePropertyGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((EdgeMutablePropertyGraphConcept< Graph >));
Expand Down
22 changes: 22 additions & 0 deletions test/reverse_graph_cc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <boost/graph/graph_concepts.hpp>
#include <boost/graph/graph_archetypes.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_matrix.hpp>
#include <boost/graph/reverse_graph.hpp>
#include <boost/concept/assert.hpp>
#include <string>
Expand Down Expand Up @@ -59,5 +60,26 @@ int main(int, char*[])
get_property(gr, graph_name_t());
set_property(gr, graph_name_t(), "foo");
}
// Check matrix
{
typedef adjacency_matrix< directedS,
property< vertex_color_t, int >, property< edge_weight_t, int >,
property< graph_name_t, std::string > >
AdjMatrix;
typedef reverse_graph< AdjMatrix > Graph;
BOOST_CONCEPT_ASSERT((VertexListGraphConcept< Graph >));
BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept< Graph >));
typedef graph_traits< Graph >::vertex_descriptor Vertex;
typedef graph_traits< Graph >::edge_descriptor Edge;
BOOST_CONCEPT_ASSERT(
(ReadablePropertyGraphConcept< Graph, Vertex, vertex_color_t >));
BOOST_CONCEPT_ASSERT(
(ReadablePropertyGraphConcept< Graph, Edge, edge_weight_t >));
BOOST_CONCEPT_ASSERT(
(ReadablePropertyGraphConcept< Graph, Edge, edge_underlying_t >));
AdjMatrix g(42);
Graph gr(g);
get_property(gr, graph_name_t());
}
return 0;
}
4 changes: 4 additions & 0 deletions test/test_graphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ int main()
Graph;
BOOST_META_ASSERT(is_directed_graph< Graph >);
BOOST_META_ASSERT(!is_multigraph< Graph >);
BOOST_META_ASSERT(is_bidirectional_graph< Graph >);
BOOST_META_ASSERT(is_directed_bidirectional_graph< Graph >);
BOOST_META_ASSERT(has_vertex_property< Graph >);
BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
BOOST_META_ASSERT(has_edge_property< Graph >);
Expand All @@ -145,6 +147,8 @@ int main()
typedef adjacency_matrix< directedS, VertexBundle, EdgeBundle > Graph;
BOOST_META_ASSERT(is_directed_graph< Graph >);
BOOST_META_ASSERT(!is_multigraph< Graph >);
BOOST_META_ASSERT(is_bidirectional_graph< Graph >);
BOOST_META_ASSERT(is_directed_bidirectional_graph< Graph >);
BOOST_META_ASSERT(has_vertex_property< Graph >);
BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
BOOST_META_ASSERT(has_edge_property< Graph >);
Expand Down