Question

can someone show me an example of how to use the Boost Graph Library isomorphism function with vertex invariants? I'm looking at the example at http://www.boost.org/doc/libs/1_50_0/libs/graph/example/isomorphism.cpp, which uses degree_vertex_invariant(). However, I want to define my own invariant function and an example would really help me to understand how to do this.

Here are some more details:

I am defining a set of discrete attributes on vertices such that I can label each vertex with an integer. So I have a mapping from any vertex(g,v) to its invariant label, which is an unsigned int. These labels are not necessarily unique, i.e. several vertices in the same graph can share the same label. So suppose I define a function:

template <typename Graph>
unsigned discrete_vertex_invariant(const typename boost::graph_traits<Graph>::vertex_descriptor &v, const Graph &g)

I want to call isomorphism like this:

typename property_map<Graph, vertex_index_t>::type
      v1_index_map = get(vertex_index, g1),
      v2_index_map = get(vertex_index, g2);
vector<typename graph_traits<Graph>::vertex_descriptor> f(num_vertices(g1));

bool is_isomorphic = isomorphism(g1, g2,
   isomorphism_map(make_iterator_property_map(f.begin(), v1_index_map, f[0])),
   discrete_vertex_invariant, discrete_vertex_invariant
)) 

... but I get an error:

no matching function for call to ‘isomorphism(
...
 <unresolved overloaded function type>, <unresolved overloaded function type>)’

What is the correct way to define discrete_vertex_invariant()?

Was it helpful?

Solution

You can find here the definition of degree_vertex_invariant. It's simply a function object with typedefs for result_type and argument_type that is expected to be called with each of the vertices of the graph and that also has a member called max that return an integer equal to the max value of your invariants plus one.

A similar functor using your discrete_vertex_invariant function would look like this:

template <typename Graph>
class discrete_vertex_invariant_functor
{
    typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_t;
    const Graph &graph;
public:
    typedef unsigned int result_type;
    typedef vertex_t argument_type;
    discrete_vertex_invariant_functor(const Graph &g):graph(g){}
    result_type operator()(argument_type v)const
    {
        return discrete_vertex_invariant(v,graph);
    }
    result_type max()
    {
        return MAX_LABEL+1;
    }
};

//helper function to help with argument deduction
template <typename Graph>
discrete_vertex_invariant_functor<Graph> make_discrete_vertex_invariant(const Graph &g)
{
    return discrete_vertex_invariant_functor<Graph>(g);
}

You could then invoke isomorphism using its named-parameter version:

bool ret=isomorphism(g1, g2, 
            isomorphism_map(make_iterator_property_map(f.begin(), v1_index_map, f[0]))
            .vertex_invariant1(make_discrete_vertex_invariant(g1))
            .vertex_invariant2(make_discrete_vertex_invariant(g2))
         );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top