test/heap_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 09 Jul 2008 07:57:53 +0200
changeset 198 e80e08222fdf
parent 100 4f754b4cf82b
child 203 215bfc30b14f
permissions -rw-r--r--
Merge
alpar@100
     1
/* -*- C++ -*-
alpar@100
     2
 *
alpar@100
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@100
     4
 *
alpar@100
     5
 * Copyright (C) 2003-2008
alpar@100
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@100
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@100
     8
 *
alpar@100
     9
 * Permission to use, modify and distribute this software is granted
alpar@100
    10
 * provided that this copyright notice appears in all copies. For
alpar@100
    11
 * precise terms see the accompanying LICENSE file.
alpar@100
    12
 *
alpar@100
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@100
    14
 * express or implied, and with no claim as to its suitability for any
alpar@100
    15
 * purpose.
alpar@100
    16
 *
alpar@100
    17
 */
alpar@100
    18
alpar@100
    19
#include <iostream>
alpar@100
    20
#include <fstream>
alpar@100
    21
#include <string>
alpar@100
    22
#include <vector>
alpar@100
    23
alpar@100
    24
#include <lemon/concept_check.h>
alpar@100
    25
#include <lemon/concepts/heap.h>
alpar@100
    26
alpar@100
    27
#include <lemon/list_graph.h>
alpar@100
    28
alpar@100
    29
#include <lemon/digraph_reader.h>
alpar@100
    30
alpar@100
    31
#include <lemon/bin_heap.h>
alpar@100
    32
#include <lemon/fib_heap.h>
alpar@100
    33
#include <lemon/radix_heap.h>
alpar@100
    34
#include <lemon/bucket_heap.h>
alpar@100
    35
alpar@100
    36
#include "test_tools.h"
alpar@100
    37
alpar@100
    38
#include "heap_test.h"
alpar@100
    39
alpar@100
    40
#include <lemon/time_measure.h>
alpar@100
    41
alpar@100
    42
using namespace lemon;
alpar@100
    43
using namespace lemon::concepts;
alpar@100
    44
alpar@100
    45
int main() {
alpar@100
    46
alpar@100
    47
  typedef int Item;
alpar@100
    48
  typedef int Prio;
alpar@100
    49
  typedef IntIntMap ItemIntMap;
alpar@100
    50
alpar@100
    51
  typedef ListDigraph Digraph;
alpar@100
    52
alpar@100
    53
  typedef Digraph::Arc Arc;
alpar@100
    54
  typedef Digraph::Node Node;
alpar@100
    55
  typedef Digraph::ArcIt ArcIt;
alpar@100
    56
  typedef Digraph::NodeIt NodeIt;
alpar@100
    57
  typedef Digraph::ArcMap<int> LengthMap;
alpar@100
    58
alpar@100
    59
  Digraph digraph;
alpar@100
    60
  LengthMap length(digraph);
alpar@100
    61
  Node start;
alpar@100
    62
alpar@100
    63
  /// \todo create own test digraph
alpar@100
    64
alpar@100
    65
  std::string f_name;
alpar@100
    66
  if( getenv("srcdir") )
alpar@100
    67
    f_name = std::string(getenv("srcdir"));
alpar@100
    68
  else f_name = ".";
alpar@100
    69
  f_name += "/test/dijkstra_test.lgf";
alpar@100
    70
  
alpar@100
    71
  std::ifstream input(f_name.c_str());
alpar@100
    72
  check(input, "Input file '" << f_name << "' not found.");
alpar@100
    73
  DigraphReader<Digraph>(input, digraph).
alpar@100
    74
    readArcMap("capacity", length).
alpar@100
    75
    readNode("source", start).
alpar@100
    76
    run();  
alpar@100
    77
 
alpar@100
    78
  {
kpeter@171
    79
    std::cout << "Checking Bin Heap" << std::endl;
alpar@100
    80
alpar@100
    81
    typedef BinHeap<Prio, ItemIntMap> IntHeap;
alpar@100
    82
    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
alpar@100
    83
    heapSortTest<IntHeap>(100);
alpar@100
    84
    heapIncreaseTest<IntHeap>(100);
alpar@100
    85
    
alpar@100
    86
    typedef FibHeap<Prio, Digraph::NodeMap<int> > NodeHeap;
alpar@100
    87
    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
alpar@100
    88
    Timer timer;
alpar@100
    89
    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
alpar@100
    90
    std::cout << timer << std::endl;
alpar@100
    91
  }
alpar@100
    92
  {
kpeter@171
    93
    std::cout << "Checking Fib Heap" << std::endl;
alpar@100
    94
alpar@100
    95
    typedef FibHeap<Prio, ItemIntMap> IntHeap;
alpar@100
    96
    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
alpar@100
    97
    heapSortTest<IntHeap>(100);
alpar@100
    98
    heapIncreaseTest<IntHeap>(100);
alpar@100
    99
alpar@100
   100
    typedef FibHeap<Prio, Digraph::NodeMap<int> > NodeHeap;
alpar@100
   101
    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
alpar@100
   102
    Timer timer;
alpar@100
   103
    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
alpar@100
   104
    std::cout << timer << std::endl;
alpar@100
   105
  }
alpar@100
   106
  {
kpeter@171
   107
    std::cout << "Checking Radix Heap" << std::endl;
alpar@100
   108
alpar@100
   109
    typedef RadixHeap<ItemIntMap> IntHeap;
alpar@100
   110
    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
alpar@100
   111
    heapSortTest<IntHeap>(100);
alpar@100
   112
    heapIncreaseTest<IntHeap>(100);
alpar@100
   113
alpar@100
   114
    typedef RadixHeap<Digraph::NodeMap<int> > NodeHeap;
alpar@100
   115
    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
alpar@100
   116
    Timer timer;
alpar@100
   117
    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
alpar@100
   118
    std::cout << timer << std::endl;
alpar@100
   119
  }
alpar@100
   120
alpar@100
   121
  {
kpeter@171
   122
    std::cout << "Checking Bucket Heap" << std::endl;
alpar@100
   123
alpar@100
   124
    typedef BucketHeap<ItemIntMap> IntHeap;
alpar@100
   125
    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
alpar@100
   126
    heapSortTest<IntHeap>(100);
alpar@100
   127
    heapIncreaseTest<IntHeap>(100);
alpar@100
   128
alpar@100
   129
    typedef BucketHeap<Digraph::NodeMap<int> > NodeHeap;
alpar@100
   130
    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
alpar@100
   131
    Timer timer;
alpar@100
   132
    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
alpar@100
   133
    std::cout << timer << std::endl;
alpar@100
   134
  }
alpar@100
   135
alpar@100
   136
  return 0;
alpar@100
   137
}