COIN-OR::LEMON - Graph Library

source: lemon-0.x/test/heap_test.cc @ 1866:c2de2ed28e59

Last change on this file since 1866:c2de2ed28e59 was 1845:f8bbfed86036, checked in by Balazs Dezso, 18 years ago

Implementation redesign
Throws exception

File size: 3.2 KB
RevLine 
[1187]1// -*- c++ -*-
2
3#include <iostream>
4#include <fstream>
[1215]5#include <string>
[1187]6#include <vector>
7
8#include <lemon/concept_check.h>
[1330]9#include <lemon/concept/heap.h>
[1187]10
[1206]11#include <lemon/smart_graph.h>
12
13#include <lemon/graph_reader.h>
14
[1187]15#include <lemon/bin_heap.h>
16#include <lemon/fib_heap.h>
17#include <lemon/radix_heap.h>
[1728]18#include <lemon/linear_heap.h>
[1187]19
[1206]20#include "test_tools.h"
[1187]21
22#include "heap_test.h"
23
[1728]24#include <lemon/time_measure.h>
[1187]25
26using namespace lemon;
[1330]27using namespace lemon::concept;
[1187]28
29
30int 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
[1206]48  /// \todo create own test graph
[1215]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.");
[1744]58  GraphReader<Graph>(input, graph).
[1845]59    readEdgeMap("capacity", length).
[1744]60    readNode("source", start).
61    run(); 
[1187]62 
63  {
64    std::cerr << "Checking Bin Heap" << std::endl;
65
66    typedef BinHeap<Item, Prio, ItemIntMap> IntHeap;
[1330]67    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
[1206]68    heapSortTest<IntHeap>(100);
69    heapIncreaseTest<IntHeap>(100);
[1187]70   
71    typedef FibHeap<Node, Prio, Graph::NodeMap<int> > NodeHeap;
[1330]72    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
[1728]73    Timer timer;
[1187]74    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
[1728]75    std::cout << timer << std::endl;
[1187]76  }
77  {
78    std::cerr << "Checking Fib Heap" << std::endl;
79
80    typedef FibHeap<Item, Prio, ItemIntMap> IntHeap;
[1330]81    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
[1206]82    heapSortTest<IntHeap>(100);
83    heapIncreaseTest<IntHeap>(100);
[1187]84
85    typedef FibHeap<Node, Prio, Graph::NodeMap<int> > NodeHeap;
[1330]86    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
[1728]87    Timer timer;
[1187]88    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
[1728]89    std::cout << timer << std::endl;
[1187]90  }
91  {
92    std::cerr << "Checking Radix Heap" << std::endl;
93
94    typedef RadixHeap<Item, ItemIntMap> IntHeap;
[1330]95    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
[1206]96    heapSortTest<IntHeap>(100);
97    heapIncreaseTest<IntHeap>(100);
[1187]98
99    typedef RadixHeap<Node, Graph::NodeMap<int> > NodeHeap;
[1330]100    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
[1728]101    Timer timer;
[1187]102    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
[1728]103    std::cout << timer << std::endl;
104  }
105
106  {
107    std::cerr << "Checking Linear Heap" << std::endl;
108
109    typedef LinearHeap<Item, ItemIntMap> IntHeap;
110    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
111    heapSortTest<IntHeap>(100);
112    heapIncreaseTest<IntHeap>(100);
113
114    typedef LinearHeap<Node, Graph::NodeMap<int> > NodeHeap;
115    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
116    Timer timer;
117    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
118    std::cout << timer << std::endl;
[1187]119  }
120
121  std::cout << __FILE__ ": All tests passed.\n";
122
123  return 0;
124}
Note: See TracBrowser for help on using the repository browser.