Boost Graph Library: Added Properties and Edge Iteration

Just trying to plunge into the Boost Graph library, and I have a few questions. I am writing code that is a wrapper class around a BGL graph. The idea is that I can manipulate the graph, but I want, and then call the wrapper method to output the graph in GEXF (XML) format.

My code looks 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 related properties, I can access vertex_index, but I can not access edge_index. How to access edge indices?

  • In the above code, I wanted to keep the generic GEXF class, but I had a problem when I tried to declare Graph::edge_iterator e, e_end; . The above code works, but it uses a specific type. How should I declare edge_iterator in general?

+4
source share
1 answer

The boost::adjacency_list<...> object does not have edge_index by default, because saving one affects complexity. You must create it yourself, but you must be careful to provide the required functionality.

Earlier:

Enhance subgraph and related properties

edge_index zero for all edges?

Increase graph bounds with indices

+2
source

All Articles