2012-08-17 19 views
5

Vì vậy, tôi phải trải qua tài liệu Boost trong một giờ hôm nay. Tôi phải mù. Tôi có, tôi hy vọng, một câu hỏi đơn giản:Thuộc tính cạnh (bao gồm các đỉnh liên quan) từ boost :: adjacency_list

Làm thế nào để bạn nhận được các đỉnh tương ứng cho một cạnh với tăng :: adjacency_list?

Tôi có đoạn mã sau mà tôi đang cố gắng để tìm ra:

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... 
} 

Bất cứ ai cũng biết làm thế nào để làm điều này?

Cảm ơn

Trả lời

8

Bạn có thể tìm thấy các chức năng mà bạn cần trong this page (trong phần gọi là "Non-thành viên Chức năng"). Những thứ bạn cần là 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

Cảm ơn vì điều đó! – MichaelM

Các vấn đề liên quan