2016-01-15 137 views
1

檸檬的世界你好(hello_lemon.cc,see here)我已經複製下面的代碼:檸檬圖形遍歷邊緣

#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。

回答

1

事實證明hello_lemon.cc不正確!函數源(邊緣)和目標(邊緣)僅針對有向圖形並因此定義弧。對於無向圖,如示例中所示,您需要使用u(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)) << ")";