Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
test-convexhull-time.C
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32# include <iostream>
33
34# include <ah-random.H>
35
36# include <geom_algorithms.H>
37# include <ahNow.H>
38
39using namespace std;
40
42
44{
45 Points ret;
46
47 for (size_t i = 0; i < n; ++i)
48 ret.append(Point(rng.get(), rng.get()));
49
50 return ret;
51}
52
53int main()
54{
55 constexpr size_t num_exp = 6;
56 constexpr size_t num_test = 12;
57 size_t sample_size = 128;
58
59 Gsl_Compatible_Rng rng(time(nullptr));
60
61 double sz[num_exp];
62 double bf[num_exp];
63 double gw[num_exp];
64 double qh[num_exp];
65
66 for (size_t i = 0; i < num_exp; ++i)
67 {
68 cout << "Testing sample size: " << sample_size << endl;
69
70 sz[i] = sample_size;
71
72 bf[i] = gw[i] = qh[i] = 0.0;
73
74 for (size_t j = 0; j < num_test; ++j)
75 {
76 Points points = generate_points(sample_size, rng);
77
78 Now now;
79 now.start();
80 QuickHull()(points);
81 qh[i] += now.elapsed();
82
83 now.start();
84 GiftWrappingConvexHull()(points);
85 gw[i] += now.elapsed();
86
87 now.start();
88 BruteForceConvexHull()(points);
89 bf[i] += now.elapsed();
90 }
91
92 sample_size = sample_size << 1;
93 }
94
95 cout << "Sample size\tQuick hull\tGift wrapping\tBrute force\n"
96 << "===========\t===========\t=============\t==========\n";
97
98 for (size_t i = 0; i < num_exp; ++i)
99 cout << sz[i] << '\t' << qh[i]/num_test << '\t' << gw[i]/num_test
100 << '\t' << bf[i]/num_test << endl;
101
102
103 return 0;
104}
105
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
High-resolution timer and benchmarking utilities.
Brute force convex hull algorithm.
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
T & append(const T &item)
Definition htlist.H:1362
Gift wrapping (Jarvis march) convex hull algorithm.
A random number generator with the sequences of GSL's gsl_rng_mt19937.
Definition ah-random.H:147
Class Now is a practical class for timing based in a high resolution clock.
Definition ahNow.H:79
TimePointType start()
Sets internally the current time point.
Definition ahNow.H:195
double elapsed()
Calculates the time that has elapsed since the last time start(), elapsed() or delta() was called.
Definition ahNow.H:209
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:221
QuickHull convex hull algorithm.
static mt19937 rng
Computational geometry algorithms.
STL namespace.
Points generate_points(size_t n, Gsl_Compatible_Rng &rng)
int main()