[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 | |
---|
| 26 | using namespace lemon; |
---|
[1330] | 27 | using namespace lemon::concept; |
---|
[1187] | 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 | |
---|
[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."); |
---|
[1206] | 58 | readGraph(input, graph, length, start); |
---|
[1187] | 59 | |
---|
| 60 | { |
---|
| 61 | std::cerr << "Checking Bin Heap" << std::endl; |
---|
| 62 | |
---|
| 63 | typedef BinHeap<Item, Prio, ItemIntMap> IntHeap; |
---|
[1330] | 64 | checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>(); |
---|
[1206] | 65 | heapSortTest<IntHeap>(100); |
---|
| 66 | heapIncreaseTest<IntHeap>(100); |
---|
[1187] | 67 | |
---|
| 68 | typedef FibHeap<Node, Prio, Graph::NodeMap<int> > NodeHeap; |
---|
[1330] | 69 | checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>(); |
---|
[1728] | 70 | Timer timer; |
---|
[1187] | 71 | dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start); |
---|
[1728] | 72 | std::cout << timer << std::endl; |
---|
[1187] | 73 | } |
---|
| 74 | { |
---|
| 75 | std::cerr << "Checking Fib Heap" << std::endl; |
---|
| 76 | |
---|
| 77 | typedef FibHeap<Item, Prio, ItemIntMap> IntHeap; |
---|
[1330] | 78 | checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>(); |
---|
[1206] | 79 | heapSortTest<IntHeap>(100); |
---|
| 80 | heapIncreaseTest<IntHeap>(100); |
---|
[1187] | 81 | |
---|
| 82 | typedef FibHeap<Node, Prio, Graph::NodeMap<int> > NodeHeap; |
---|
[1330] | 83 | checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>(); |
---|
[1728] | 84 | Timer timer; |
---|
[1187] | 85 | dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start); |
---|
[1728] | 86 | std::cout << timer << std::endl; |
---|
[1187] | 87 | } |
---|
| 88 | { |
---|
| 89 | std::cerr << "Checking Radix Heap" << std::endl; |
---|
| 90 | |
---|
| 91 | typedef RadixHeap<Item, ItemIntMap> IntHeap; |
---|
[1330] | 92 | checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>(); |
---|
[1206] | 93 | heapSortTest<IntHeap>(100); |
---|
| 94 | heapIncreaseTest<IntHeap>(100); |
---|
[1187] | 95 | |
---|
| 96 | typedef RadixHeap<Node, Graph::NodeMap<int> > NodeHeap; |
---|
[1330] | 97 | checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>(); |
---|
[1728] | 98 | Timer timer; |
---|
[1187] | 99 | dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start); |
---|
[1728] | 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; |
---|
[1187] | 116 | } |
---|
| 117 | |
---|
| 118 | std::cout << __FILE__ ": All tests passed.\n"; |
---|
| 119 | |
---|
| 120 | return 0; |
---|
| 121 | } |
---|