In the context of BGL, I need to iterate the in_edges
and out_edges
but I want to exclude those that are part of the reverse edges i.e. exclude those that are part of the reverse edges property_map
. The code below shows what I would like to do but of course the property_map
doesn't have find
and end
methods.
UPDATE:
A possible solution is to maintain a separate structure like a map containing the reverse edges while building the graph. This will work if I had control of the graph building but I don't because I use the function read_dimacs_max_flow
to read a graph file in DIMACS format. So I can only rely on BGL's accessibility methods to figure out what is what.
Graph definition:
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;
and the example snippet of what I would like to do (but doesn't compile with the error below):
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);
}
}
and the compiler error:
/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