2011-01-26 3 views
2

그래프의 가장자리를 반복하고 에지 가중치를 출력하려고합니다. 나는 혼란 스럽다. 나는 "가장자리"를 출력하는 방법을 알고 있지만 실제로는 가장자리를 정의하는 꼭지점 (정점, 정점)입니다. 그렇다면 * edgePair.first를 EdgeWeightMap에 색인화하여 꼭짓점 * edgePair.first에서 시작하는 가장자리의 가중치를 얻으시겠습니까? 컴파일되지 않습니다 : "no operator for match < <".출력 BGL 에지 가중치

#include <iostream> 
#include <boost/graph/graph_traits.hpp> 
#include <boost/graph/adjacency_list.hpp> 

typedef boost::property<boost::edge_weight_t, double> EdgeWeightProperty; 
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, EdgeWeightProperty> Graph; 

int main(int,char*[]) 
{ 
    // Create a graph object 
    Graph g(2); 

    EdgeWeightProperty e = 5; 
    add_edge(0, 1, e, g); 

    boost::property_map<Graph, boost::edge_weight_t>::type EdgeWeightMap = get(boost::edge_weight_t(), g); 

    typedef boost::graph_traits<Graph>::edge_iterator edge_iter; 
    std::pair<edge_iter, edge_iter> edgePair; 
    for(edgePair = edges(g); edgePair.first != edgePair.second; ++edgePair.first) 
    { 
     std::cout << EdgeWeightMap[*edgePair.first] << " "; 
    } 

    return 0; 
} 

의견이 있으십니까?

감사합니다, 데이비드

이 코드에서
+0

다음을 참조하십시오 : http://programmingexamples.net/index.php?title=Boost 간단한 예제. –

답변

4

EdgeWeightProperty는 정점 속성보다는 가장자리 속성으로 선언하고, 그래서 그 속성 가장자리를 삽입 이해가되지 않습니다. adjacency_list typedef에 boost::no_propertyEdgeWeightProperty 앞에 추가하십시오. 또한 operator[]이 아닌 get(EdgeWeightMap, *edgePair.first)을 사용하는 것이 더 많은 속성 맵 유형에서 작동하므로이 값을 사용하는 것이 좋습니다.