Boost图形库:捆绑属性和遍历边缘

5

我正在尝试理解Boost Graph Library,有几个问题想请教。我正在编写一个包装类,用于封装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;

以下是我的问题:

  1. 当我使用捆绑属性时,我可以访问vertex_index,但我无法访问edge_index。如何获取对边缘索引的访问权限?

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

1个回答

3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接