我正在使用C 图库Koala来计算图的最小切割。
这是我正在使用的示例 - 示例。它只是创建一个图形,并在边缘上具有能力并计算最小切割。
我的问题与这一行有关:
Flow::minEdgeCut(g, cap, s, t, Flow::outCut(blackHole, edgeIter()));
这是函数参数的文档。
它说它返回了最小切割经历的边缘。它立即使用std::cout
打印边缘,但我需要在程序以后访问它们。我的问题是如何访问将它们存储在其中的数据结构,例如在以后的阶段打印它们。
该示例将stuct edgeIter
作为参数传递给outCut
。edgeIter
提供3个过载操作员。我需要在此stuct中添加其他成员吗?
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 ); }
edgeIter
是 OutputIterator
的实例。您可以调整代码以使用std::back_inserter
并在矢量edges
中收集所有结果:
std::vector<MyGraph::PEdge> edges;
Flow::minEdgeCut(g, cap, s, t, Flow::outCut(blackHole, std::back_inserter(edges)));
也有一个front_inserter
,或者您可以编写诸如edgeIter
的自定义实现。