BGL: Copying graphs and edge_descriptors confusion
I have a graph, 'inputGraph' with a bool in its bundled edge properties. If I copy that graph with: Graph g = inputGraph; there seems to be some odd behavior with the edge_descriptors. If you take a look at this example: http://programmingexamples.net/index.php?title=CPP/Boost/BGL/CopyAGraph I set one of the edges to visible=0 and then output all of the edge visibilities using the iterator from boost::edges(g) - this works properly, the edge that I set to visible=0 indeeds shows up as such. However, if I instead use the iterator from boost::edges(inputGraph) , all of the edges appear as visible! Shouldn't the edge_descriptors be identical since the graph g is an exact copy of inputGraph? Can anyone explain why the last two loops in that example do not produce the same output? Thanks, David
Hi David, On Monday, 27. June 2011 19:25:58 David Doria wrote:
I have a graph, 'inputGraph' with a bool in its bundled edge properties. If I copy that graph with:
Graph g = inputGraph;
there seems to be some odd behavior with the edge_descriptors. If you take a look at this example:
http://programmingexamples.net/index.php?title=CPP/Boost/BGL/CopyAGraph
I set one of the edges to visible=0 and then output all of the edge visibilities using the iterator from boost::edges(g) - this works properly, the edge that I set to visible=0 indeeds shows up as such. However, if I instead use the iterator from boost::edges(inputGraph) , all of the edges appear as visible! Shouldn't the edge_descriptors be identical since the graph g is an exact copy of inputGraph?
Can anyone explain why the last two loops in that example do not produce the same output?
I can't explain to you why you observe this unexpected behavior, but there is also the copy_graph() function in the BGL which might perhaps suit your needs? Hope that helps, Best, Cedric
Thanks,
David _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I can't explain to you why you observe this unexpected behavior, but there is also the copy_graph() function in the BGL which might perhaps suit your needs?
Good to know, but that didn't change anything. I changed Graph g = inputGraph; to Graph g; boost::copy_graph(inputGraph, g); and the output was identical. Any other thoughts? David
On Mon, 27 Jun 2011, David Doria wrote:
I can't explain to you why you observe this unexpected behavior, but there is also the copy_graph() function in the BGL which might perhaps suit your needs?
Good to know, but that didn't change anything. I changed
Graph g = inputGraph;
to
Graph g; boost::copy_graph(inputGraph, g);
and the output was identical.
Any other thoughts?
Iterators are not preserved among copies of an object; they aren't in STL either. You need to use iterators from the same graph that you are trying to access with them. Note that this is also true for vertex and edge descriptors for some graph types (listS is the most common). -- Jeremiah Willcock
Iterators are not preserved among copies of an object; they aren't in STL either. You need to use iterators from the same graph that you are trying to access with them. Note that this is also true for vertex and edge descriptors for some graph types (listS is the most common).
Ah I see. Phew, that has been driving me nuts all morning. I was looking at the output (operator<<) of the edge_descriptors and they looked correct, but I guess they were pointing to the correct vertices, only in the wrong graph? Does the copy constructor do anything different than the copy_graph function that Cedric pointed out? David
On Mon, 27 Jun 2011, David Doria wrote:
Iterators are not preserved among copies of an object; they aren't in STL either. You need to use iterators from the same graph that you are trying to access with them. Note that this is also true for vertex and edge descriptors for some graph types (listS is the most common).
Ah I see. Phew, that has been driving me nuts all morning. I was looking at the output (operator<<) of the edge_descriptors and they looked correct, but I guess they were pointing to the correct vertices, only in the wrong graph?
Yes, probably. Some graph types do have descriptors that work across separate graph objects, but you should not rely on that.
Does the copy constructor do anything different than the copy_graph function that Cedric pointed out?
The copy constructor for adjacency_list just copies the raw data without actually traversing the graph. I know the compressed_sparse_row version takes arbitrary graphs and does a special-purpose algorithm that is similar to copy_graph in behavior; I do not know what other graph types do, but it should be equivalent to copy_graph. -- Jeremiah Willcock
participants (3)
-
Cedric Laczny
-
David Doria
-
Jeremiah Willcock