繁体   English   中英

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

[英]C++ KOALA graph library - understanding syntax to access a data structure

我正在使用C ++图形库KOALA计算图形的最小割线

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

我的问题与这条线有关:

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

这是函数自变量文档

它说它返回最小切割所经过的边缘。 它立即使用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 ); }

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的自定义实现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM