[Lemon-commits] Alpar Juttner: Bugfix in AllArcLookUp<> (#447)

Lemon HG hg at lemon.cs.elte.hu
Thu Sep 6 10:49:19 CEST 2012


details:   http://lemon.cs.elte.hu/hg/lemon/rev/157427808b40
changeset: 1149:157427808b40
user:      Alpar Juttner <alpar [at] cs.elte.hu>
date:      Fri Aug 24 15:37:23 2012 +0200
description:
	Bugfix in AllArcLookUp<> (#447)

diffstat:

 lemon/core.h             |  25 ++++++++++---
 test/CMakeLists.txt      |   1 +
 test/arc_look_up_test.cc |  85 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 7 deletions(-)

diffs (138 lines):

diff --git a/lemon/core.h b/lemon/core.h
--- a/lemon/core.h
+++ b/lemon/core.h
@@ -1848,15 +1848,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<GR>::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 --git a/test/CMakeLists.txt b/test/CMakeLists.txt
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -13,6 +13,7 @@
 
 SET(TESTS
   adaptors_test
+  arc_look_up_test
   bfs_test
   circulation_test
   connectivity_test
diff --git a/test/arc_look_up_test.cc b/test/arc_look_up_test.cc
new file mode 100644
--- /dev/null
+++ b/test/arc_look_up_test.cc
@@ -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 <iostream>
+#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<ListDigraph>(graph, lgfs).run();
+  
+  AllArcLookUp<ListDigraph> 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;
+}



More information about the Lemon-commits mailing list