[BGL] How do I iterate over a labeled graph?
I am trying to iterate over my labeled_graph like so: struct Vertex { std::string vertType; }; typedef Graph::vertex_iterator VertexIter; VertexIter vertexIter, vertexEnd; for (tie(vertexIter, vertexEnd) = vertices(graph); vertexIter != vertexEnd; vertexIter++) { std::string vertexType = graph[*vertexIter].vertType; } However, I get a compiler error saying that graph has no operator [] that accepts an unsigned int. How should I be doing what I'm trying to do? -- View this message in context: http://boost.2283326.n4.nabble.com/BGL-How-do-I-iterate-over-a-labeled-graph... Sent from the Boost - Users mailing list archive at Nabble.com.
On Fri, 12 Oct 2012, eric wrote:
I am trying to iterate over my labeled_graph like so:
struct Vertex { std::string vertType; }; typedef Graph::vertex_iterator VertexIter; VertexIter vertexIter, vertexEnd; for (tie(vertexIter, vertexEnd) = vertices(graph); vertexIter != vertexEnd; vertexIter++) { std::string vertexType = graph[*vertexIter].vertType; }
However, I get a compiler error saying that graph has no operator [] that accepts an unsigned int. How should I be doing what I'm trying to do?
The easiest is probably to use graph.graph()[*vertexIter]. That gets the underlying graph then indexes that using the vertex. -- Jeremiah Willcock
Okay, thank you ... new issue.... I am using a labeled_graph, and if I assign a vertex property and then try to get that node again to check the value (like so): Vertex rootVert = patentGraph[rootName]; rootVert.vertType = "Root"; rootVert = patentGraph[rootName]; At the end rootVert.vertType is no longer "Root". Am I getting some sort of const reference such that my assignment is getting dropped on the floor? -- View this message in context: http://boost.2283326.n4.nabble.com/BGL-How-do-I-iterate-over-a-labeled-graph... Sent from the Boost - Users mailing list archive at Nabble.com.
On Fri, 12 Oct 2012, eric wrote:
Okay, thank you ... new issue....
I am using a labeled_graph, and if I assign a vertex property and then try to get that node again to check the value (like so):
Vertex rootVert = patentGraph[rootName]; rootVert.vertType = "Root"; rootVert = patentGraph[rootName];
At the end rootVert.vertType is no longer "Root". Am I getting some sort of const reference such that my assignment is getting dropped on the floor?
If Vertex is your vertex property type, you are getting a copy and so your updates are being dropped. Declaring rootVert as a Vertex& might fix your issue. -- Jeremiah Willcock
Ha! Yes. It's been a while since I've programmed in C++ and I'm a little rusty. Thanks! That got it working. -- View this message in context: http://boost.2283326.n4.nabble.com/BGL-How-do-I-iterate-over-a-labeled-graph... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
eric
-
Jeremiah Willcock