Change value of adjacent vertices and remove self loop
Posted
by
StereoMatching
on Stack Overflow
See other posts from Stack Overflow
or by StereoMatching
Published on 2014-06-01T02:50:39Z
Indexed on
2014/06/01
3:26 UTC
Read the original article
Hit count: 83
Try to write a Karger’s algorithm with boost::graph
example (first column is vertice, other are adjacent vertices):
- 1 2 3
- 2 1 3 4
- 3 1 2 4
- 4 2 3
assume I merge 2 to 1, I get the result
- 1 2 3 2 1 1 3 4
- 2 1 3 4
- 3 1 2 4
- 4 2 3
first question : How could I change the adjacent vertices("2" to "1") of vertice 1?
my naive solution
template<typename Vertex, typename Graph>
void change_adjacent_vertices_value(Vertex input, Vertex value, Graph &g)
{
for (auto it = boost::adjacent_vertices(input, g);
it.first != it.second; ++it.first){
if(*it.first == value){
*(it.first) = input; //error C2106: '=' : left operand must be l-value
}
}
}
Apparently, I can't set the value of the adjacent vertices to "1" by this way
The result I want after "change_adjacent_vertices_value"
- 1 1 3 1 1 1 3 4
- 2 1 3 4
- 3 1 2 4
- 4 2 3
second question : How could I pop out the adjacent vertices?
Assume I want to pop out the consecutive 1 from the vertice 1 The result I expected
- 1 1 3 1 3 4
- 2 1 3 4
- 3 1 2 4
- 4 2 3
any function like "pop_adjacent_vertex" could use?
© Stack Overflow or respective owner