gpt4 book ai didi

C++ KOALA 图形库 - 理解访问数据结构的语法

转载 作者:行者123 更新时间:2023-11-30 03:17:44 25 4
gpt4 key购买 nike

我正在使用 C++ graph library KOALA计算图的最小割。

这是我正在使用的示例 - example .它只是创建一个边上有容量的图并计算最小割。

我的问题与这一行有关:

Flow::minEdgeCut(g, cap, s, t, Flow::outCut(blackHole, edgeIter()));

这是 document for the arguments of the function .

它说它返回最小切割经过的边。它立即使用 std::cout 打印边缘,但我需要稍后在程序中访问它们。我的问题是如何访问存储它们的数据结构,例如在稍后阶段打印它们。

该示例将 stuct edgeIter 作为参数传递给 outCutedgeIter 提供了 3 个重载运算符。我需要向这个结构添加额外的成员吗?

struct edgeIter {
void operator=(MyGraph::PEdge e) { cout << e->info; }
void operator++() { }
edgeIter &operator*() { return *this; }
};

这里也是 outcut 方法的定义。

/** \brief Auxiliary class to represent the edge cut. (output structure) */
template< class VIter, class EIter > struct OutCut
{
VIter vertIter;/**<\brief Insert iterator to the container with vertexes (accessible from starting vertex after the cut)*/
EIter edgeIter;/**<\brief Insert iterator to the container with edges of the cat.*/
/**\brief Constructor*/
OutCut( VIter av, EIter ei ): vertIter( av ), edgeIter( ei ) { }
};

/**\brief Generating function for the OutCut object.
*
* \tparam VIter the type of insert iterator to container with vertices.
* \tparam EIter the type of insert iterator to container with edges.
* \param av the insert iterator to container with vertices.
* \tparam ei the insert iterator to container with edges.
*
* [See example](examples/flow/example_Flow.html). */
template< class VIter, class EIter > static OutCut< VIter,EIter > outCut( VIter av, EIter ei )
{ return OutCut< VIter,EIter >( av,ei ); }

最佳答案

edgeIterOutputIterator 的实例.您可以调整代码以使用 std::back_inserter并将所有结果收集到 vector edges 中,如下所示:

std::vector<MyGraph::PEdge> edges;
Flow::minEdgeCut(g, cap, s, t, Flow::outCut(blackHole, std::back_inserter(edges)));

还有一个front_inserter,或者你可以写一个像edgeIter这样的自定义实现。

关于C++ KOALA 图形库 - 理解访问数据结构的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55237766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com