test/heap_test.cc
author deba
Wed, 25 Jan 2006 16:44:19 +0000
changeset 1906 7fa90b66ca9e
parent 1744 51d5d41e15b1
child 1956 a055123339d5
permissions -rw-r--r--
Omitting warnings
deba@1187
     1
// -*- c++ -*-
deba@1187
     2
deba@1187
     3
#include <iostream>
deba@1187
     4
#include <fstream>
alpar@1215
     5
#include <string>
deba@1187
     6
#include <vector>
deba@1187
     7
deba@1187
     8
#include <lemon/concept_check.h>
deba@1330
     9
#include <lemon/concept/heap.h>
deba@1187
    10
deba@1206
    11
#include <lemon/smart_graph.h>
deba@1206
    12
deba@1206
    13
#include <lemon/graph_reader.h>
deba@1206
    14
deba@1187
    15
#include <lemon/bin_heap.h>
deba@1187
    16
#include <lemon/fib_heap.h>
deba@1187
    17
#include <lemon/radix_heap.h>
deba@1728
    18
#include <lemon/linear_heap.h>
deba@1187
    19
deba@1206
    20
#include "test_tools.h"
deba@1187
    21
deba@1187
    22
#include "heap_test.h"
deba@1187
    23
deba@1728
    24
#include <lemon/time_measure.h>
deba@1187
    25
deba@1187
    26
using namespace lemon;
deba@1330
    27
using namespace lemon::concept;
deba@1187
    28
deba@1187
    29
deba@1187
    30
int main() {
deba@1187
    31
deba@1187
    32
  typedef int Item;
deba@1187
    33
  typedef int Prio;
deba@1187
    34
  typedef IntIntMap ItemIntMap;
deba@1187
    35
deba@1187
    36
  typedef ListGraph Graph;
deba@1187
    37
deba@1187
    38
  typedef Graph::Edge Edge;
deba@1187
    39
  typedef Graph::Node Node;
deba@1187
    40
  typedef Graph::EdgeIt EdgeIt;
deba@1187
    41
  typedef Graph::NodeIt NodeIt;
deba@1187
    42
  typedef Graph::EdgeMap<int> LengthMap;
deba@1187
    43
deba@1187
    44
  Graph graph;
deba@1187
    45
  LengthMap length(graph);
deba@1187
    46
  Node start;
deba@1187
    47
deba@1206
    48
  /// \todo create own test graph
alpar@1215
    49
alpar@1215
    50
  std::string f_name;
alpar@1215
    51
  if( getenv("srcdir") )
alpar@1215
    52
    f_name = std::string(getenv("srcdir"));
alpar@1215
    53
  else f_name = ".";
alpar@1215
    54
  f_name += "/dijkstra_test.lgf";
alpar@1215
    55
  
alpar@1215
    56
  std::ifstream input(f_name.c_str());
alpar@1215
    57
  check(input, "Input file '" << f_name << "' not found.");
deba@1744
    58
  GraphReader<Graph>(input, graph).
deba@1845
    59
    readEdgeMap("capacity", length).
deba@1744
    60
    readNode("source", start).
deba@1744
    61
    run();  
deba@1187
    62
 
deba@1187
    63
  {
deba@1187
    64
    std::cerr << "Checking Bin Heap" << std::endl;
deba@1187
    65
deba@1187
    66
    typedef BinHeap<Item, Prio, ItemIntMap> IntHeap;
deba@1330
    67
    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
deba@1206
    68
    heapSortTest<IntHeap>(100);
deba@1206
    69
    heapIncreaseTest<IntHeap>(100);
deba@1187
    70
    
deba@1187
    71
    typedef FibHeap<Node, Prio, Graph::NodeMap<int> > NodeHeap;
deba@1330
    72
    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
deba@1728
    73
    Timer timer;
deba@1187
    74
    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
deba@1728
    75
    std::cout << timer << std::endl;
deba@1187
    76
  }
deba@1187
    77
  {
deba@1187
    78
    std::cerr << "Checking Fib Heap" << std::endl;
deba@1187
    79
deba@1187
    80
    typedef FibHeap<Item, Prio, ItemIntMap> IntHeap;
deba@1330
    81
    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
deba@1206
    82
    heapSortTest<IntHeap>(100);
deba@1206
    83
    heapIncreaseTest<IntHeap>(100);
deba@1187
    84
deba@1187
    85
    typedef FibHeap<Node, Prio, Graph::NodeMap<int> > NodeHeap;
deba@1330
    86
    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
deba@1728
    87
    Timer timer;
deba@1187
    88
    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
deba@1728
    89
    std::cout << timer << std::endl;
deba@1187
    90
  }
deba@1187
    91
  {
deba@1187
    92
    std::cerr << "Checking Radix Heap" << std::endl;
deba@1187
    93
deba@1187
    94
    typedef RadixHeap<Item, ItemIntMap> IntHeap;
deba@1330
    95
    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
deba@1206
    96
    heapSortTest<IntHeap>(100);
deba@1206
    97
    heapIncreaseTest<IntHeap>(100);
deba@1187
    98
deba@1187
    99
    typedef RadixHeap<Node, Graph::NodeMap<int> > NodeHeap;
deba@1330
   100
    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
deba@1728
   101
    Timer timer;
deba@1187
   102
    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
deba@1728
   103
    std::cout << timer << std::endl;
deba@1728
   104
  }
deba@1728
   105
deba@1728
   106
  {
deba@1728
   107
    std::cerr << "Checking Linear Heap" << std::endl;
deba@1728
   108
deba@1728
   109
    typedef LinearHeap<Item, ItemIntMap> IntHeap;
deba@1728
   110
    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
deba@1728
   111
    heapSortTest<IntHeap>(100);
deba@1728
   112
    heapIncreaseTest<IntHeap>(100);
deba@1728
   113
deba@1728
   114
    typedef LinearHeap<Node, Graph::NodeMap<int> > NodeHeap;
deba@1728
   115
    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
deba@1728
   116
    Timer timer;
deba@1728
   117
    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
deba@1728
   118
    std::cout << timer << std::endl;
deba@1187
   119
  }
deba@1187
   120
deba@1187
   121
  std::cout << __FILE__ ": All tests passed.\n";
deba@1187
   122
deba@1187
   123
  return 0;
deba@1187
   124
}