Bugfix in AllArcLookUp<> (#447)
authorAlpar Juttner <alpar@cs.elte.hu>
Fri, 24 Aug 2012 15:37:23 +0200
changeset 993157427808b40
parent 990 7440937d154b
child 994 20ae244b4779
child 997 761fe0846f49
Bugfix in AllArcLookUp<> (#447)
lemon/core.h
test/CMakeLists.txt
test/arc_look_up_test.cc
     1.1 --- a/lemon/core.h	Fri Jun 22 16:25:56 2012 +0200
     1.2 +++ b/lemon/core.h	Fri Aug 24 15:37:23 2012 +0200
     1.3 @@ -1848,15 +1848,26 @@
     1.4      ///this operator. If you change the outgoing arcs of
     1.5      ///a single node \c n, then \ref refresh(Node) "refresh(n)" is enough.
     1.6      ///
     1.7 -#ifdef DOXYGEN
     1.8 -    Arc operator()(Node s, Node t, Arc prev=INVALID) const {}
     1.9 -#else
    1.10 -    using ArcLookUp<GR>::operator() ;
    1.11 -    Arc operator()(Node s, Node t, Arc prev) const
    1.12 +    Arc operator()(Node s, Node t, Arc prev=INVALID) const
    1.13      {
    1.14 -      return prev==INVALID?(*this)(s,t):_next[prev];
    1.15 +      if(prev==INVALID)
    1.16 +        {
    1.17 +          Arc f=INVALID;
    1.18 +          Arc e;
    1.19 +          for(e=_head[s];
    1.20 +              e!=INVALID&&_g.target(e)!=t;
    1.21 +              e = t < _g.target(e)?_left[e]:_right[e]) ;
    1.22 +          while(e!=INVALID)
    1.23 +            if(_g.target(e)==t)
    1.24 +              {
    1.25 +                f = e;
    1.26 +                e = _left[e];
    1.27 +              }
    1.28 +            else e = _right[e];
    1.29 +          return f;
    1.30 +        }
    1.31 +      else return _next[prev];
    1.32      }
    1.33 -#endif
    1.34  
    1.35    };
    1.36  
     2.1 --- a/test/CMakeLists.txt	Fri Jun 22 16:25:56 2012 +0200
     2.2 +++ b/test/CMakeLists.txt	Fri Aug 24 15:37:23 2012 +0200
     2.3 @@ -13,6 +13,7 @@
     2.4  
     2.5  SET(TESTS
     2.6    adaptors_test
     2.7 +  arc_look_up_test
     2.8    bfs_test
     2.9    circulation_test
    2.10    connectivity_test
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/arc_look_up_test.cc	Fri Aug 24 15:37:23 2012 +0200
     3.3 @@ -0,0 +1,85 @@
     3.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
     3.5 + *
     3.6 + * This file is a part of LEMON, a generic C++ optimization library.
     3.7 + *
     3.8 + * Copyright (C) 2003-2009
     3.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    3.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    3.11 + *
    3.12 + * Permission to use, modify and distribute this software is granted
    3.13 + * provided that this copyright notice appears in all copies. For
    3.14 + * precise terms see the accompanying LICENSE file.
    3.15 + *
    3.16 + * This software is provided "AS IS" with no warranty of any kind,
    3.17 + * express or implied, and with no claim as to its suitability for any
    3.18 + * purpose.
    3.19 + *
    3.20 + */
    3.21 +
    3.22 +#include <iostream>
    3.23 +#include "lemon/list_graph.h"
    3.24 +#include "lemon/lgf_reader.h"
    3.25 +
    3.26 +#include "test_tools.h"
    3.27 +
    3.28 +using namespace lemon;
    3.29 +
    3.30 +const int lgfn = 4;
    3.31 +const std::string lgf =
    3.32 +  "@nodes\n"
    3.33 +"label\n"
    3.34 +"0\n"
    3.35 +"1\n"
    3.36 +"2\n"
    3.37 +"3\n"
    3.38 +"4\n"
    3.39 +"5\n"
    3.40 +"6\n"
    3.41 +"@arcs\n"
    3.42 +"label\n"
    3.43 +"5 6 0\n"
    3.44 +"5 4 1\n"
    3.45 +"4 6 2\n"
    3.46 +"3 4 3\n"
    3.47 +"3 4 4\n"
    3.48 +"3 2 5\n"
    3.49 +"3 5 6\n"
    3.50 +"3 5 7\n"
    3.51 +"3 5 8\n"
    3.52 +"3 5 9\n"
    3.53 +"2 4 10\n"
    3.54 +"2 4 11\n"
    3.55 +"2 4 12\n"
    3.56 +"2 4 13\n"
    3.57 +"1 2 14\n"
    3.58 +"1 2 15\n"
    3.59 +"1 0 16\n"
    3.60 +"1 3 17\n"
    3.61 +"1 3 18\n"
    3.62 +"1 3 19\n"
    3.63 +"1 3 20\n"
    3.64 +"0 2 21\n"
    3.65 +"0 2 22\n"
    3.66 +"0 2 23\n"
    3.67 +"0 2 24\n";
    3.68 +
    3.69 +
    3.70 +int main() {
    3.71 +  ListDigraph graph;
    3.72 +  std::istringstream lgfs(lgf);
    3.73 +  DigraphReader<ListDigraph>(graph, lgfs).run();
    3.74 +  
    3.75 +  AllArcLookUp<ListDigraph> lookup(graph);
    3.76 +	
    3.77 +  int numArcs = countArcs(graph);
    3.78 +	
    3.79 +  int arcCnt = 0;
    3.80 +  for(ListDigraph::NodeIt n1(graph); n1 != INVALID; ++n1)
    3.81 +    for(ListDigraph::NodeIt n2(graph); n2 != INVALID; ++n2)
    3.82 +      for(ListDigraph::Arc a = lookup(n1, n2); a != INVALID;
    3.83 +	  a = lookup(n1, n2, a))
    3.84 +	++arcCnt;
    3.85 +  check(arcCnt==numArcs, "Wrong total number of arcs");
    3.86 +
    3.87 +  return 0;
    3.88 +}