[BGL] property_map not compiling because it's not l-value?

Hi,
I'm trying to use the concepts in the Kevin Bacon example in my code and
am having trouble with compiling.
http://www.boost.org/libs/graph/doc/kevin_bacon.html
When I compiled the example by itself, it ran fine. However when I
changed it to my data, then it gave me a compile error of "error C2106:
'=' : left operand must be l-value"
I don't know why this is, other than variable name, I just changed the
vertex type from string to index. Nothing that I can see would cause
this.
The line not compiling is "grid_id[u] = gid;" See below for code.
************************************************************************
****************************
typedef property_map

On 11/2/07, Ferng, Andrew D
Hi,
I'm trying to use the concepts in the Kevin Bacon example in my code and am having trouble with compiling. http://www.boost.org/libs/graph/doc/kevin_bacon.html
When I compiled the example by itself, it ran fine. However when I changed it to my data, then it gave me a compile error of "error C2106: '=' : left operand must be l-value"
I don't know why this is, other than variable name, I just changed the vertex type from string to index. Nothing that I can see would cause this.
The line not compiling is "grid_id[u] = gid;" See below for code.
<snip>
Any ideas why this is? I'm confused as to what's causing this. Any other way to populate the property map?
I'm using VS2005 and boost 1.33.1.
Hi Andrew, Your code didn't show the type of graph you're using for interfaceGraph, but I'm going to assume that it's an adjacency_list using a std::vector to store the vertices. In that case, the vertex index is populated automatically with the indices of each vertex descriptor in the underlying vector, making the vertex index map read-only. In other configurations (for example, using a std::list to store the vertices) you can set the vertex index - in fact, you have to initialize it yourself if you're going to use it. The vertex index and edge index are used by most BGL algorithms to create property maps from vertices and edges to arbitrary types, so I'd recommend against using them for anything else (in your code, you're using them to store a grid id and connecting element id). Check out the documentation on bundled properties, which allow you to augment graphs with arbitrary properties easily (http://www.boost.org/libs/graph/doc/bundles.html). Regards, Aaron

Hi Aaron,
Thanks for the help! Still trying to understand how to use BGL.
As for the original graph type, I was using:
typedef adjacency_list<
vecS,
vecS,
undirectedS,
property

On 11/5/07, Ferng, Andrew D
Hi Aaron, Thanks for the help! Still trying to understand how to use BGL.
As for the original graph type, I was using: typedef adjacency_list< vecS, vecS, undirectedS, property
, property > ConnectionGraph; Having had no luck with it, I changed it back to the example using name / string and then it worked.
typedef adjacency_list< vecS, vecS, undirectedS, property
, property > ConnectionGraph; So I'm still confused as to why it would be a l-value issue in one case but not in the other. In both of these situations, the goal is trying to populate the property map right?
Vertex index maps and edge index maps are special cases - they shouldn't be used for any purpose but for mapping all vertices (or edges, respectively) in the graph g to unique indices in the range [0..num_vertices(g)) (or num_edges(g), respectively). Such a property map is useful because if you have a vertex or edge index map that returns indices in constant time, you can create constant-time property maps that map vertices/edges to _any_ type T by composing the vertex/edge index map with a std::vector that holds values of type T. If you need a property map to store something else, like a label for each vertex, you should use some other property map type (as you did above, with vertex_name_t or edge_name_t), or better yet, use bundled properties. As to why you get an lvalue property map in one case and an rvalue property map in the other case - if you store your vertices in a std::vector, the vertex index map can be provided for you, since the "vertex index" for each vertex can just be the index at which the vertex is stored. On the other hand, if you store vertices in a std::list, there's no natural association between vertices and the range [0..num_vertices(g)), so you have to populate one yourself (and these indices are stored internally along with the storage for the vertices). So, the mechanism used to provide the vertex index map is different depending on whether you store vertices in a vector or a list - in one case (list), you can put things into the map, in the other case (vector), you can't. Regards, Aaron
participants (2)
-
Aaron Windsor
-
Ferng, Andrew D