2011-10-14 68 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?

回答