# HG changeset patch
# User marci
# Date 1083856248 0
# Node ID 5531429143bc9a5f98a86686eb84bc77f411808a
# Parent  61898ac9e9dc4092904597118b2c804defd902c7


diff -r 61898ac9e9dc -r 5531429143bc src/hugo/dimacs.h
--- a/src/hugo/dimacs.h	Thu May 06 14:25:21 2004 +0000
+++ b/src/hugo/dimacs.h	Thu May 06 15:10:48 2004 +0000
@@ -77,7 +77,6 @@
     typename Graph::Node u;
     NullMap<typename Graph::Edge, int> n;
     readDimacs(is, g, n, u, u, n);
-    std::cout<<"igen en.";
   }
 
   /// sg problem
diff -r 61898ac9e9dc -r 5531429143bc src/work/marci/bfs_dfs_misc.h
--- a/src/work/marci/bfs_dfs_misc.h	Thu May 06 14:25:21 2004 +0000
+++ b/src/work/marci/bfs_dfs_misc.h	Thu May 06 15:10:48 2004 +0000
@@ -19,27 +19,29 @@
     FOR_EACH_LOC(typename Graph::NodeIt, n, g) {
       if (!reached[n]) {
 	bfs.pushAndSetReached(n);
-	bool_map.set(n, false) {
-	  while (!bfs.finished()) {
-	    if (bfs.isBNodeNewlyReached()) {
-	      bool_map.set(bfs.bNode())=!bfs.aNode();
-	    } else {
-	      if (bool_map[bfs.bNode()]==bool_map[bfs.aNode()]) {
-		return false;
-	      }
+	bool_map.set(n, false);
+	while (!bfs.finished()) {
+	  if (bfs.isBNodeNewlyReached()) {
+	    bool_map.set(bfs.bNode())=!bfs.aNode();
+	  } else {
+	    if (bool_map[bfs.bNode()]==bool_map[bfs.aNode()]) {
+	      return false;
 	    }
-	    ++bfs;
 	  }
+	  ++bfs;
 	}
       }
     }
+    
     return true;
   }
 
   /// experimental topsort, 
   /// I think the final version will work as an iterator
+  /// if the graph is not a acyclic, the na pre-topological order is obtained 
+  /// (see Schrijver's book)
   template<typename Graph> 
-  void topSort(Graph& g, std::list<typename Graph::Node>& l) {
+  void topSort(const Graph& g, std::list<typename Graph::Node>& l) {
     l.clear();
     typedef typename Graph::template NodeMap<bool> ReachedMap;
     ReachedMap reached(g/*, false*/);
diff -r 61898ac9e9dc -r 5531429143bc src/work/marci/makefile
--- a/src/work/marci/makefile	Thu May 06 14:25:21 2004 +0000
+++ b/src/work/marci/makefile	Thu May 06 15:10:48 2004 +0000
@@ -4,7 +4,7 @@
 INCLUDEDIRS ?= -I../.. -I../../hugo -I.. -I../{marci,jacint,alpar,klao,akos,athos} -I$(BOOSTROOT)
 
 LEDABINARIES = leda_graph_demo leda_bfs_dfs max_bipartite_matching_demo
-BINARIES = max_flow_demo iterator_bfs_demo macro_test lg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_try bipartite_matching_try_2 bipartite_matching_try_3
+BINARIES = max_flow_demo iterator_bfs_demo macro_test lg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_try bipartite_matching_try_2 bipartite_matching_try_3 top_sort_test
 #gw_vs_not preflow_demo_boost edmonds_karp_demo_boost preflow_demo_jacint preflow_demo_athos edmonds_karp_demo_alpar preflow_demo_leda
 
 include ../makefile
diff -r 61898ac9e9dc -r 5531429143bc src/work/marci/top_sort.dim
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/work/marci/top_sort.dim	Thu May 06 15:10:48 2004 +0000
@@ -0,0 +1,5 @@
+p mat 5 4
+a 1 3
+a 2 3
+a 3 5
+a 3 4
diff -r 61898ac9e9dc -r 5531429143bc src/work/marci/top_sort_test.cc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/work/marci/top_sort_test.cc	Thu May 06 15:10:48 2004 +0000
@@ -0,0 +1,25 @@
+// -*- c++ -*-
+#include <iostream>
+#include <fstream>
+#include <list>
+
+#include <hugo/dimacs.h>
+#include <bfs_dfs_misc.h>
+#include <list_graph.h>
+
+using namespace hugo;
+
+int main() {
+  typedef ListGraph Graph;
+  Graph g;
+  readDimacs(std::cin, g);
+  std::list<Graph::Node> l;
+  topSort(g, l);
+  std::cout << "Leaving order of dfs which is pretopological..." << std::endl;
+  for(std::list<Graph::Node>::const_iterator i=l.begin(); i!=l.end(); ++i) {
+    std::cout << *i << " ";
+  }
+  std::cout << std::endl;
+
+  return 0;
+}