-
June 22nd, 2010, 10:21 PM
#1
Boost Graph Library - Accessing a vertex
Hi,
I am a newbie to boost graph library (BGL).
1) To build a graph with vertices with unique ids - Able to do this
2) To get the vertex containing a specific idsI have created a graph with vertices that have a custom property. - how can I do this ?
The way I have tried to do is to iterate through all the vertices and checked each vertex's property value. Is there a better way to do this ?
Note - This field is a unique Id field
Can it be indexed based on the unique id, so that it can be accessed directly ?
Given below is a small example:
Code:
/*
Aim -
-----
1) To build a graph with vertices with unique ids - Able to do this
2) To get the vertex containing a specific ids - How do I do this ?
*/
#include "boost/graph/adjacency_list.hpp"
using namespace boost;
class VertId
{
public:
typedef boost :: vertex_property_tag kind;
};
int main()
{
typedef property<VertId, std :: string> VertIdProp;
typedef adjacency_list<
vecS,
vecS,
directedS,
VertIdProp
> GraphType;
GraphType g1;
std :: string vp1 = "a100",
vp2 = "a200",
vp3 = "a300";
add_vertex(vp1, g1);
add_vertex(vp2, g1);
add_vertex(vp3, g1);
property_map<GraphType, VertId> :: type propMap1;
propMap1 = get(VertId(), g1);
graph_traits<GraphType> :: vertex_iterator vertCurrItr, vertEndItr;
// search for vertex containing the id a300
for(
tie(vertCurrItr, vertEndItr) = vertices(g1);
vertCurrItr != vertEndItr;
vertCurrItr++
)
{
if(propMap1[*vertCurrItr] == "a300")
std :: cout << "found it!!\n";
}
return (0);
}
Thanks,
Muthu
-
June 23rd, 2010, 07:37 AM
#2
Re: Boost Graph Library - Accessing a vertex
Code:
Can it be indexed based on the unique id, so that it can be accessed directly ?
Not directly as far as I know, but it is if course possible to create a std::map from the relevant values to the corresponding vertices independent of the graph.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|