src/work/marci/top_sort_test.cc
author alpar
Mon, 28 Feb 2005 13:03:36 +0000
changeset 1180 f772c360b466
parent 762 511200bdb71f
permissions -rw-r--r--
Better color to bw conversion
marci@549
     1
// -*- c++ -*-
marci@549
     2
#include <iostream>
marci@549
     3
#include <fstream>
marci@549
     4
#include <list>
marci@549
     5
alpar@921
     6
#include <lemon/dimacs.h>
marci@549
     7
#include <bfs_dfs_misc.h>
marci@642
     8
#include <sage_graph.h>
alpar@921
     9
#include <lemon/graph_wrapper.h>
alpar@921
    10
#include <lemon/maps.h>
marci@762
    11
#include <for_each_macros.h>
marci@549
    12
alpar@921
    13
using namespace lemon;
marci@549
    14
marci@609
    15
using std::cout;
marci@609
    16
using std::endl;
marci@609
    17
marci@549
    18
int main() {
marci@642
    19
  typedef SageGraph Graph;
marci@549
    20
  Graph g;
marci@552
    21
  readDimacs(std::cin, g); 
marci@609
    22
 
marci@552
    23
  {
marci@552
    24
    std::list<Graph::Node> l;
marci@609
    25
    //NullMap<Graph::Node, Graph::Edge> pred;
marci@609
    26
    Graph::NodeMap<Graph::Edge> pred(g, INVALID);
marci@577
    27
    topSort(g, l, pred);
marci@609
    28
    cout << "Leaving order of dfs which is pretopological..." << endl;
marci@552
    29
    for(std::list<Graph::Node>::const_iterator i=l.begin(); i!=l.end(); ++i) {
marci@609
    30
      cout << *i << " ";
marci@552
    31
    }
marci@609
    32
    cout << endl;
marci@609
    33
    
marci@609
    34
    FOR_EACH_LOC(Graph::NodeIt, n, g) {
marci@609
    35
      cout << "pred of node " << n << " is " << pred[n] << endl;
marci@609
    36
    }
marci@549
    37
  }
marci@552
    38
  
marci@552
    39
  {
marci@552
    40
    typedef RevGraphWrapper<Graph> GW;
marci@552
    41
    GW gw(g);
marci@552
    42
    std::list<GW::Node> l;
marci@609
    43
    //NullMap<GW::Node, GW::Edge> pred;
marci@609
    44
    GW::NodeMap<Graph::Edge> pred(gw, INVALID);
marci@577
    45
    topSort(gw, l, pred);
marci@609
    46
    cout << "Same in the reversed oriented graph..." << endl;
marci@552
    47
    for(std::list<GW::Node>::const_iterator i=l.begin(); i!=l.end(); ++i) {
marci@609
    48
      cout << *i << " ";
marci@552
    49
    }
marci@609
    50
    cout << endl;
marci@609
    51
marci@609
    52
    FOR_EACH_LOC(GW::NodeIt, n, gw) {
marci@609
    53
      cout << "pred of node " << n << " is " << pred[n] << endl;
marci@609
    54
    }
marci@552
    55
  }
marci@549
    56
marci@549
    57
  return 0;
marci@549
    58
}