# HG changeset patch # User Alpar Juttner # Date 1345817431 -7200 # Node ID 20ae244b4779dfb7d1ab934226710d16b4d205de # Parent 78434a448b5ea0fcf4fb89ef5647afeb847cd2c7# Parent 157427808b40dfd2f0656084be888e9b481d25f2 Merge bugfix #447 diff -r 78434a448b5e -r 20ae244b4779 lemon/core.h --- a/lemon/core.h Thu Dec 22 20:55:43 2011 +0100 +++ b/lemon/core.h Fri Aug 24 16:10:31 2012 +0200 @@ -1868,15 +1868,26 @@ ///this operator. If you change the outgoing arcs of ///a single node \c n, then \ref refresh(Node) "refresh(n)" is enough. /// -#ifdef DOXYGEN - Arc operator()(Node s, Node t, Arc prev=INVALID) const {} -#else - using ArcLookUp::operator() ; - Arc operator()(Node s, Node t, Arc prev) const + Arc operator()(Node s, Node t, Arc prev=INVALID) const { - return prev==INVALID?(*this)(s,t):_next[prev]; + if(prev==INVALID) + { + Arc f=INVALID; + Arc e; + for(e=_head[s]; + e!=INVALID&&_g.target(e)!=t; + e = t < _g.target(e)?_left[e]:_right[e]) ; + while(e!=INVALID) + if(_g.target(e)==t) + { + f = e; + e = _left[e]; + } + else e = _right[e]; + return f; + } + else return _next[prev]; } -#endif }; diff -r 78434a448b5e -r 20ae244b4779 test/CMakeLists.txt --- a/test/CMakeLists.txt Thu Dec 22 20:55:43 2011 +0100 +++ b/test/CMakeLists.txt Fri Aug 24 16:10:31 2012 +0200 @@ -13,6 +13,7 @@ SET(TESTS adaptors_test + arc_look_up_test bellman_ford_test bfs_test circulation_test diff -r 78434a448b5e -r 20ae244b4779 test/arc_look_up_test.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/arc_look_up_test.cc Fri Aug 24 16:10:31 2012 +0200 @@ -0,0 +1,85 @@ +/* -*- mode: C++; indent-tabs-mode: nil; -*- + * + * This file is a part of LEMON, a generic C++ optimization library. + * + * Copyright (C) 2003-2009 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#include +#include "lemon/list_graph.h" +#include "lemon/lgf_reader.h" + +#include "test_tools.h" + +using namespace lemon; + +const int lgfn = 4; +const std::string lgf = + "@nodes\n" +"label\n" +"0\n" +"1\n" +"2\n" +"3\n" +"4\n" +"5\n" +"6\n" +"@arcs\n" +"label\n" +"5 6 0\n" +"5 4 1\n" +"4 6 2\n" +"3 4 3\n" +"3 4 4\n" +"3 2 5\n" +"3 5 6\n" +"3 5 7\n" +"3 5 8\n" +"3 5 9\n" +"2 4 10\n" +"2 4 11\n" +"2 4 12\n" +"2 4 13\n" +"1 2 14\n" +"1 2 15\n" +"1 0 16\n" +"1 3 17\n" +"1 3 18\n" +"1 3 19\n" +"1 3 20\n" +"0 2 21\n" +"0 2 22\n" +"0 2 23\n" +"0 2 24\n"; + + +int main() { + ListDigraph graph; + std::istringstream lgfs(lgf); + DigraphReader(graph, lgfs).run(); + + AllArcLookUp lookup(graph); + + int numArcs = countArcs(graph); + + int arcCnt = 0; + for(ListDigraph::NodeIt n1(graph); n1 != INVALID; ++n1) + for(ListDigraph::NodeIt n2(graph); n2 != INVALID; ++n2) + for(ListDigraph::Arc a = lookup(n1, n2); a != INVALID; + a = lookup(n1, n2, a)) + ++arcCnt; + check(arcCnt==numArcs, "Wrong total number of arcs"); + + return 0; +}