I wrote a very simple sample using BGL adjacent list and using a random access EdgeList. But when I invoke remove_out_edge method, It seems wrong. My config is Boost 1.33.1 and Visual Studio 2005, here is my code:
------------x-------------------------------Begin here-----------------------------------------x-------------
#include
#include <string>
using namespace boost;
using namespace std;
namespace boost{
struct vertex_label_t {
typedef vertex_property_tag kind;
};
}
template
void print_graph(EdgeIter first, EdgeIter last, const Graph& G)
{
typedef typename property_map::const_type LabelMap;
LabelMap label = get(vertex_label_t(), G);
typedef typename boost::property_traits<LabelMap>::value_type LabelType;
LabelType src_label, targ_label;
while (first != last) {
src_label = boost::get(label, source(*first, G));
targ_label = boost::get(label, target(*first, G));
cout << src_label << " <-> "
<< targ_label << endl;
++first;
}
}
typedef property LabelProperty;
typedef adjacency_list MyGraphType;
bool AnyEdge(MyGraphType::edge_descriptor e)
{
return true;
}
int main()
{
typedef pair Pair;
Pair edge_array[8] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair(2,4), Pair(3,1), Pair(3,4), Pair(4,1) };
MyGraphType G(5);
for (int i = 0; i < 8; ++i)
add_edge(edge_array[i].first, edge_array[i].second, G);
property_map::type
name = get(vertex_label_t(), G);
boost::put(name, 0, "0");
boost::put(name, 1, "1");
boost::put(name, 2, "2");
boost::put(name, 3, "3");
boost::put(name, 4, "4");
print_graph(edges(G).first, edges(G).second, G);
// Remove out edges of vertex 0
cout << "Remove out edges of vertex 0" << endl;
remove_out_edge_if(0, AnyEdge, G);
print_graph(edges(G).first, edges(G).second, G);
}
------------x-------------------------------End here-----------------------------------------x-------------
and the result is:
------------------------------------------------------------------------------------------------------------------
0 <-> 1
0 <-> 2
0 <-> 3
0 <-> 4
2 <-> 4
3 <-> 1
3 <-> 4
4 <-> 1
Remove out edges of vertex 0
0 <-> 2
0 <-> 4
3 <-> 1
4 <-> 1
------------------------------------------------------------------------------------------------------------------
Is there something wrong?
---------------------------------
Brings words and photos together (easily) with
PhotoMail - it's free and works with Yahoo! Mail.