[BGL] How can I use vertex object rather than integer?
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@erhouse.co.kr wfms123@hotmail.com
Hello, You can't use your own vertex and edge classes with the adjacency_list class, however you can add extra data to the vertices and edges using internal properties. Page 52 of the BGL book has an explanation and examples. Also, of course you can create you own graph structure and then implement the BGL interface. Then all the BGL algorithms will work with your graph. You might find Chapter 10 of the BGL book helpful in doing this. Cheers, Jeremy On Wed, 5 Jun 2002, �ڱ�� wrote: yg-boo> for example, yg-boo> yg-boo> class Node yg-boo> { yg-boo> public: yg-boo> int m_id; yg-boo> }; yg-boo> yg-boo> class Edge yg-boo> { yg-boo> public: yg-boo> int from_node_id; yg-boo> int to_node_id; yg-boo> }; yg-boo> yg-boo> How can I use this class to make graph? yg-boo> many examples show only integer id graph.. yg-boo> yg-boo> thanks in advance yg-boo> ---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 855-3608 ----------------------------------------------------------------------
Thank you for your answer, Jeremy Siek.
but I can't be cheered. ( ^^; )
1. I ordered BGL book and will get it in 10 days.
( I live in korea, the 2002 FIFA world cup co-host. but not sell BGL book.)
2. Before Creating my graph structure and interface, what I want to do is :
(1) Add object pointer to integer graph(object has an integer ID).
(2) Bind the object's member function to visitor object.
for example,
using namespace std;
using namespace boost;
class MyVertexObject
{
:
public:
Draw();
private:
int m_id;
};
vector
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@y..., "¹Ú±â¼ö"
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@e... wfms123@h...
participants (4)
-
a_schweitzer
-
Jeremy Siek
-
박기수
-
�ڱ��