test/heap_test.cc
author alpar
Mon, 24 Oct 2005 08:11:21 +0000
changeset 1735 41e96cd91d6d
parent 1435 8e85e6bbefdf
child 1744 51d5d41e15b1
permissions -rw-r--r--
New version of XML reader/writer.
Now, there are only a single XmlIo class both for reading and writing.
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@1206
    58
  readGraph(input, graph, length, start);  
deba@1187
    59
 
deba@1187
    60
  {
deba@1187
    61
    std::cerr << "Checking Bin Heap" << std::endl;
deba@1187
    62
deba@1187
    63
    typedef BinHeap<Item, Prio, ItemIntMap> IntHeap;
deba@1330
    64
    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
deba@1206
    65
    heapSortTest<IntHeap>(100);
deba@1206
    66
    heapIncreaseTest<IntHeap>(100);
deba@1187
    67
    
deba@1187
    68
    typedef FibHeap<Node, Prio, Graph::NodeMap<int> > NodeHeap;
deba@1330
    69
    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
deba@1728
    70
    Timer timer;
deba@1187
    71
    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
deba@1728
    72
    std::cout << timer << std::endl;
deba@1187
    73
  }
deba@1187
    74
  {
deba@1187
    75
    std::cerr << "Checking Fib Heap" << std::endl;
deba@1187
    76
deba@1187
    77
    typedef FibHeap<Item, Prio, ItemIntMap> IntHeap;
deba@1330
    78
    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
deba@1206
    79
    heapSortTest<IntHeap>(100);
deba@1206
    80
    heapIncreaseTest<IntHeap>(100);
deba@1187
    81
deba@1187
    82
    typedef FibHeap<Node, Prio, Graph::NodeMap<int> > NodeHeap;
deba@1330
    83
    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
deba@1728
    84
    Timer timer;
deba@1187
    85
    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
deba@1728
    86
    std::cout << timer << std::endl;
deba@1187
    87
  }
deba@1187
    88
  {
deba@1187
    89
    std::cerr << "Checking Radix Heap" << std::endl;
deba@1187
    90
deba@1187
    91
    typedef RadixHeap<Item, ItemIntMap> IntHeap;
deba@1330
    92
    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
deba@1206
    93
    heapSortTest<IntHeap>(100);
deba@1206
    94
    heapIncreaseTest<IntHeap>(100);
deba@1187
    95
deba@1187
    96
    typedef RadixHeap<Node, Graph::NodeMap<int> > NodeHeap;
deba@1330
    97
    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
deba@1728
    98
    Timer timer;
deba@1187
    99
    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
deba@1728
   100
    std::cout << timer << std::endl;
deba@1728
   101
  }
deba@1728
   102
deba@1728
   103
  {
deba@1728
   104
    std::cerr << "Checking Linear Heap" << std::endl;
deba@1728
   105
deba@1728
   106
    typedef LinearHeap<Item, ItemIntMap> IntHeap;
deba@1728
   107
    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
deba@1728
   108
    heapSortTest<IntHeap>(100);
deba@1728
   109
    heapIncreaseTest<IntHeap>(100);
deba@1728
   110
deba@1728
   111
    typedef LinearHeap<Node, Graph::NodeMap<int> > NodeHeap;
deba@1728
   112
    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
deba@1728
   113
    Timer timer;
deba@1728
   114
    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
deba@1728
   115
    std::cout << timer << std::endl;
deba@1187
   116
  }
deba@1187
   117
deba@1187
   118
  std::cout << __FILE__ ": All tests passed.\n";
deba@1187
   119
deba@1187
   120
  return 0;
deba@1187
   121
}