summaryrefslogtreecommitdiff
path: root/src/Alpha_complex/benchmark/Alpha_complex_3d_benchmark.cpp
blob: 99ad94b9f5f3ab4620b47c1a337daf52ce99f37f (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#include <gudhi/Alpha_complex_3d.h>
#include <gudhi/Alpha_complex.h>
// to construct a simplex_tree from alpha complex
#include <gudhi/Simplex_tree.h>
#include <gudhi/random_point_generators.h>
#include <gudhi/Clock.h>

#include <iostream>
#include <string>
#include <vector>
#include <limits>  // for numeric limits
#include <fstream>

#include <CGAL/Epick_d.h>
#include <CGAL/Epeck_d.h>
#include <CGAL/Random.h>

std::ofstream results_csv("results.csv");

template <typename Kernel>
void benchmark_points_on_torus_dD(const std::string& msg) {
  std::cout << "+ " << msg << std::endl;

  results_csv << "\"" << msg << "\";" << std::endl;
  results_csv << "\"nb_points\";"
              << "\"nb_simplices\";"
              << "\"alpha_creation_time(sec.)\";"
              << "\"complex_creation_time(sec.)\";" << std::endl;

  using K = CGAL::Epick_d<CGAL::Dimension_tag<3>>;
  for (int nb_points = 1000; nb_points <= 125000; nb_points *= 5) {
    std::cout << "  Alpha complex dD on torus with " << nb_points << " points." << std::endl;
    std::vector<K::Point_d> points_on_torus = Gudhi::generate_points_on_torus_3D<K>(nb_points, 1.0, 0.5);
    std::vector<typename Kernel::Point_d> points;

    for (auto p : points_on_torus) {
      points.push_back(typename Kernel::Point_d(p.begin(), p.end()));
    }

    Gudhi::Clock ac_create_clock("    benchmark_points_on_torus_dD - Alpha complex 3d creation");
    ac_create_clock.begin();
    Gudhi::alpha_complex::Alpha_complex<Kernel> alpha_complex_from_points(points);
    ac_create_clock.end();
    std::cout << ac_create_clock;

    Gudhi::Simplex_tree<> complex;
    Gudhi::Clock st_create_clock("    benchmark_points_on_torus_dD - complex creation");
    st_create_clock.begin();
    alpha_complex_from_points.create_complex(complex);
    st_create_clock.end();
    std::cout << st_create_clock;

    results_csv << nb_points << ";" << complex.num_simplices() << ";" << ac_create_clock.num_seconds() << ";"
                << st_create_clock.num_seconds() << ";" << std::endl;

    std::cout << "    benchmark_points_on_torus_dD - nb simplices = " << complex.num_simplices() << std::endl;
  }
}

template <typename Alpha_complex_3d>
void benchmark_points_on_torus_3D(const std::string& msg) {
  using K = CGAL::Epick_d<CGAL::Dimension_tag<3>>;
  std::cout << "+ " << msg << std::endl;

  results_csv << "\"" << msg << "\";" << std::endl;
  results_csv << "\"nb_points\";"
              << "\"nb_simplices\";"
              << "\"alpha_creation_time(sec.)\";"
              << "\"complex_creation_time(sec.)\";" << std::endl;

  for (int nb_points = 1000; nb_points <= 125000; nb_points *= 5) {
    std::cout << "  Alpha complex 3d on torus with " << nb_points << " points." << std::endl;
    std::vector<K::Point_d> points_on_torus = Gudhi::generate_points_on_torus_3D<K>(nb_points, 1.0, 0.5);
    std::vector<typename Alpha_complex_3d::Point_3> points;

    for (auto p : points_on_torus) {
      points.push_back(typename Alpha_complex_3d::Point_3(p[0], p[1], p[2]));
    }

    Gudhi::Clock ac_create_clock("    benchmark_points_on_torus_3D - Alpha complex 3d creation");
    ac_create_clock.begin();
    Alpha_complex_3d alpha_complex_from_points(points);
    ac_create_clock.end();
    std::cout << ac_create_clock;

    Gudhi::Simplex_tree<> complex;
    Gudhi::Clock st_create_clock("    benchmark_points_on_torus_3D - complex creation");
    st_create_clock.begin();
    alpha_complex_from_points.create_complex(complex);
    st_create_clock.end();
    std::cout << st_create_clock;

    results_csv << nb_points << ";" << complex.num_simplices() << ";" << ac_create_clock.num_seconds() << ";"
                << st_create_clock.num_seconds() << ";" << std::endl;

    std::cout << "    benchmark_points_on_torus_3D - nb simplices = " << complex.num_simplices() << std::endl;
  }
}

template <typename Weighted_alpha_complex_3d>
void benchmark_weighted_points_on_torus_3D(const std::string& msg) {
  using K = CGAL::Epick_d<CGAL::Dimension_tag<3>>;

  std::cout << "+ " << msg << std::endl;

  results_csv << "\"" << msg << "\";" << std::endl;
  results_csv << "\"nb_points\";"
              << "\"nb_simplices\";"
              << "\"alpha_creation_time(sec.)\";"
              << "\"complex_creation_time(sec.)\";" << std::endl;

  CGAL::Random random(8);

  for (int nb_points = 1000; nb_points <= 125000; nb_points *= 5) {
    std::cout << "  Alpha complex 3d on torus with " << nb_points << " points." << std::endl;
    std::vector<K::Point_d> points_on_torus = Gudhi::generate_points_on_torus_3D<K>(nb_points, 1.0, 0.5);

    using Point = typename Weighted_alpha_complex_3d::Bare_point_3;
    using Weighted_point = typename Weighted_alpha_complex_3d::Weighted_point_3;

    std::vector<Weighted_point> points;

    for (auto p : points_on_torus) {
      points.push_back(Weighted_point(Point(p[0], p[1], p[2]), 0.9 + random.get_double(0., 0.01)));
    }

    Gudhi::Clock ac_create_clock("    benchmark_weighted_points_on_torus_3D - Alpha complex 3d creation");
    ac_create_clock.begin();
    Weighted_alpha_complex_3d alpha_complex_from_points(points);
    ac_create_clock.end();
    std::cout << ac_create_clock;

    Gudhi::Simplex_tree<> complex;
    Gudhi::Clock st_create_clock("    benchmark_weighted_points_on_torus_3D - complex creation");
    st_create_clock.begin();
    alpha_complex_from_points.create_complex(complex);
    st_create_clock.end();
    std::cout << st_create_clock;

    results_csv << nb_points << ";" << complex.num_simplices() << ";" << ac_create_clock.num_seconds() << ";"
                << st_create_clock.num_seconds() << ";" << std::endl;

    std::cout << "    benchmark_weighted_points_on_torus_3D - nb simplices = " << complex.num_simplices() << std::endl;
  }
}

template <typename Periodic_alpha_complex_3d>
void benchmark_periodic_points(const std::string& msg) {
  std::cout << "+ " << msg << std::endl;

  results_csv << "\"" << msg << "\";" << std::endl;
  results_csv << "\"nb_points\";"
              << "\"nb_simplices\";"
              << "\"alpha_creation_time(sec.)\";"
              << "\"complex_creation_time(sec.)\";" << std::endl;

  CGAL::Random random(8);

  for (double nb_points = 10.; nb_points <= 40.; nb_points += 10.) {
    std::cout << "  Periodic alpha complex 3d with " << nb_points * nb_points * nb_points << " points." << std::endl;
    using Point = typename Periodic_alpha_complex_3d::Point_3;
    std::vector<Point> points;

    for (double i = 0; i < nb_points; i++) {
      for (double j = 0; j < nb_points; j++) {
        for (double k = 0; k < nb_points; k++) {
          points.push_back(
              Point(i + random.get_double(0., 0.1), j + random.get_double(0., 0.1), k + random.get_double(0., 0.1)));
        }
      }
    }

    Gudhi::Clock ac_create_clock("    benchmark_periodic_points - Alpha complex 3d creation");
    ac_create_clock.begin();
    Periodic_alpha_complex_3d alpha_complex_from_points(points, 0., 0., 0., nb_points, nb_points, nb_points);
    ac_create_clock.end();
    std::cout << ac_create_clock;

    Gudhi::Simplex_tree<> complex;
    Gudhi::Clock st_create_clock("    benchmark_periodic_points - complex creation");
    st_create_clock.begin();
    alpha_complex_from_points.create_complex(complex);
    st_create_clock.end();
    std::cout << st_create_clock;

    results_csv << nb_points * nb_points * nb_points << ";" << complex.num_simplices() << ";"
                << ac_create_clock.num_seconds() << ";" << st_create_clock.num_seconds() << ";" << std::endl;

    std::cout << "    benchmark_periodic_points - nb simplices = " << complex.num_simplices() << std::endl;
  }
}

template <typename Weighted_periodic_alpha_complex_3d>
void benchmark_weighted_periodic_points(const std::string& msg) {
  std::cout << "+ " << msg << std::endl;

  results_csv << "\"" << msg << "\";" << std::endl;
  results_csv << "\"nb_points\";"
              << "\"nb_simplices\";"
              << "\"alpha_creation_time(sec.)\";"
              << "\"complex_creation_time(sec.)\";" << std::endl;

  CGAL::Random random(8);

  for (double nb_points = 10.; nb_points <= 40.; nb_points += 10.) {
    std::cout << "  Weighted periodic alpha complex 3d with " << nb_points * nb_points * nb_points << " points."
              << std::endl;

    using Point = typename Weighted_periodic_alpha_complex_3d::Bare_point_3;
    using Weighted_point = typename Weighted_periodic_alpha_complex_3d::Weighted_point_3;
    std::vector<Weighted_point> points;

    for (double i = 0; i < nb_points; i++) {
      for (double j = 0; j < nb_points; j++) {
        for (double k = 0; k < nb_points; k++) {
          points.push_back(Weighted_point(
              Point(i + random.get_double(0., 0.1), j + random.get_double(0., 0.1), k + random.get_double(0., 0.1)),
              random.get_double(0., (nb_points * nb_points) / 64.)));
        }
      }
    }

    Gudhi::Clock ac_create_clock("    benchmark_weighted_periodic_points - Alpha complex 3d creation");
    ac_create_clock.begin();
    Weighted_periodic_alpha_complex_3d alpha_complex_from_points(points, 0., 0., 0., nb_points, nb_points, nb_points);
    ac_create_clock.end();
    std::cout << ac_create_clock;

    Gudhi::Simplex_tree<> complex;
    Gudhi::Clock st_create_clock("    benchmark_weighted_periodic_points - complex creation");
    st_create_clock.begin();
    alpha_complex_from_points.create_complex(complex);
    st_create_clock.end();
    std::cout << st_create_clock;

    results_csv << nb_points * nb_points * nb_points << ";" << complex.num_simplices() << ";"
                << ac_create_clock.num_seconds() << ";" << st_create_clock.num_seconds() << ";" << std::endl;

    std::cout << "    benchmark_weighted_periodic_points - nb simplices = " << complex.num_simplices() << std::endl;
  }
}

int main(int argc, char** argv) {
  benchmark_points_on_torus_dD<CGAL::Epick_d<CGAL::Dimension_tag<3>>>("Fast static dimension version");
  benchmark_points_on_torus_dD<CGAL::Epick_d<CGAL::Dynamic_dimension_tag>>("Fast dynamic dimension version");
  benchmark_points_on_torus_dD<CGAL::Epeck_d<CGAL::Dimension_tag<3>>>("Exact static dimension version");
  benchmark_points_on_torus_dD<CGAL::Epeck_d<CGAL::Dynamic_dimension_tag>>("Exact dynamic dimension version");

  benchmark_points_on_torus_3D<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::FAST, false, false>>("Fast version");
  benchmark_points_on_torus_3D<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::SAFE, false, false>>("Safe version");
  benchmark_points_on_torus_3D<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::EXACT, false, false>>("Exact version");

  benchmark_weighted_points_on_torus_3D<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::FAST, true, false>>("Fast version");
  benchmark_weighted_points_on_torus_3D<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::SAFE, true, false>>("Safe version");
  benchmark_weighted_points_on_torus_3D<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::EXACT, true, false>>("Exact version");

  benchmark_periodic_points<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::FAST, false, true>>("Fast version");
  benchmark_periodic_points<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::SAFE, false, true>>("Safe version");
  benchmark_periodic_points<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::EXACT, false, true>>("Exact version");

  benchmark_weighted_periodic_points<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::FAST, true, true>>("Fast version");
  benchmark_weighted_periodic_points<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::SAFE, true, true>>("Safe version");
  benchmark_weighted_periodic_points<
      Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::EXACT, true, true>>("Exact version");

  return 0;
}