2011-10-14 150 views
4

试图让我的头绕着Boost Graph Library,我有几个问题。我正在编写一些围绕BGL图的包装类代码。这个想法是,我可以操纵图表,但我想要的,然后调用一个包装方法来输出GEXF(XML)格式的图形。Boost Graph Library:捆绑属性并遍历边缘

我的代码是这样的:

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?

回答