|
Boost Users : |
From: Line Blander Reinhardt (lbr_at_[hidden])
Date: 2008-07-08 13:18:35
Hi Eric
I am not really clear what you need. I am not an expert rather a newbie but I have used boost to make graphs
Here are some sample code for making a graph
make a graph.h file including (or make it all in one file what you prefer):
#include <vector>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/tuple/tuple.hpp>
#include "properties.h"
some of these might not be needed you should experiment with that (better to give you too many than too few). Proterties you can write at the top or include as a file.
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperties, EdgeProperties, GraphProperties> Graph;
typedef boost::graph_traits<Graph> DirectedTraits;
typedef DirectedTraits::vertex_descriptor DirectedVertex;
typedef DirectedTraits::edge_descriptor DirectedEdge;
typedef DirectedTraits::vertex_iterator VertexIterator;
typedef DirectedTraits::edge_iterator DirectedEdgeIterator;
Then you have defined a graph (first line) and vertex and edge descriptors and iterators (used when you load your graph into it)
DirectedS makes a directed graph.
you can make the properties in a properties.h file which you can include in the graph.h file
Example of properties (if using string remember to include the string library):
enum vertex_x_t{vertex_x};
enum vertex_y_t{vertex_y};
template <> struct property_kind<shipping_graph::vertex_x_t>{
typedef vertex_property_tag type;
};
template <> struct property_kind<shipping_graph::vertex_y_t>{
typedef vertex_property_tag type;
};
// Vertex properties
typedef boost::property<vertex_x_t, int,
boost::property<vertex_y_t, int,
boost::property<boost::vertex_name_t, std::string> > > VertexProperties;
You can do the same for edgeproperties and graphproperties
To load your graph into the graph do:
Graph _graph;
using namespace boost;
UnDirectedVertex v;
UnDirectedEdge e;
for (int i=0; i< <number of vertices>; i++) {
v= add_vertex(graph);
put(vertex_name, graph, v, boost::lexical_cast<std::string>(i));
put(vertex_x, graph, v, <your x coordinate>);
put(vertex_y, graph, v, <your y coordinate>);
}
for each of your edges from i to j write:
tie(e,inserted)= add_edge(i,j, graph);
put(edge_name, graph, e, edgeName(i, j));
To print the graph you can use the iterators to go through the vertex list and edge list.
I hope this explanation will help you make a boost graph.
Best
Line
________________________________
Fra: boost-users-bounces_at_[hidden] på vegne af Eric B
Sendt: ma 07-07-2008 23:58
Til: boost-users_at_[hidden]
Emne: [Boost-users] BGL Newbie
Hi
this message may have been sent twice as i got an error on my previous
post, if so I apologize
I'd like to build a boost graph from my own graph representation which
is made of:
std::vector<tNode*> => vertices
std::set<std::pair<tNode*,tNode*> > => edges (oriented)
tNode is a custom struct which contains various data and 2 integer
attribtues for coordinates x,y
I need to compute XY for each node in order to display them
I have done that with another lib but as BGL seems more recent I d like
to evaluate it.
I'm not a boost expert neither a template guru => therefore I have some
problems (even after having read lot of examples).
I'd like to have an example to understand how BGL works.
1) how to build a boost representation of my own graph (where boost
nodes ID would be integer cast of tNode* so that I can feed back my own
nodes with XY)
2) how to run a layout algorithm on the boost representation (kawai or
any other else).
Than you
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
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