【发布时间】:2019-03-19 09:39:31
【问题描述】:
我正在使用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 作为参数传递给outCut。 edgeIter 提供 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 ); }
【问题讨论】:
标签: c++ templates graph operator-overloading