Location: LEMON/LEMON-main/test/heap_test.h - annotation
Load file history
Bfs/Dfs/Dijkstra and their deps ported from svn trung -r 3441.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b r100:4f754b4cf82b | /* -*- C++ -*-
*
* This file is a part of LEMON, a generic C++ optimization library
*
* Copyright (C) 2003-2008
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
*
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
*
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
* purpose.
*
*/
#include <vector>
#include <algorithm>
#include <lemon/dijkstra.h>
class IntIntMap : public std::vector<int> {
public:
typedef std::vector<int> Parent;
typedef int Key;
typedef int Value;
IntIntMap() : Parent() {}
IntIntMap(int n) : Parent(n) {}
IntIntMap(int n, int v) : Parent(n, v) {}
void set(int key, int value) {
Parent::operator[](key) = value;
}
};
template <typename _Heap>
void heapSortTest(int n) {
typedef _Heap Heap;
IntIntMap map(n, -1);
Heap heap(map);
std::vector<int> v(n);
for (int i = 0; i < n; ++i) {
v[i] = rnd[1000];
heap.push(i, v[i]);
}
std::sort(v.begin(), v.end());
for (int i = 0; i < n; ++i) {
check(v[i] == heap.prio() ,"Wrong order in heap sort.");
heap.pop();
}
}
template <typename _Heap>
void heapIncreaseTest(int n) {
typedef _Heap Heap;
IntIntMap map(n, -1);
Heap heap(map);
std::vector<int> v(n);
for (int i = 0; i < n; ++i) {
v[i] = rnd[1000];
heap.push(i, v[i]);
}
for (int i = 0; i < n; ++i) {
v[i] += rnd[1000];
heap.increase(i, v[i]);
}
std::sort(v.begin(), v.end());
for (int i = 0; i < n; ++i) {
check(v[i] == heap.prio() ,"Wrong order in heap increase test.");
heap.pop();
}
}
template <typename _Digraph, typename _LengthMap, typename _Heap>
void dijkstraHeapTest(_Digraph& digraph, _LengthMap& length,
typename _Digraph::Node& start) {
typedef _Heap Heap;
typedef _Digraph Digraph;
typedef _LengthMap LengthMap;
typedef typename Digraph::Node Node;
typedef typename Digraph::Arc Arc;
typedef typename Digraph::NodeIt NodeIt;
typedef typename Digraph::ArcIt ArcIt;
typename Dijkstra<Digraph, LengthMap>::template DefStandardHeap<Heap>::
Create dijkstra(digraph, length);
dijkstra.run(start);
for(ArcIt e(digraph); e!=INVALID; ++e) {
Node u=digraph.source(e);
Node v=digraph.target(e);
if (dijkstra.reached(u)) {
check( dijkstra.dist(v) - dijkstra.dist(u) <= length[e],
"Error in a shortest path tree arc!");
}
}
for(NodeIt v(digraph); v!=INVALID; ++v) {
if ( dijkstra.reached(v) && dijkstra.predArc(v) != INVALID ) {
Arc e=dijkstra.predArc(v);
Node u=digraph.source(e);
check( dijkstra.dist(v) - dijkstra .dist(u) == length[e],
"Error in a shortest path tree arc!");
}
}
}
|