부스트 그래프 라이브러리를 사용하여 double
에지 가중치와 double
버텍스 가중치를 가진 무향 그래프를 저장하고 있습니다. 내 코드의 여러 위치에서 최단 경로를 검색하기 위해 Dijkstra의 알고리즘을 적용해야합니다. 내 가중치로 저장된 모서리 가중치를 일시적으로 무시하고 싶다는 결정을 내리기 전까지는 (임시로만 그래프 가중치가 수정되지 않아야 함) 이렇게하는 것이 좋습니다. 내 코드는 기본적으로 다음과 같습니다, 그래프의 에지 가중치가 나중에 변경 될 것입니다 비록boost :: dijkstra_shortest_paths가 내부 그래프 가중치를 덮어 쓰시겠습니까?
// Initial typedefs
typedef boost::property<boost::edge_weight_t, double> edge_weight_t;
typedef boost::property<boost::vertex_discover_time_t, double> vertex_weight_t;
typedef boost::adjacency_list<boost::vecS,
boost::vecS,
boost::undirectedS,
vertex_weight_t,
edge_weight_t> graph_t;
// In a function, where graph is a const reference of type graph_t
std::vector<double> pathLengths(boost::num_vertices(graph));
boost::property_map<graph_t, boost::edge_weight_t>::type weightMap;
boost::graph_traits<graph_t>::edge_iterator e_it, e_it_end;
for(boost::tie(e_it, e_it_end) = boost::edges(graph);
e_it != e_it_end;
++e_it)
{
weightMap[ *e_it ] = 1.0;
}
boost::dijkstra_shortest_paths(graph,
boost::vertex(vertex, graph),
boost::distance_map(&pathLengths[0]).weight_map(weightMap));
위의 코드에서 const를 참조입니다. 내가 도대체 뭘 잘못하고있는 겁니까? 또는 더 구체적으로 가중치 그래프에서 가장자리 가중치를 일시적으로 무시할 수 있습니까?
분명히 현재의 가장자리 가중치를 저장하고이를 가중치로 바꾸고 나중에 다시 변경할 수 있습니다. 그러나, 나는 그 내가 오전 잘못 확신하고, 나는이 문제를 무시하고 싶지 않아요.
감사합니다. 답변을 수락하는 데 오랜 시간이 걸려서 죄송합니다. – Gnosophilon