我试图了解如何构建图并使用boost库运行stoer_wagner_min_cut
算法。
到目前为止,我已经使用adjacency_matrix
容器构建了图形。
问题是使stoer_wagner_min_cut
有效。我红this
文档,我遇到两件事:
WeightMap weights
作为输入。 第一部分是什么意思?
adjacency_matrix
是某种类型的“顶点列表图和关联图”吗?有一个例子吗?同样,图中的所有边的权重均为1。我不知道如何组装该
WeightMap weights
。并找不到任何示例。编辑:
这就是我可以管理的
#include <boost/graph/adjacency_matrix.hpp>
#include <boost/graph/stoer_wagner_min_cut.hpp>
#include <boost/property_map/property_map.h>
using namespace boost;
typedef adjacency_matrix<undirectedS> UGraph;
void main()
{
static_property_map<UGraph, int>; // im not sure about UGraph
G = buildGraph(); // this function works fine
parity_map = stoer_wagner_min_cut(G, ..?..);
}
我应该如何定义此静态属性映射以返回int值1?我对此有点挣扎。
我还看到
stoer_wagner_min_cut
的返回值为parity_map
(ParityMap必须是可写属性映射的模型,其值类型应该是bool类型)我在建筑物和使用这些 map 方面有些挣扎,我很乐意为此提供一些指导和示例。
谢谢。
最佳答案
what does the first section means? is adjacency_matrix some type of "Vertex List Graph and Incidence Graph"? is there an example for that?
这意味着图类型必须为命名的概念建模。这里记录了这些概念:
在这种情况下,提供静态属性图将是最简单的:
Live On Coliru
#include <boost/functional/hash.hpp>
#include <boost/graph/adjacency_matrix.hpp>
#include <boost/graph/stoer_wagner_min_cut.hpp>
#include <boost/property_map/property_map.hpp>
using namespace boost;
typedef adjacency_matrix<undirectedS> UGraph;
UGraph buildGraph() {
UGraph g(10);
// todo
return g;
}
#include <iostream>
int main() {
UGraph g = buildGraph(); // this function works fine
int i = stoer_wagner_min_cut(g, boost::make_static_property_map<UGraph::edge_descriptor>(1));
std::cout << "i: " << i << "\n";
}