Question

I'm trying boost::graph header library, but I still can't add verticles to my graph.

Here is how I use add_vertex function :

void GraphManager::addToGraph(VertexProperties node){

    //no error, but i do not need it
    vertex_t v = boost::add_vertex(graph);

    //compilation error
    vertex_t v = boost::add_vertex(node, graph);

    /*...*/
}

My definitions are here :

#ifndef GRAPH_DEFINITION_H
#define GRAPH_DEFINITION_H

#include <boost/graph/adjacency_list.hpp>
#include "matchedword.h"

typedef MatchedWord* VertexProperties;

struct EdgeProperties
{
   int distance;
   EdgeProperties() : distance(0) {}
   EdgeProperties(int d) : distance(d) {}
};

struct GraphProperties {

};

typedef boost::adjacency_list<
   boost::vecS, boost::vecS, boost::undirectedS,
   boost::property<VertexProperties, boost::vertex_bundle_t>,
   boost::property<EdgeProperties, boost::edge_bundle_t>,
   boost::property<GraphProperties, boost::graph_bundle_t>
> Graph;

typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<Graph>::edge_descriptor edge_t;


#endif // GRAPH_DEFINITION_H

Any idea ? Thanks.

error: no matching function for call to 'add_vertex(MatchedWord*&, Graph&)' candidates are: [...] template typename Config::vertex_descriptor boost::add_vertex(const typename Config::vertex_property_type&, boost::adj_list_impl&)

note: template argument deduction/substitution failed:

note: 'Graph {aka boost::adjacency_list, boost::property, boost::property >}' is not derived from 'boost::adj_list_impl'

I do not understand the meaning of this error output.

Was it helpful?

Solution 2

Ravenspoint, you were right, I just misused bundle properties.

Here is my code, which works now :)

#ifndef GRAPH_DEFINITION_H
#define GRAPH_DEFINITION_H

#include <boost/graph/adjacency_list.hpp>
#include "matchedword.h"

struct VertexProperties {
public :
    MatchedWord* matchedWord;
};

struct EdgeProperties
{
   int distance;
   EdgeProperties() : distance(0) {}
   EdgeProperties(int d) : distance(d) {}
};

struct GraphProperties {

};

typedef boost::adjacency_list<
   boost::vecS, boost::vecS, boost::undirectedS,
   VertexProperties,
   EdgeProperties,
   GraphProperties
> Graph;

typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<Graph>::edge_descriptor edge_t;


#endif // GRAPH_DEFINITION_H

The called function (maybe I'll rework the definition later) is:

void GraphManager::addToGraph(VertexProperties node){
    vertex_t v = boost::add_vertex(graph);
    graph[v].matchedWord = node.matchedWord;
}

Thanks for your answers all !

OTHER TIPS

It is easier to use bundled properties.

Something like this:

// A class to hold bundled properties for a vertex
// In this case, we have a pointer to a MatchedWord object

class vertex_props {
public:
MatchedWord * pMW;
};

Define a graph type with bundled properties

typedef boost::adjacency_list<
boost::vecS, boost::vecS, boost::undirectedS,
vertex_props,
...
> Graph_t;

Now you can add a vertex with specified bundled properties like this

void GraphManager::addToGraph(MatchedWord * node){
   graph[ boost::add_vertex(graph) ].pMW = node;
   ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top