Boost Graph库:捆绑属性和跨边缘迭代

Mic*_* D. 5 c++ templates boost boost-graph

只是想让我了解Boost Graph库,我有几个问题。我正在写一些代码,它是围绕BGL图的包装器类。我的想法是,我可以随意操作图形,然后调用包装器方法以GEXF(XML)格式输出图形。

我的代码是这样的:

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;
Run Code Online (Sandbox Code Playgroud)

这是我的问题:

  1. 使用捆绑属性时,我可以访问vertex_index,但不能访问edge_index。如何获得边缘索引?

  2. 在上面的代码中,我想保持GEXF类的通用性,但是当我尝试声明Graph::edge_iterator e, e_end;上述代码时,我遇到了一个问题,但上面的代码使用的是具体类型。我应该如何通用地声明edge_iterator?

Jef*_*ges 3

默认情况下,对象中没有 edge_index,boost::adjacency_list<...>因为维护它会影响复杂性。您必须自己创建一个,但必须注意它是否提供所需的功能。

之前 :

增强子图和捆绑属性

所有边的edge_index都为零?

使用索引增强图边