使用C ++ Boost的图形库 [英] Using C++ Boost's Graph Library

查看:598
本文介绍了使用C ++ Boost的图形库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感到困惑如何使用Boost库实际上是创建一个图,我已经看过这个例子code和没有注释解释它做什么。

I am confused about how to actually create a Graph using the boost library, I have looked at the example code and there are no comments explaining what it does.

你怎么做一个曲线图,当您去添加顶点和边?

How do you make a graph, and add vertices and edges as you go?

推荐答案

下面是一个简单的例子,使用邻接表并执行拓扑排序:

Here's a simple example, using an adjacency list and executing a topological sort:

#include <iostream>
#include <deque>
#include <iterator>

#include "boost/graph/adjacency_list.hpp"
#include "boost/graph/topological_sort.hpp"

int main()
{
    // Create a n adjacency list, add some 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 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 a topological sort.
    std::deque<int> topo_order;
    boost::topological_sort(g, std::front_inserter(topo_order));

    // Print the results.
    for(std::deque<int>::const_iterator i = topo_order.begin();
        i != topo_order.end();
        ++i)
    {
        cout << tasks[v] << endl;
    }

    return 0;
}

我同意了boost ::图文档可以恐吓。我建议你​​看看下面的链接:

I agree that the boost::graph documentation can be intimidating. I suggest you have a look at the link below:

<一个href=\"http://www.boost.org/doc/libs/1_48_0/libs/graph/doc/table_of_contents.html\">http://www.boost.org/doc/libs/1_48_0/libs/graph/doc/table_of_contents.html

我不记得,如果印刷书的内容是一样的,我怀疑这是对眼睛更容易一些。其实,我学会了使用boost:图从书。学习曲线可以感受到pretty陡峭虽然。这本书我指的是和评论可以在这里找到:

I can't recall if the contents of the printed book is the same, I suspect it's a bit easier on the eyes. I actually learnt to use boost:graph from the book. The learning curve can feel pretty steep though. The book I refer to and reviews can be found here:

<一个href=\"http://rads.stackoverflow.com/amzn/click/0201729148\">http://www.amazon.com/Boost-Graph-Library-Reference-Manual/dp/0201729148/ref=sr_1_1?ie=UTF8&qid=1326242972&sr=8-1

这篇关于使用C ++ Boost的图形库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆