|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-04-16 08:47:06
On Wednesday 16 April 2003 12:18 am, Eric Fowler wrote:
> Sorry if this is obvious, I am just getting started with BGL.
>
> I wish to make a simple geometric graph, in which vertices are comprised of
> points in x, y space(x, y being unsigned integers), and edge weights are
> unsigned integers equal to the distance-squared between the vertex points.
>
> Simple, huh?
>
> Here's where I am at:
>
> #include "stdafx.h"
> #include <boost\config.hpp>
> #include <boost\graph\adjacency_list.hpp>
> using namespace boost;
>
> typedef std::pair<unsigned, unsigned> Point;
> int main(int argc, char* argv[])
> {
> typedef adjacency_list<listS, vecS, directedS> Graph;
> Graph g;
> Point p(1, 2); //just to show it all compiles
> return 0;
> }
>
> Now, how do I "tell" my Graph I am storing Point vertices with unsigned int
> edges? Do I need to define properties? How?
You'll need create a name (tag) for the point property:
struct vertex_location_t { typedef boost::vertex_property_tag kind; };
Then install the property into the vertex:
typedef adjacency_list<listS, vecS, directedS,
property<vertex_location_t, Point> >
Graph;
Similarly, you can install an edge weight property with the predefined name
boost::edge_weight_t on the edges this way:
typedef adjacency_list<listS, vecS, directedS,
property<vertex_location_t, Point>,
property<edge_weight_t, unsigned int> >
Graph;
HTH,
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk