Reputation: 195
Just trying to get my head around the Boost Graph Library and I have a few questions. I'm writing some code which is a wrapper class around a BGL graph. The idea is that I can manipulate the graph however I want, then call a wrapper method to output the graph in GEXF (XML) format.
My code is something like this:
struct Vertex {
std::string label;
...
};
struct Edge {
std::string label;
double weight;
...
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, Vertex, Edge> GraphType;
template <typename Graph>
class GEXF
{
private:
Graph graph;
...
};
template <typename Graph>
void GEXF<Graph>::buildXML()
{
...
// output the edges
property_map<adjacency_list<>, edge_index_t>::type edge_id = get(edge_index, graph);
GraphType::edge_iterator e, e_end;
for(tie(e, e_end) = edges(graph); e != e_end; ++e)
{
xmlpp::Element *edge = ePtr->add_child("edge");
// next line gives an error, property not found
edge->set_attribute("id", tostring<size_t>(get(edge_id, *e)));
edge->set_attribute("source", tostring<size_t>(source(*e, graph)));
edge->set_attribute("target", tostring<size_t>(target(*e, graph)));
}
}
...
// instantiate in main():
GEXF<GraphType> gexf;
Here are my questions:
When I use bundled properties, I can access vertex_index, but I can't access edge_index. How do I get access to edge indices?
In the code above, I wanted to keep the GEXF class generic, but I ran into a problem when I tried to declare Graph::edge_iterator e, e_end;
The above code works, but it's using a concrete type. How should I declare the edge_iterator generically?
Upvotes: 5
Views: 2141
Reputation: 4251
There is no edge_index by default in a boost::adjacency_list<...>
object because maintaining one impacts the complexity. You must create one yourself, but you must take some care that it provides the desired functionality.
Previously :
Boost Subgraph and Bundled properties
edge_index zero for all edges?
Boost Graph edges with indexes
Upvotes: 3