# HG changeset patch # User Alpar Juttner # Date 1345816254 -7200 # Node ID 0da74b2d0beaa0303797b0bbdf18d805be6a7f8e # Parent a5810903ed28c2184c54742465439861ad5ba227# Parent 157427808b40dfd2f0656084be888e9b481d25f2 Merge bugfix #447 to branch 1.2 diff -r a5810903ed28 -r 0da74b2d0bea lemon/core.h --- a/lemon/core.h Fri Jun 22 16:38:46 2012 +0200 +++ b/lemon/core.h Fri Aug 24 15:50:54 2012 +0200 @@ -1849,15 +1849,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 a5810903ed28 -r 0da74b2d0bea test/CMakeLists.txt --- a/test/CMakeLists.txt Fri Jun 22 16:38:46 2012 +0200 +++ b/test/CMakeLists.txt Fri Aug 24 15:50:54 2012 +0200 @@ -13,6 +13,7 @@ SET(TESTS adaptors_test + arc_look_up_test bellman_ford_test bfs_test circulation_test diff -r a5810903ed28 -r 0da74b2d0bea 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 15:50:54 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; +}