src/work/marci/top_sort_test.cc
author deba
Wed, 08 Sep 2004 12:06:45 +0000 (2004-09-08)
changeset 822 88226d9fe821
parent 642 e812963087f0
child 921 818510fa3d99
permissions -rw-r--r--
The MapFactories have been removed from the code because
if we use macros then they increases only the complexity.

The pair iterators of the maps are separeted from the maps.

Some macros and comments has been changed.
marci@549
     1
// -*- c++ -*-
marci@549
     2
#include <iostream>
marci@549
     3
#include <fstream>
marci@549
     4
#include <list>
marci@549
     5
marci@549
     6
#include <hugo/dimacs.h>
marci@549
     7
#include <bfs_dfs_misc.h>
marci@642
     8
#include <sage_graph.h>
marci@557
     9
#include <hugo/graph_wrapper.h>
marci@577
    10
#include <hugo/maps.h>
marci@762
    11
#include <for_each_macros.h>
marci@549
    12
marci@549
    13
using namespace hugo;
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
}