그래프의 가장자리를 반복하고 에지 가중치를 출력하려고합니다. 나는 혼란 스럽다. 나는 "가장자리"를 출력하는 방법을 알고 있지만 실제로는 가장자리를 정의하는 꼭지점 (정점, 정점)입니다. 그렇다면 * 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;
}
의견이 있으십니까?
감사합니다, 데이비드
이 코드에서
다음을 참조하십시오 : http://programmingexamples.net/index.php?title=Boost 간단한 예제. –