5
그래프의 가장자리를 반복하고 각 에지의 무게를 검사해야합니다. 나는 가장자리를 수정하지 않기 때문에, 함수는 const 참조를 그래프로 취한다. 그러나 에지 가중치를 얻는 유일한 방법은 속성 맵에 대한 액세스 권한을 얻는 것입니다. 이는 속성을 위반하는 것으로 보입니다.const 부스트 :: 그래프의 에지 가중치 반복
void printEdgeWeights(const Graph& graph) {
typedef Graph::edge_iterator EdgeIterator;
std::pair<EdgeIterator, EdgeIterator> edges = boost::edges(graph);
typedef boost::property_map<Graph, boost::edge_weight_t>::type WeightMap;
// The following line will not compile:
WeightMap weights = boost::get(boost::edge_weight_t(), graph);
EdgeIterator edge;
for (edge = edges.first; edge != edges.second; ++edge) {
std::cout << boost::get(weights, *edge) << std::endl;
}
}
그래서 나는이 작업을 수행해야한다 :이 문제를 방지 할 수있는 방법이
Graph& trust_me = const_cast<Graph&>(graph);
WeightMap weights = boost::get(boost::edge_weight_t(), trust_me);
있습니까?
부수적으로, 속성 맵 조회가 일정 시간일까요?
참고로, 여기 내 정의 그래프입니다.
struct FeatureIndex { ... };
typedef boost::property<boost::vertex_index_t, int,
FeatureIndex>
VertexProperty;
typedef boost::property<boost::edge_index_t, int,
boost::property<boost::edge_weight_t, int> >
EdgeProperty;
typedef boost::subgraph<
boost::adjacency_list<boost::vecS,
boost::vecS,
boost::undirectedS,
VertexProperty,
EdgeProperty> >
Graph;
고마워요!