Skip to content

Commit 9021bb2

Browse files
authored
Merge pull request #686 from Becheler/fix/issue-182-tiernan-vertex-index
fix: tiernan_all_cycles requires only a vertex_index map
2 parents 3f2da15 + 7844c67 commit 9021bb2

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎include/boost/graph/tiernan_all_cycles.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ namespace detail
150150
const ClosedMatrix& m)
151151
{
152152
BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< Graph >));
153-
BOOST_CONCEPT_ASSERT((VertexIndexGraphConcept< Graph >));
154153
typedef typename graph_traits< Graph >::vertex_descriptor Vertex;
154+
using IndexMap = typename ::boost::property_map< Graph, ::boost::vertex_index_t >::const_type;
155+
BOOST_CONCEPT_ASSERT((::boost::ReadablePropertyMapConcept< IndexMap, Vertex >));
155156

156157
// get the vertices in question
157158
Vertex u = source(e, g), v = target(e, g);

‎test/tiernan_all_cycles.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <iostream>
88

99
#include <boost/graph/graph_utility.hpp>
10+
#include <boost/graph/adjacency_list.hpp>
1011
#include <boost/graph/undirected_graph.hpp>
1112
#include <boost/graph/directed_graph.hpp>
1213
#include <boost/graph/tiernan_all_cycles.hpp>
@@ -103,6 +104,24 @@ void test_stateful_visitor_with_ref()
103104
BOOST_TEST_EQ(copied.count, static_cast< std::size_t >(0));
104105
}
105106

107+
// adjacency_list has a vertex index but no renumber_vertex_indices, see issue 182
108+
void test_adjacency_list()
109+
{
110+
using graph_t = boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS >;
111+
graph_t g(4);
112+
113+
// a triangle and a two cycle, so two elementary cycles
114+
boost::add_edge(0, 1, g);
115+
boost::add_edge(1, 2, g);
116+
boost::add_edge(2, 0, g);
117+
boost::add_edge(1, 3, g);
118+
boost::add_edge(3, 1, g);
119+
120+
cycle_tally tally;
121+
boost::tiernan_all_cycles(g, std::ref(tally));
122+
BOOST_TEST_EQ(tally.count, static_cast< std::size_t >(2));
123+
}
124+
106125
int main(int, char*[])
107126
{
108127
typedef undirected_graph<> Graph;
@@ -115,6 +134,7 @@ int main(int, char*[])
115134
test< DiGraph >();
116135

117136
test_stateful_visitor_with_ref();
137+
test_adjacency_list();
118138

119139
return boost::report_errors();
120140
}

0 commit comments

Comments
 (0)