Skip to content
Merged
Changes from 3 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
74 changes: 42 additions & 32 deletions include/boost/graph/isomorphism.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <utility>
#include <vector>
#include <iterator>
Comment thread
Becheler marked this conversation as resolved.
Resolved
#include <algorithm>
#include <boost/config.hpp>
#include <boost/assert.hpp>
Expand All @@ -19,11 +18,6 @@
#include <boost/pending/indirect_cmp.hpp> // for make_indirect_pmap
#include <boost/concept/assert.hpp>

#ifndef BOOST_GRAPH_ITERATION_MACROS_HPP
#define BOOST_ISO_INCLUDED_ITER_MACROS // local macro, see bottom of file
#include <boost/graph/iteration_macros.hpp>
#endif

namespace boost
{

Expand Down Expand Up @@ -182,28 +176,37 @@ namespace detail
bool test_isomorphism()
{
// reset isomapping
BGL_FORALL_VERTICES_T(v, G1, Graph1)
f[v] = graph_traits< Graph2 >::null_vertex();
for(const auto v : boost::make_iterator_range(vertices(G1)))
{
f[v] = graph_traits< Graph2 >::null_vertex();
}

// Calculate all invariants of G1 and G2, sort and compare
std::vector< invariant_t > invar1_array;
invar1_array.reserve(num_vertices(G1));
BGL_FORALL_VERTICES_T(v, G1, Graph1)
invar1_array.push_back(invariant1(v));
for(const auto v : boost::make_iterator_range(vertices(G1)))
{
invar1_array.push_back(invariant1(v));
}
sort(invar1_array);

std::vector< invariant_t > invar2_array;
invar2_array.reserve(num_vertices(G2));
BGL_FORALL_VERTICES_T(v, G2, Graph2)
invar2_array.push_back(invariant2(v));
for(const auto v : boost::make_iterator_range(vertices(G2)))
{
invar2_array.push_back(invariant2(v));
}
sort(invar2_array);
if (!equal(invar1_array, invar2_array))
return false;

// Sort vertices by the multiplicity of their invariants
std::vector< vertex1_t > V_mult;
BGL_FORALL_VERTICES_T(v, G1, Graph1)
V_mult.push_back(v);
for(const auto v : boost::make_iterator_range(vertices(G1)))
{
V_mult.push_back(v);
}

sort(V_mult, compare_multiplicity(invariant1, multiplicities(invar1_array.begin(), invar1_array.end())));

std::vector< default_color_type > color_vec(num_vertices(G1));
Expand Down Expand Up @@ -428,9 +431,10 @@ namespace detail
void map_disconnected_vertices()
{
std::vector< vertex1_t > unmatched_g1_vertices;
BGL_FORALL_VERTICES_T(v, G1, Graph1)
for(const auto v : boost::make_iterator_range(vertices(G1)))
{
if(f[v] == graph_traits< Graph2 >::null_vertex()) {
if(f[v] == graph_traits< Graph2 >::null_vertex())
{
unmatched_g1_vertices.push_back(v);
}
}
Expand All @@ -440,7 +444,8 @@ namespace detail
typedef unordered_multimap< invariant_t, vertex2_t > g2_invariant_vertex_multimap;
typedef typename g2_invariant_vertex_multimap::iterator multimap_iter;
g2_invariant_vertex_multimap unmatched_invariants;
BGL_FORALL_VERTICES_T(v, G2, Graph2)

for(const auto v : boost::make_iterator_range(vertices(G2)))
{
if(!in_S[v])
{
Expand All @@ -464,13 +469,20 @@ namespace detail

template < typename Graph, typename InDegreeMap >
void compute_in_degree(const Graph& g, InDegreeMap in_degree_map)
{
BGL_FORALL_VERTICES_T(v, g, Graph)
put(in_degree_map, v, 0);
{
for(const auto v : boost::make_iterator_range(vertices(g)))
{
put(in_degree_map, v, 0);
}

for(const auto u : boost::make_iterator_range(vertices(g)))
{

BGL_FORALL_VERTICES_T(u, g, Graph)
BGL_FORALL_ADJ_T(u, v, g, Graph)
put(in_degree_map, v, get(in_degree_map, v) + 1);
for(const auto v : boost::make_iterator_range(adjacent_vertices(u, g)))
{
put(in_degree_map, v, get(in_degree_map, v) + 1);
}
}
}

} // namespace detail
Expand All @@ -490,8 +502,10 @@ template < typename InDegreeMap, typename Graph > class degree_vertex_invariant
, m_max_vertex_out_degree(0)
, m_g(g)
{
BGL_FORALL_VERTICES_T(v, g, Graph)

for(const auto v : boost::make_iterator_range(vertices(g)))
{

m_max_vertex_in_degree
= (std::max)(m_max_vertex_in_degree, get(m_in_degree_map, v));
m_max_vertex_out_degree
Expand Down Expand Up @@ -521,7 +535,7 @@ template < typename InDegreeMap, typename Graph > class degree_vertex_invariant
template < typename Graph > size_t count_vertices(const Graph& g)
{
size_t n = 0;
BGL_FORALL_VERTICES_T(v, g, Graph)
for(const auto v : boost::make_iterator_range(vertices(g)))
{
(void)v;
++n;
Expand Down Expand Up @@ -723,10 +737,11 @@ inline bool verify_isomorphism(
return false;
#endif

BGL_FORALL_EDGES_T(e1, g1, Graph1)
for(const auto& e1 : boost::make_iterator_range(edges(g1)))

{
bool found_edge = false;
BGL_FORALL_EDGES_T(e2, g2, Graph2)
for(const auto& e2 : boost::make_iterator_range(edges(g2)))
{
if (source(e2, g2) == get(iso_map, source(e1, g1))
&& target(e2, g2) == get(iso_map, target(e1, g1)))
Expand All @@ -744,9 +759,4 @@ inline bool verify_isomorphism(

} // namespace boost

#ifdef BOOST_ISO_INCLUDED_ITER_MACROS
#undef BOOST_ISO_INCLUDED_ITER_MACROS
#include <boost/graph/iteration_macros_undef.hpp>
#endif

#endif // BOOST_GRAPH_ISOMORPHISM_HPP
Loading