|
Boost Users : |
From: a_schweitzer (a_schweitzer_at_[hidden])
Date: 2002-06-06 20:01:46
I'm not sure, but after playing with this for a while, I think the
vertex and edge objects (vertex_descriptor, edge_descriptors) used by
the graphs are opaque handles: you can't get at their contents
directly.
To attach properties to the vertices or graph I did the following:
-> In the adjacency list template declaration, specify a vertex
property class and an edge property class.
-> This class is some version of a boost "property" class.
-> Before you define this class you use a macro to define a string
identifying it.
-> To access your data you call get(id_string, Graph), which returns
a "property map" class. The property map class seems to be a boost
way of doing things.
-> Then you get your data from the map, using either a different
verstion of get or operator []. So what I did ended up doing to get
data was something like the following, assuming I had a
vertex_descriptor v, say from an add_vertex:
int iColor = get(vertex_color, MyGraphObject)[v];
Part of what I ended up doing was:
//In properties.hpp I added:
BOOST_DEF_PROPERTY(vertex, custom);
BOOST_DEF_PROPERTY(edge, type);
BOOST_DEF_PROPERTY(edge, custom);
//Then I defined:
typedef property < edge_name_t, int, property < edge_type_t,
eEdgeTypes > > EProps ;
//This gives edges two properies: an int accessed through edge_name
// and enumerated eEdgeTypes accessed through edge_type
class VertexProperties
{
public:
char m_cName;
int m_iDFSOrder;
int m_iRootIdx;
int m_iComponent;
int m_iComponentHeight;
bool m_bSelfLoop;
VertexProperties(){memset(this, 0, sizeof(*this));}
};
typedef property < vertex_custom_t, VertexProperties, property <
vertex_index_t, int > >
VProps;
//That gives each vertex a VertexProperties class accessible through
//vertex_custom, and an integer index property accessible through
//vertex_index.
//finally here's the graph definition:
typedef adjacency_list< listS,vecS,directedS,VProps,EProps > Graph;
//to access my custom properties I would do something like this:
Graph g;
vertex_descriptor v;
get(vertex_custom, g)[v].m_iDFSOrder = iNextDFSOrder++;
Gloomy PS: I got all my code working --- and then the MS VC++
compiler stopped working, giving me internal errors. On Windows CE
(Platform Builder) I couldn't get it working at all.
--- In Boost-Users_at_y..., "¹Ú±â¼ö" <yg-boost-users_at_m...> wrote:
> for example,
>
> class Node
> {
> public:
> int m_id;
> };
>
> class Edge
> {
> public:
> int from_node_id;
> int to_node_id;
> };
>
> How can I use this class to make graph?
> many examples show only integer id graph..
>
> thanks in advance
>
>
> ----------------------------------------
> Ki-Soo, Park
> HP: 82-11-9040-4957
> e-mail: park_at_e...
> wfms123_at_h...
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net