| 1 | //======================================================================= |
|---|
| 2 | // Copyright 1997, 1998, 1999, 2000 University of Notre Dame. |
|---|
| 3 | // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek |
|---|
| 4 | // |
|---|
| 5 | // Distributed under the Boost Software License, Version 1.0. (See |
|---|
| 6 | // accompanying file LICENSE_1_0.txt or copy at |
|---|
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 8 | //======================================================================= |
|---|
| 9 | #include <boost/config.hpp> |
|---|
| 10 | #include <iostream> |
|---|
| 11 | #include <vector> |
|---|
| 12 | #include <boost/graph/random.hpp> |
|---|
| 13 | #include <boost/random/mersenne_twister.hpp> |
|---|
| 14 | #include <algorithm> |
|---|
| 15 | #include <boost/pending/fibonacci_heap.hpp> |
|---|
| 16 | #include <boost/graph/graph_utility.hpp> |
|---|
| 17 | #include <boost/pending/indirect_cmp.hpp> |
|---|
| 18 | |
|---|
| 19 | using namespace boost; |
|---|
| 20 | |
|---|
| 21 | int |
|---|
| 22 | main() |
|---|
| 23 | { |
|---|
| 24 | typedef indirect_cmp<float*,std::less<float> > ICmp; |
|---|
| 25 | int i; |
|---|
| 26 | boost::mt19937 gen; |
|---|
| 27 | for (int N = 2; N < 200; ++N) { |
|---|
| 28 | uniform_int<> distrib(0, N-1); |
|---|
| 29 | variate_generator<boost::mt19937&, uniform_int<> > rand_gen(gen, distrib); |
|---|
| 30 | for (int t = 0; t < 10; ++t) { |
|---|
| 31 | std::vector<float> v, w(N); |
|---|
| 32 | |
|---|
| 33 | ICmp cmp(&w[0], std::less<float>()); |
|---|
| 34 | fibonacci_heap<int, ICmp> Q(N, cmp); |
|---|
| 35 | |
|---|
| 36 | for (int c = 0; c < w.size(); ++c) |
|---|
| 37 | w[c] = c; |
|---|
| 38 | std::random_shuffle(w.begin(), w.end()); |
|---|
| 39 | |
|---|
| 40 | for (i = 0; i < N; ++i) |
|---|
| 41 | Q.push(i); |
|---|
| 42 | |
|---|
| 43 | for (i = 0; i < N; ++i) { |
|---|
| 44 | int u = rand_gen(); |
|---|
| 45 | float r = rand_gen(); r /= 2.0; |
|---|
| 46 | w[u] = w[u] - r; |
|---|
| 47 | Q.update(u); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | for (i = 0; i < N; ++i) { |
|---|
| 51 | v.push_back(w[Q.top()]); |
|---|
| 52 | Q.pop(); |
|---|
| 53 | } |
|---|
| 54 | std::sort(w.begin(), w.end()); |
|---|
| 55 | |
|---|
| 56 | if (! std::equal(v.begin(), v.end(), w.begin())) { |
|---|
| 57 | std::cout << std::endl << "heap sorted: "; |
|---|
| 58 | std::copy(v.begin(), v.end(), |
|---|
| 59 | std::ostream_iterator<float>(std::cout," ")); |
|---|
| 60 | std::cout << std::endl << "correct: "; |
|---|
| 61 | std::copy(w.begin(), w.end(), |
|---|
| 62 | std::ostream_iterator<float>(std::cout," ")); |
|---|
| 63 | std::cout << std::endl; |
|---|
| 64 | return -1; |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | std::cout << "fibonacci heap passed test" << std::endl; |
|---|
| 69 | return 0; |
|---|
| 70 | } |
|---|