【发布时间】:2012-09-18 14:35:43
【问题描述】:
我想在我的图中添加随机边,如下:
#include <iostream>
#include <utility> // for std::pair
#include <algorithm>
#include <boost/graph/adjacency_list.hpp>
#include "boost/graph/topological_sort.hpp"
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/graphviz.hpp>
int main()
{
using namespace std;
using namespace boost;
typedef adjacency_list< listS, vecS, undirectedS > undigraph;
int const N = read_int_from_user("Number of vertices: ");
undigraph g(N);
// add some edges, // #1
for (int i = 0; i != N; ++i)
{
for (int j = 0; j != N; ++j)
{
add_edge(i, j, g);
}
}
write_graphviz(cout, g);
}
#1 之后的行就是这样做的。
但是正如您所看到的,每个顶点存在 8 条边,但我希望最多只有 4 条,并且希望以随机方式连接所有顶点,最重要的是,每个顶点只能有 4 个化合价顶点。我怎样才能做到这一点?
【问题讨论】:
-
8和4的数字从何而来?! -
我想说的是,您似乎对任何细节都非常松懈......这不是“BOOST”而是“Boost”,并且它不是“图形库”,而是 graph 库。这是一个小问题,但你显然在这个项目上苦苦挣扎,我想提醒你,如果你不努力把小细节做好,你会发现把所有东西放在一起是一个巨大的挑战。
-
@KerrekSB 是的,我确实在这个项目上苦苦挣扎,而且我的截止日期非常接近。我肯定会更多地提高我的基本技能,并会考虑你的话。非常感谢您的建议。
-
您找到解决方案了吗?如果下面的答案是您想要的答案,请接受;)
标签: c++ boost graph boost-graph