Iterater for subset extraction?

I have a couple of n00b questions. I have constructed a BGL graph that uses the edge_name_t property to road names. I want to change the weights of some of the roads based on input from the user. Is there a way to set up an iterator to step through edges that have names which match elements of a set? (e.g., "A,B,B1,L,M") In a related question, I need to extract a vertex whose vertex_index_t value matches a specific value. The vertices were not entered in any specific order, so the "vertex(1, g)" function returns the first vertex to have been entered into the graph, but not necessarily the one whose index value is "1". Thanks, Thom -- this sig intentionally left blank

Hi Thom,
2006/11/8, Thom DeCarlo
I have a couple of n00b questions. I have constructed a BGL graph that uses the edge_name_t property to road names. I want to change the weights of some of the roads based on input from the user. Is there a way to set up an iterator to step through edges that have names which match elements of a set? (e.g., "A,B,B1,L,M")
In a related question, I need to extract a vertex whose vertex_index_t value matches a specific value. The vertices were not entered in any specific order, so the "vertex(1, g)" function returns the first vertex to have been entered into the graph, but not necessarily the one whose index value is "1".
If I don't get you wrong, there's no direct way in the BGL to do that. The properties you attach to a vertex or an edge are normally accessed through the edge or vertex descriptor respectively. What you want to do is the other way around. Get from a property to the edge desciptor(s) that match that property or in the case of vertex_index to the vertex descriptor. Maybe you can use Bimap (http://tinyurl.com/y95qng), where you can get keys (edge/vertex-descriptors) from values together with the concept of exterior property maps (http://tinyurl.com/yhju58) and Constructing an Exterior Property Map. Reading further in the Bimap docs, I think I found what you want: http://tinyurl.com/yxzpme HTH, Stephan

-----Original Message----- From: Stephan Diederich
Hi Thom,
2006/11/8, Thom DeCarlo
: I have a couple of n00b questions. I have constructed a BGL graph that uses the edge_name_t property to road names. I want to change the weights of some of the roads based on input from the user. Is there a way to set up an iterator to step through edges that have names which match elements of a set? (e.g., "A,B,B1,L,M")
In a related question, I need to extract a vertex whose vertex_index_t value matches a specific value. The vertices were not entered in any specific order, so the "vertex(1, g)" function returns the first vertex to have been entered into the graph, but not necessarily the one whose index value is "1".
If I don't get you wrong, there's no direct way in the BGL to do that. The properties you attach to a vertex or an edge are normally accessed through the edge or vertex descriptor respectively. What you want to do is the other way around. Get from a property to the edge desciptor(s) that match that property or in the case of vertex_index to the vertex descriptor. Maybe you can use Bimap (http://tinyurl.com/y95qng), where you can get keys (edge/vertex-descriptors) from values together with the concept of exterior property maps (http://tinyurl.com/yhju58) and Constructing an Exterior Property Map.
Reading further in the Bimap docs, I think I found what you want: http://tinyurl.com/yxzpme
HTH, Stephan
Well, once I figure out how to use it, I've found the Filter Iterator (http://www.boost.org/libs/iterator/doc/filter_iterator.html) which may solve the first part of my problem. For the second part, I'm not sure exactly what you mean. Let me describe the problem a bit more. Each vertex has an internal property that I've created: // define a struct for the vertex coordinate properties typedef struct vCoord { double Lon; //degrees double Lat; //degrees double Alt; //meters above WGS84 ellipsoid } Coord; The user will provide a specific coordinate for his starting and ending points and a preferred route of street names. I need to traverse the BGL graph to find the vertex nearest the user's coordinate that is also on the route. (Initially, I thought I was going to give each vertex a name and the user would provide that name, hence the search for a specific vertex index value. But, it is more likely that the user will know his position than the neighborhood of road names.) I think the filter iterator will also help with this problem. At least it will let me narrow down the number of vertices that need to be compared when searching for the closest one. Does this sound reasonable? Thanks, Thom

Hi Thom,
Well, once I figure out how to use it, I've found the Filter Iterator (http://www.boost.org/libs/iterator/doc/filter_iterator.html) which may solve the first part of my problem.
The filter iterator can be used, if you want to iterate over all of your container (linear time), and extract "on the fly" only those values you are interested in. With your edge_name_t example, you can take an iterator to the edges, and a predicate which extracts the edge name from the edge-property and compares those names to the list of searched streets. But still, this is a linear time operation. The other way would be to have a map of street-names, which maps to the edge_descriptors in your graph (if the edge_name_t is attached to you edges). In this map you can search (e.g. map::find) in logarithmic time.(But only with starting letters) To summarize: In BGL, you have properties attached to edges/vertices. To access them, you have to specify the {vertex,edge}descriptor. In your case, if I understand your problem, you want to specify the street-name (or part of it) to get the descriptor (and therefrom use the BGL to get to the next street, and so on) That's why I came up with Bimap. It provides both ways.
The user will provide a specific coordinate for his starting and ending points and a preferred route of street names. I need to traverse the BGL graph to find the vertex nearest the user's coordinate that is also on the route. (Initially, I thought I was going to give each vertex a name and the user would provide that name, hence the search for a specific vertex index value. But, it is more likely that the user will know his position than the neighborhood of road names.)
The case with you vertex properties is quite different. To find the next vertex to the specified vertex you need to calculate a distance value (e.g. euclidian). If you don't want to check all vertices against your initial coordinates, you need a data structure which limits the search space for you, e.g. a simple grid.
I think the filter iterator will also help with this problem. At least it will let me narrow down the number of vertices that need to be compared when searching for the closest one.
Hm, how are you going to do this? Cheers, Stephan
participants (2)
-
Stephan Diederich
-
Thom DeCarlo