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