BGL의 문맥에서 나는 in_edges
과 out_edges
을 반복 할 필요가 있습니다. 그러나 나는 역방향 가장자리의 일부인 것을 제외하고 싶습니다. 즉, 역방향 가장자리의 일부인 제외 할 것입니다. property_map
. 아래 코드는 내가하고 싶은 것을 보여 주지만 물론 property_map
에는 find
과 end
메서드가 없습니다.부스트의 property_map은 키가 존재하는지 테스트합니까?
업데이트 : 가능한 해결책은 그래프를 만드는 동안 반대쪽 가장자리가 포함 된지도와 같은 별도의 구조를 유지하는 것입니다. 이 함수는 그래프 건물을 제어 할 수는 있지만 작동하지 않습니다. 왜냐하면 read_dimacs_max_flow
함수를 사용하여 DIMACS 형식의 그래프 파일을 읽었 기 때문입니다. 그래서 나는 BGL의 접근성 방법에 의존해서 무엇이 무엇인지 알아낼 수 있습니다.
그래프 정의 :
typedef adjacency_list_traits<vecS, vecS, bidirectionalS> ttraits;
typedef adjacency_list<vecS, vecS, bidirectionalS,
// vertex properties
property<vertex_index_t, int,
property<vertex_color_t, default_color_type> >,
// edge properties
property<edge_capacity_t, int,
property<edge_residual_capacity_t, int,
property<edge_reverse_t, ttraits::edge_descriptor> > >, no_property, vecS> tbgl_adjlist_bidir;
typedef graph_traits<tbgl_adjlist_bidir>::vertex_descriptor tvertex;
typedef graph_traits<tbgl_adjlist_bidir>::edge_descriptor tedge;
typedef property_map<tbgl_adjlist_bidir, edge_capacity_t>::type tedge_capacity_map;
typedef property_map<tbgl_adjlist_bidir, edge_reverse_t>::type treverse_edge_map;
typedef property_map<tbgl_adjlist_bidir, vertex_color_t>::type tvertex_color_map;
typedef property_map<tbgl_adjlist_bidir, vertex_index_t>::type tvertex_index_map;
typedef graph_traits<tbgl_adjlist_bidir>::vertex_iterator tvertex_iterator;
typedef graph_traits<tbgl_adjlist_bidir>::edge_iterator tedge_iterator;
typedef graph_traits<tbgl_adjlist_bidir>::out_edge_iterator tout_edge_iterator;
typedef graph_traits<tbgl_adjlist_bidir>::in_edge_iterator tin_edge_iterator;
과 내가하고 싶은 (그러나 아래의 오류와 함께 컴파일되지 않습니다) 무엇의 예를 조각 :
tvertex_index_map indices = get(vertex_index, bgl_adjlist_bidir);
tedge_capacity_map capacities = get(edge_capacity, bgl_adjlist_bidir);
treverse_edge_map rev_edges = get(edge_reverse, bgl_adjlist_bidir);
// iterate all vertices in the right order
for (int current = 0; current < m_num_vertices; ++current) {
printf("processing vertex=%d\n", current);
tin_edge_iterator ei1, ei1_end;
for (tie(ei1, ei1_end) = in_edges(tvertex(current), bgl_adjlist_bidir); ei1 != ei1_end; ++ei1) {
// exclude reverse edges <<<<<<<======= HOW DO I DO THIS??
if (rev_edges.find(*ei1) != rev_edges.end()) {
continue;
}
int in = indices[boost::source(*ei1, bgl_adjlist_bidir)];
printf("in edge: %d <- %d \n", current, in);
}
}
컴파일러 오류 :
/Users/bravegag/code/fastcode_project/build_debug$ make 2> out ; grep -i "error" ./out
[ 2%] Building CXX object CMakeFiles/submodularity.dir/src/graph/hp_adjlist_bidir.cc.o
/Users/bravegag/code/fastcode_project/code/src/api/hp_adjlist_bidir.h:146:18: error: 'treverse_edge_map' has no member named 'find'
/Users/bravegag/code/fastcode_project/code/src/api/hp_adjlist_bidir.h:146:42: error: 'treverse_edge_map' has no member named 'end'
make[2]: *** [CMakeFiles/submodularity.dir/src/graph/hp_adjlist_bidir.cc.o] Error 1
make[1]: *** [CMakeFiles/submodularity.dir/all] Error 2
make: *** [all] Error 2
그런 상세하고 유익한 답변을 해주셔서 감사합니다. 좋은 정보가 많이 있습니다. 그러나 그래프를 직접 작성할 수는 없지만, 내지도를 사용하는 것이 좋습니다. 대신에 BGL 함수'read_dimacs_max_flow'를 사용하여 DIMACS 형식의 그래프 파일을 읽었습니다. 따라서 BGL의 함수를 사용하여 무엇이 무엇인지 알아낼 수 있습니다. 즉, 엉덩이에 왕가의 고통이 있습니다. ( –
이 게시물을 보내 주셔서 감사합니다. 그것은 나를 많이 영감을. 나는 부스트 그래프 라이브러리의 가난한 문서를 고통스러워하고 올바른 매크로를 실행하는 올바른 인수를 추가 할 수있는 방법을 찾기 위해 전체 구글 검색해야 최대 흐름 알고리즘을 부스트. 이제 내 자신의 표준을 시도 할거야 ::지도 유형의 역지도와 그것이 작동되기를 바랍니다. –