柠檬图迭代边缘



来自Lemon的hello world(hello_lemon.cc,见这里)我复制了以下代码:

#include <iostream>
#include <lemon/list_graph.h>
int main()
{
  typedef lemon::ListGraph Graph;
  typedef Graph::EdgeIt EdgeIt;
  typedef Graph::Edge Edge;
  typedef Graph::NodeIt NodeIt;
  typedef Graph::Node Node;
  typedef Graph::EdgeMap<int> LengthMap;
  using lemon::INVALID;
  Graph g;
  Node s=g.addNode();
  Node v2=g.addNode();
  Node v3=g.addNode();
  Node v4=g.addNode();
  Node v5=g.addNode();
  Node t=g.addNode();
  Edge s_v2=g.addEdge(s, v2);
  Edge s_v3=g.addEdge(s, v3);
  Edge v2_v4=g.addEdge(v2, v4);
  Edge v2_v5=g.addEdge(v2, v5);
  Edge v3_v5=g.addEdge(v3, v5);
  Edge v4_t=g.addEdge(v4, t);
  Edge v5_t=g.addEdge(v5, t);
  std::cout << "Nodes:";
  for (NodeIt i(g); i!=INVALID; ++i)
    std::cout << " " << g.id(i);
  std::cout << std::endl;
  std::cout << "Edges:";
  for (EdgeIt i(g); i!=INVALID; ++i)
    std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
}

我想做的只是遍历节点/边缘并打印它们。但是,当我尝试编译它时,我收到以下错误:

g++ -I"/opt/lemon/include" -I"/opt/lemon/lib"  -Wall -Werror -fpic -DNDEBUG -O3 test.cc
test.cc: In function ‘int main()’:
test.cc:68:41: error: no matching function for call to ‘lemon::ListGraph::source(EdgeIt&)’
test.cc:68:41: note: candidate is:
In file included from test.cc:22:0:
/opt/lemon/include/lemon/list_graph.h:878:10: note: lemon::ListGraphBase::Node lemon::ListGraphBase::source(lemon::ListGraphBase::Arc) const
/opt/lemon/include/lemon/list_graph.h:878:10: note:   no known conversion for argument 1 from ‘EdgeIt {aka lemon::GraphExtender<lemon::ListGraphBase>::EdgeIt}’ to ‘lemon::ListGraphBase::Arc’
test.cc:68:69: error: no matching function for call to ‘lemon::ListGraph::target(EdgeIt&)’
test.cc:68:69: note: candidate is:
In file included from test.cc:22:0:
/opt/lemon/include/lemon/list_graph.h:879:10: note: lemon::ListGraphBase::Node lemon::ListGraphBase::target(lemon::ListGraphBase::Arc) const
/opt/lemon/include/lemon/list_graph.h:879:10: note:   no known conversion for argument 1 from ‘EdgeIt {aka lemon::GraphExtender<lemon::ListGraphBase>::EdgeIt}’ to ‘lemon::ListGraphBase::Arc’

知道如何解决这个问题吗?我正在使用Lemon 1.3.1,这是目前的最新版本。

事实证明,hello_lemon.cc 不正确!函数 source(edge) 和 target(edge) 仅用于有向图和弧。对于无向图,如示例中所示,您需要使用 u(edge) 和 v(edge) 或 v(edge) resp.(谁想出了这个逻辑......因此,迭代集的正确代码是:

std::cout << "Edges:";
  for (EdgeIt i(g); i!=INVALID; ++i)
    std::cout << " (" << g.id(g.u(i)) << "," << g.id(g.v(i)) << ")";

最新更新