Skip to content

Commit 9237081

Browse files
Merge pull request #403 from Wavetrace/feature-matrix-bidir
Make adjacency_matrix implement BidirectionalGraph concept
2 parents 8f05ca2 + 50d2681 commit 9237081

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

include/boost/graph/adjacency_matrix.hpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ struct adj_matrix_traversal_tag : public virtual adjacency_matrix_tag,
433433
public virtual vertex_list_graph_tag,
434434
public virtual incidence_graph_tag,
435435
public virtual adjacency_graph_tag,
436-
public virtual edge_list_graph_tag
436+
public virtual edge_list_graph_tag,
437+
public virtual bidirectional_graph_tag
437438
{
438439
};
439440

@@ -826,6 +827,27 @@ typename adjacency_matrix< D, VP, EP, GP, A >::degree_size_type in_degree(
826827
return n;
827828
}
828829

830+
// O(N)
831+
template < typename VP, typename EP, typename GP, typename A >
832+
typename adjacency_matrix< directedS, VP, EP, GP, A >::degree_size_type
833+
degree(
834+
typename adjacency_matrix< directedS, VP, EP, GP, A >::vertex_descriptor u,
835+
const adjacency_matrix< directedS, VP, EP, GP, A >& g)
836+
{
837+
return in_degree(u, g) + out_degree(u, g);
838+
}
839+
840+
// O(N)
841+
template < typename VP, typename EP, typename GP, typename A >
842+
typename adjacency_matrix< undirectedS, VP, EP, GP, A >::degree_size_type
843+
degree(
844+
typename adjacency_matrix< undirectedS, VP, EP, GP, A >::vertex_descriptor
845+
u,
846+
const adjacency_matrix< undirectedS, VP, EP, GP, A >& g)
847+
{
848+
return out_degree(u, g);
849+
}
850+
829851
//=========================================================================
830852
// Functions required by the AdjacencyGraph concept
831853

test/adj_matrix_cc.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ int main(int, char*[])
2121
BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >));
2222
BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< Graph >));
2323
BOOST_CONCEPT_ASSERT((AdjacencyGraphConcept< Graph >));
24+
BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept< Graph >));
2425
BOOST_CONCEPT_ASSERT((MutableGraphConcept< Graph >));
2526
BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept< Graph >));
2627
}
@@ -30,6 +31,7 @@ int main(int, char*[])
3031
BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >));
3132
BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< Graph >));
3233
BOOST_CONCEPT_ASSERT((AdjacencyGraphConcept< Graph >));
34+
BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept< Graph >));
3335
BOOST_CONCEPT_ASSERT((MutableGraphConcept< Graph >));
3436
BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept< Graph >));
3537
}
@@ -44,6 +46,7 @@ int main(int, char*[])
4446
BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >));
4547
BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< Graph >));
4648
BOOST_CONCEPT_ASSERT((AdjacencyGraphConcept< Graph >));
49+
BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept< Graph >));
4750
BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept< Graph >));
4851
BOOST_CONCEPT_ASSERT((VertexMutablePropertyGraphConcept< Graph >));
4952
BOOST_CONCEPT_ASSERT((EdgeMutablePropertyGraphConcept< Graph >));
@@ -64,6 +67,7 @@ int main(int, char*[])
6467
BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >));
6568
BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< Graph >));
6669
BOOST_CONCEPT_ASSERT((AdjacencyGraphConcept< Graph >));
70+
BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept< Graph >));
6771
BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept< Graph >));
6872
BOOST_CONCEPT_ASSERT((VertexMutablePropertyGraphConcept< Graph >));
6973
BOOST_CONCEPT_ASSERT((EdgeMutablePropertyGraphConcept< Graph >));

test/reverse_graph_cc.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <boost/graph/graph_concepts.hpp>
1010
#include <boost/graph/graph_archetypes.hpp>
1111
#include <boost/graph/adjacency_list.hpp>
12+
#include <boost/graph/adjacency_matrix.hpp>
1213
#include <boost/graph/reverse_graph.hpp>
1314
#include <boost/concept/assert.hpp>
1415
#include <string>
@@ -59,5 +60,26 @@ int main(int, char*[])
5960
get_property(gr, graph_name_t());
6061
set_property(gr, graph_name_t(), "foo");
6162
}
63+
// Check matrix
64+
{
65+
typedef adjacency_matrix< directedS,
66+
property< vertex_color_t, int >, property< edge_weight_t, int >,
67+
property< graph_name_t, std::string > >
68+
AdjMatrix;
69+
typedef reverse_graph< AdjMatrix > Graph;
70+
BOOST_CONCEPT_ASSERT((VertexListGraphConcept< Graph >));
71+
BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept< Graph >));
72+
typedef graph_traits< Graph >::vertex_descriptor Vertex;
73+
typedef graph_traits< Graph >::edge_descriptor Edge;
74+
BOOST_CONCEPT_ASSERT(
75+
(ReadablePropertyGraphConcept< Graph, Vertex, vertex_color_t >));
76+
BOOST_CONCEPT_ASSERT(
77+
(ReadablePropertyGraphConcept< Graph, Edge, edge_weight_t >));
78+
BOOST_CONCEPT_ASSERT(
79+
(ReadablePropertyGraphConcept< Graph, Edge, edge_underlying_t >));
80+
AdjMatrix g(42);
81+
Graph gr(g);
82+
get_property(gr, graph_name_t());
83+
}
6284
return 0;
6385
}

test/test_graphs.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ int main()
132132
Graph;
133133
BOOST_META_ASSERT(is_directed_graph< Graph >);
134134
BOOST_META_ASSERT(!is_multigraph< Graph >);
135+
BOOST_META_ASSERT(is_bidirectional_graph< Graph >);
136+
BOOST_META_ASSERT(is_directed_bidirectional_graph< Graph >);
135137
BOOST_META_ASSERT(has_vertex_property< Graph >);
136138
BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
137139
BOOST_META_ASSERT(has_edge_property< Graph >);
@@ -145,6 +147,8 @@ int main()
145147
typedef adjacency_matrix< directedS, VertexBundle, EdgeBundle > Graph;
146148
BOOST_META_ASSERT(is_directed_graph< Graph >);
147149
BOOST_META_ASSERT(!is_multigraph< Graph >);
150+
BOOST_META_ASSERT(is_bidirectional_graph< Graph >);
151+
BOOST_META_ASSERT(is_directed_bidirectional_graph< Graph >);
148152
BOOST_META_ASSERT(has_vertex_property< Graph >);
149153
BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
150154
BOOST_META_ASSERT(has_edge_property< Graph >);

0 commit comments

Comments
 (0)