test/heap_test.cc
author Peter Kovacs <kpeter@inf.elte.hu>
Sun, 15 Jun 2008 22:03:33 +0200
changeset 170 91fb4372688f
child 171 02f4d5d9bfd7
permissions -rw-r--r--
Port dijkstra_test.cc from SVN -r3499
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
alpar@100
    46
int main() {
alpar@100
    47
alpar@100
    48
  typedef int Item;
alpar@100
    49
  typedef int Prio;
alpar@100
    50
  typedef IntIntMap ItemIntMap;
alpar@100
    51
alpar@100
    52
  typedef ListDigraph Digraph;
alpar@100
    53
alpar@100
    54
  typedef Digraph::Arc Arc;
alpar@100
    55
  typedef Digraph::Node Node;
alpar@100
    56
  typedef Digraph::ArcIt ArcIt;
alpar@100
    57
  typedef Digraph::NodeIt NodeIt;
alpar@100
    58
  typedef Digraph::ArcMap<int> LengthMap;
alpar@100
    59
alpar@100
    60
  Digraph digraph;
alpar@100
    61
  LengthMap length(digraph);
alpar@100
    62
  Node start;
alpar@100
    63
alpar@100
    64
  /// \todo create own test digraph
alpar@100
    65
alpar@100
    66
  std::string f_name;
alpar@100
    67
  if( getenv("srcdir") )
alpar@100
    68
    f_name = std::string(getenv("srcdir"));
alpar@100
    69
  else f_name = ".";
alpar@100
    70
  f_name += "/test/dijkstra_test.lgf";
alpar@100
    71
  
alpar@100
    72
  std::ifstream input(f_name.c_str());
alpar@100
    73
  check(input, "Input file '" << f_name << "' not found.");
alpar@100
    74
  DigraphReader<Digraph>(input, digraph).
alpar@100
    75
    readArcMap("capacity", length).
alpar@100
    76
    readNode("source", start).
alpar@100
    77
    run();  
alpar@100
    78
 
alpar@100
    79
  {
alpar@100
    80
    std::cerr << "Checking Bin Heap" << std::endl;
alpar@100
    81
alpar@100
    82
    typedef BinHeap<Prio, ItemIntMap> IntHeap;
alpar@100
    83
    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
alpar@100
    84
    heapSortTest<IntHeap>(100);
alpar@100
    85
    heapIncreaseTest<IntHeap>(100);
alpar@100
    86
    
alpar@100
    87
    typedef FibHeap<Prio, Digraph::NodeMap<int> > NodeHeap;
alpar@100
    88
    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
alpar@100
    89
    Timer timer;
alpar@100
    90
    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
alpar@100
    91
    std::cout << timer << std::endl;
alpar@100
    92
  }
alpar@100
    93
  {
alpar@100
    94
    std::cerr << "Checking Fib Heap" << std::endl;
alpar@100
    95
alpar@100
    96
    typedef FibHeap<Prio, ItemIntMap> IntHeap;
alpar@100
    97
    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
alpar@100
    98
    heapSortTest<IntHeap>(100);
alpar@100
    99
    heapIncreaseTest<IntHeap>(100);
alpar@100
   100
alpar@100
   101
    typedef FibHeap<Prio, Digraph::NodeMap<int> > NodeHeap;
alpar@100
   102
    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
alpar@100
   103
    Timer timer;
alpar@100
   104
    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
alpar@100
   105
    std::cout << timer << std::endl;
alpar@100
   106
  }
alpar@100
   107
  {
alpar@100
   108
    std::cerr << "Checking Radix Heap" << std::endl;
alpar@100
   109
alpar@100
   110
    typedef RadixHeap<ItemIntMap> IntHeap;
alpar@100
   111
    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
alpar@100
   112
    heapSortTest<IntHeap>(100);
alpar@100
   113
    heapIncreaseTest<IntHeap>(100);
alpar@100
   114
alpar@100
   115
    typedef RadixHeap<Digraph::NodeMap<int> > NodeHeap;
alpar@100
   116
    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
alpar@100
   117
    Timer timer;
alpar@100
   118
    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
alpar@100
   119
    std::cout << timer << std::endl;
alpar@100
   120
  }
alpar@100
   121
alpar@100
   122
  {
alpar@100
   123
    std::cerr << "Checking Bucket Heap" << std::endl;
alpar@100
   124
alpar@100
   125
    typedef BucketHeap<ItemIntMap> IntHeap;
alpar@100
   126
    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
alpar@100
   127
    heapSortTest<IntHeap>(100);
alpar@100
   128
    heapIncreaseTest<IntHeap>(100);
alpar@100
   129
alpar@100
   130
    typedef BucketHeap<Digraph::NodeMap<int> > NodeHeap;
alpar@100
   131
    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
alpar@100
   132
    Timer timer;
alpar@100
   133
    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
alpar@100
   134
    std::cout << timer << std::endl;
alpar@100
   135
  }
alpar@100
   136
alpar@100
   137
  std::cout << __FILE__ ": All tests passed.\n";
alpar@100
   138
alpar@100
   139
  return 0;
alpar@100
   140
}