Using C++ Boost's Graph Library -



Using C++ Boost's Graph Library -

i confused how create graph using boost library, have looked @ illustration code , there no comments explaining does.

how create graph, , add together vertices , edges go?

here's simple example, using adjacency list , executing topological sort:

#include <iostream> #include <deque> #include <iterator> #include "boost/graph/adjacency_list.hpp" #include "boost/graph/topological_sort.hpp" int main() { // create n adjacency list, add together vertices. boost::adjacency_list<> g(num tasks); boost::add_vertex(0, g); boost::add_vertex(1, g); boost::add_vertex(2, g); boost::add_vertex(3, g); boost::add_vertex(4, g); boost::add_vertex(5, g); boost::add_vertex(6, g); // add together edges between vertices. boost::add_edge(0, 3, g); boost::add_edge(1, 3, g); boost::add_edge(1, 4, g); boost::add_edge(2, 1, g); boost::add_edge(3, 5, g); boost::add_edge(4, 6, g); boost::add_edge(5, 6, g); // perform topological sort. std::deque<int> topo_order; boost::topological_sort(g, std::front_inserter(topo_order)); // print results. for(std::deque<int>::const_iterator = topo_order.begin(); != topo_order.end(); ++i) { cout << tasks[v] << endl; } homecoming 0; }

i agree boost::graph documentation can intimidating. suggest have @ link below:

http://www.boost.org/doc/libs/1_48_0/libs/graph/doc/table_of_contents.html

i can't recall if contents of printed book same, suspect it's bit easier on eyes. learnt utilize boost:graph book. learning curve can sense pretty steep though. book refer , reviews can found here:

http://www.amazon.com/boost-graph-library-reference-manual/dp/0201729148/ref=sr_1_1?ie=utf8&qid=1326242972&sr=8-1

c++ boost

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -