2012-08-17 93 views
5

所以,我必須在今天通過Boost文檔一個小時。我必須失明。我希望我有一個簡單的問題:從boost獲得邊緣屬性(包括相關頂點):adjacency_list

如何獲得帶有boost :: adjacency_list的邊的相應頂點?

我有下面的代碼,我想弄清楚:

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph; 
typedef boost::graph_traits<Graph>::edge_iterator EdgeIterator; 
typedef std::pair<EdgeIterator, EdgeIterator> EdgePair; 

EdgePair ep; 
for (ep = edges(g); ep.first != ep.second; ++ep.first) 
{ 
    // Get the two vertices that are joined by this edge... 
} 

任何人都知道如何做到這一點?

感謝

回答

8

你可以找到你需要this page(在所謂的「非成員函數」一節)的功能。你需要的是sourcetarget

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph; 
typedef boost::graph_traits<Graph>::edge_iterator EdgeIterator; 
typedef std::pair<EdgeIterator, EdgeIterator> EdgePair; 
typedef boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor; 

EdgePair ep; 
VertexDescriptor u,v; 
for (ep = edges(g); ep.first != ep.second; ++ep.first) 
{ 
    // Get the two vertices that are joined by this edge... 
    u=source(*ep.first,g); 
    v=target(*ep.first,g); 
} 
+0

謝謝! – MichaelM 2012-08-21 04:12:56

相關問題