DGtal  1.5.beta
pConvexity-benchmark.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
31 #include <vector>
32 #include <algorithm>
33 #include <chrono>
34 #include "DGtal/base/Common.h"
35 #include "DGtal/kernel/SpaceND.h"
36 #include "DGtal/kernel/domains/HyperRectDomain.h"
37 #include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
38 #include "DGtal/topology/KhalimskySpaceND.h"
39 #include "DGtal/shapes/Shapes.h"
40 #include "DGtal/geometry/volumes/PConvexity.h"
41 #include "DGtal/geometry/volumes/DigitalConvexity.h"
42 
68 using namespace std;
69 using namespace DGtal;
70 
71 double rand01() { return double( rand() ) / double( RAND_MAX ); }
72 
73 template <Dimension dim>
74 void
75 timingsPConvexity( std::vector< std::tuple< std::size_t, double, bool > >& results,
76  std::size_t nb_tries, std::size_t nb_vertices, std::size_t range,
77  double pconvexity_probability = 0.5 )
78 {
80  typedef typename KSpace::Point Point;
81  typedef typename KSpace::Space Space;
83  typedef DigitalConvexity< KSpace > DConvexity;
85  DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
86  PConvexity pconv;
87  Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
88  std::cout << "Computing " << nb_tries << " P-convexities in Z" << dim << std::endl;
89  for ( auto n = 0; n < nb_tries; ++n )
90  {
91  // Create vertices
92  std::vector< Point > V;
93  for ( auto i = 0; i < nb_vertices; i++ ) {
94  Point p;
95  for ( auto j = 0; j < dim; j++ ) p[ j ] = rand() % range;
96  V.push_back( p );
97  }
98  // create 0-convex or fully convex set.
99  std::vector< Point > X;
100  bool force_pconvexity = rand01() < pconvexity_probability;
101  if ( force_pconvexity )
102  X = dconv.envelope( V );
103  else
104  {
105  auto P = dconv.CvxH( V );
106  P.getPoints( X );
107  }
108  // Analyse P-convexity
109  std::chrono::high_resolution_clock::time_point
110  t1 = std::chrono::high_resolution_clock::now();
111  bool is_pconvex = pconv.isPConvex( X );
112  std::chrono::high_resolution_clock::time_point
113  t2 = std::chrono::high_resolution_clock::now();
114  double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
115  results.push_back( std::make_tuple( X.size(), dt/1e6, is_pconvex ) );
116  if ( force_pconvexity && ! is_pconvex )
117  trace.warning() << "Invalid computation of either FC* or P-convexity !" << std::endl;
118  }
119 }
120 
121 template <Dimension dim>
122 void
123 timingsFullConvexity( std::vector< std::tuple< std::size_t, double, bool > >& results,
124  std::size_t nb_tries, std::size_t nb_vertices, std::size_t range,
125  double fconvexity_probability = 0.5 )
126 {
128  typedef typename KSpace::Point Point;
129  typedef typename KSpace::Space Space;
131  typedef DigitalConvexity< KSpace > DConvexity;
133  DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
134  PConvexity pconv;
135  Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
136  std::cout << "Computing " << nb_tries << " full convexities in Z" << dim << std::endl;
137  for ( auto n = 0; n < nb_tries; ++n )
138  {
139  // Create vertices
140  std::vector< Point > V;
141  for ( auto i = 0; i < nb_vertices; i++ ) {
142  Point p;
143  for ( auto j = 0; j < dim; j++ ) p[ j ] = rand() % range;
144  V.push_back( p );
145  }
146  // create 0-convex or fully convex set.
147  std::vector< Point > X;
148  bool force_fconvexity = rand01() < fconvexity_probability;
149  if ( force_fconvexity )
150  X = dconv.envelope( V );
151  else
152  {
153  auto P = dconv.CvxH( V );
154  P.getPoints( X );
155  }
156  // Analyse full convexity
157  std::chrono::high_resolution_clock::time_point
158  t1 = std::chrono::high_resolution_clock::now();
159  bool is_fconvex = dconv.isFullyConvex( X );
160  std::chrono::high_resolution_clock::time_point
161  t2 = std::chrono::high_resolution_clock::now();
162  double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
163  results.push_back( std::make_tuple( X.size(), dt/1e6, is_fconvex ) );
164  if ( force_fconvexity && ! is_fconvex )
165  trace.warning() << "Invalid computation of either FC* or full convexity !" << std::endl;
166  }
167 }
168 
169 template <Dimension dim>
170 void
171 timingsFullConvexityFast( std::vector< std::tuple< std::size_t, double, bool > >& results,
172  std::size_t nb_tries, std::size_t nb_vertices, std::size_t range,
173  double fconvexity_probability = 0.5 )
174 {
176  typedef typename KSpace::Point Point;
177  typedef typename KSpace::Space Space;
179  typedef DigitalConvexity< KSpace > DConvexity;
181  DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
182  PConvexity pconv;
183  Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
184  std::cout << "Computing " << nb_tries << " full convexities in Z" << dim << std::endl;
185  for ( auto n = 0; n < nb_tries; ++n )
186  {
187  // Create vertices
188  std::vector< Point > V;
189  for ( auto i = 0; i < nb_vertices; i++ ) {
190  Point p;
191  for ( auto j = 0; j < dim; j++ ) p[ j ] = rand() % range;
192  V.push_back( p );
193  }
194  // create 0-convex or fully convex set.
195  std::vector< Point > X;
196  bool force_fconvexity = rand01() < fconvexity_probability;
197  if ( force_fconvexity )
198  X = dconv.envelope( V );
199  else
200  {
201  auto P = dconv.CvxH( V );
202  P.getPoints( X );
203  }
204  // Analyse full convexity
205  std::chrono::high_resolution_clock::time_point
206  t1 = std::chrono::high_resolution_clock::now();
207  bool is_fconvex = dconv.isFullyConvexFast( X );
208  std::chrono::high_resolution_clock::time_point
209  t2 = std::chrono::high_resolution_clock::now();
210  double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
211  results.push_back( std::make_tuple( X.size(), dt/1e6, is_fconvex ) );
212  if ( force_fconvexity && ! is_fconvex )
213  trace.warning() << "Invalid computation of either FC* or full convexity !" << std::endl;
214  }
215 }
216 
217 
218 template <Dimension dim>
219 void
221 ( std::vector< std::tuple< std::size_t, double, bool > >& results,
222  std::size_t nb_tries, std::size_t range )
223 {
225  typedef typename KSpace::Point Point;
226  typedef typename KSpace::Space Space;
228  typedef DigitalConvexity< KSpace > DConvexity;
230  DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
231  PConvexity pconv;
232  Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
233  std::cout << "Computing " << nb_tries << " P-convexities in Z" << dim << std::endl;
234  for ( auto n = 0; n < nb_tries; ++n )
235  {
236  double filling_probability = 0.1 + 0.9 * double( n ) / double( nb_tries );
237  // Create vertices
238  std::set< Point > S;
239  std::size_t nb_vertices
240  = std::size_t( filling_probability * ceil( pow( range, dim ) ) );
241  for ( auto i = 0; i < nb_vertices; i++ ) {
242  Point p;
243  for ( auto j = 0; j < dim; j++ ) p[ j ] = rand() % range;
244  S.insert( p );
245  }
246  // create digital set.
247  std::vector< Point > X( S.cbegin(), S.cend() );
248  // Analyse P-convexity
249  std::chrono::high_resolution_clock::time_point
250  t1 = std::chrono::high_resolution_clock::now();
251  bool is_pconvex = pconv.isPConvex( X );
252  std::chrono::high_resolution_clock::time_point
253  t2 = std::chrono::high_resolution_clock::now();
254  double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
255  results.push_back( std::make_tuple( X.size(), dt/1e6, is_pconvex ) );
256  }
257 }
258 
259 template <Dimension dim>
260 void
262 ( std::vector< std::tuple< std::size_t, double, bool > >& results,
263  std::size_t nb_tries, std::size_t range )
264 {
266  typedef typename KSpace::Point Point;
267  typedef typename KSpace::Space Space;
269  typedef DigitalConvexity< KSpace > DConvexity;
271  DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
272  PConvexity pconv;
273  Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
274  std::cout << "Computing " << nb_tries << " full convexities in Z" << dim << std::endl;
275  for ( auto n = 0; n < nb_tries; ++n )
276  {
277  double filling_probability = 0.1 + 0.9 * double( n ) / double( nb_tries );
278  // Create vertices
279  std::set< Point > S;
280  std::size_t nb_vertices
281  = std::size_t( filling_probability * ceil( pow( range, dim ) ) );
282  for ( auto i = 0; i < nb_vertices; i++ ) {
283  Point p;
284  for ( auto j = 0; j < dim; j++ ) p[ j ] = rand() % range;
285  S.insert( p );
286  }
287  // create digital set.
288  std::vector< Point > X( S.cbegin(), S.cend() );
289  // Analyse full convexity
290  std::chrono::high_resolution_clock::time_point
291  t1 = std::chrono::high_resolution_clock::now();
292  bool is_fconvex = dconv.isFullyConvex( X );
293  std::chrono::high_resolution_clock::time_point
294  t2 = std::chrono::high_resolution_clock::now();
295  double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
296  results.push_back( std::make_tuple( X.size(), dt/1e6, is_fconvex ) );
297  }
298 }
299 
300 
301 template <Dimension dim>
302 void
304 ( std::vector< std::tuple< std::size_t, double, bool > >& results,
305  std::size_t nb_tries, std::size_t range )
306 {
308  typedef typename KSpace::Point Point;
309  typedef typename KSpace::Space Space;
311  typedef DigitalConvexity< KSpace > DConvexity;
313  DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
314  PConvexity pconv;
315  Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
316  std::cout << "Computing " << nb_tries << " full convexities (fast) in Z" << dim << std::endl;
317  for ( auto n = 0; n < nb_tries; ++n )
318  {
319  double filling_probability = 0.1 + 0.9 * double( n ) / double( nb_tries );
320  // Create vertices
321  std::set< Point > S;
322  std::size_t nb_vertices
323  = std::size_t( filling_probability * ceil( pow( range, dim ) ) );
324  for ( auto i = 0; i < nb_vertices; i++ ) {
325  Point p;
326  for ( auto j = 0; j < dim; j++ ) p[ j ] = rand() % range;
327  S.insert( p );
328  }
329  // create digital set.
330  std::vector< Point > X( S.cbegin(), S.cend() );
331  // Analyse full convexity
332  std::chrono::high_resolution_clock::time_point
333  t1 = std::chrono::high_resolution_clock::now();
334  bool is_fconvex = dconv.isFullyConvexFast( X );
335  std::chrono::high_resolution_clock::time_point
336  t2 = std::chrono::high_resolution_clock::now();
337  double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
338  results.push_back( std::make_tuple( X.size(), dt/1e6, is_fconvex ) );
339  }
340 }
341 
342 
343 
345  const std::vector< std::tuple< std::size_t, double, bool > >& results,
346  const std::string& fname )
347 {
348  std::ofstream output( fname );
349  output << "# Results of " << results.size() << " P-convexity computations in Z"
350  << dim << std::endl
351  << "# Card(X) time(ms) p-convex?" << std::endl;
352  for ( auto&& r : results )
353  output << std::get<0>( r ) << " " << std::get<1>( r ) << " " << std::get<2>( r )
354  << std::endl;
355  output.close();
356 }
357 
358 /*
359  Display results using gnuplot
360 
361  plot "./timings-p-convexity-Z2.txt" using 1:2 w p, "./timings-p-convexity-Z3.txt" using 1:2 w p,"./timings-p-convexity-Z4.txt" using 1:2 w p, 0.2e-5*x*log(x) w l lw 2
362 
363  plot "./timings-p-convexity-Z2.txt" using 1:($3 == 1 ? $2 : 1/0) title "P-convex in Z2" w p, "./timings-p-convexity-Z2.txt" using 1:($3 == 0 ? $2 : 1/0) title "non P-convex in Z2" w p, 0.2e-5*x*log(x) w l lw 2
364 
365  plot "./timings-p-convexity-Z3.txt" using 1:($3 == 1 ? $2 : 1/0) title "P-convex in Z3" w p, "./timings-p-convexity-Z3.txt" using 1:($3 == 0 ? $2 : 1/0) title "non P-convex in Z3" w p, 0.4e-5*x*log(x) w l lw 2
366 
367  plot "./timings-p-convexity-Z4.txt" using 1:($3 == 1 ? $2 : 1/0) title "P-convex in Z4" w p, "./timings-p-convexity-Z4.txt" using 1:($3 == 0 ? $2 : 1/0) title "non P-convex in Z4" w p, 0.4e-5*x*log(x) w l lw 2
368 
369  set terminal eps font "Helvetica,14"
370  set key bottom right
371 
372  plot [1e2:1e7][1e-2:1e4] 1e-6*x*log(x) w l lw 3, "./timings-p-convexity-Z2.txt" using 1:($3 == 1 ? $2 : 1/0) title "FC: P-convex charac. (in Z2)" w p pt 5 lc rgb "blue", "./timings-p-convexity-Z2.txt" using 1:($3 == 0 ? $2 : 1/0) title "non FC: P-convex charac. (in Z2)" w p pt 4 lc rgb "blue", "./timings-fcf-convexity-Z2.txt" using 1:($3 == 1 ? $2 : 1/0) title "FC: cellular charac. (in Z2)" w p pt 7 lc rgb "black", "./timings-fcf-convexity-Z2.txt" using 1:($3 == 0 ? $2 : 1/0) title "non FC: cellular charac. (in Z2)" w p pt 6 lc rgb "black", "./timings-fc-convexity-Z2.txt" using 1:($3 == 1 ? $2 : 1/0) title "FC: discrete morphological charac. (in Z2)" w p pt 13 lc rgb "magenta", "./timings-fc-convexity-Z2.txt" using 1:($3 == 0 ? $2 : 1/0) title "non FC: discrete morphological charac. (in Z2)" w p pt 12 lc rgb "magenta"
373 
374 
375  plot [1e2:1e7][1e-2:1e4] 1e-6*x*log(x) w l lw 3, "./timings-p-convexity-Z3.txt" using 1:($3 == 1 ? $2 : 1/0) title "FC: P-convex charac. (in Z3)" w p pt 5 lc rgb "blue", "./timings-p-convexity-Z3.txt" using 1:($3 == 0 ? $2 : 1/0) title "non FC: P-convex charac. (in Z3)" w p pt 4 lc rgb "blue", "./timings-fcf-convexity-Z3.txt" using 1:($3 == 1 ? $2 : 1/0) title "FC: cellular charac. (in Z3)" w p pt 7 lc rgb "black", "./timings-fcf-convexity-Z3.txt" using 1:($3 == 0 ? $2 : 1/0) title "non FC: cellular charac. (in Z3)" w p pt 6 lc rgb "black", "./timings-fc-convexity-Z3.txt" using 1:($3 == 1 ? $2 : 1/0) title "FC: discrete morphological charac. (in Z3)" w p pt 13 lc rgb "magenta", "./timings-fc-convexity-Z3.txt" using 1:($3 == 0 ? $2 : 1/0) title "non FC: discrete morphological charac. (in Z3)" w p pt 12 lc rgb "magenta"
376 
377 
378  plot [1e2:1e7][1e-2:1e4] 1e-6*x*log(x) w l lw 3, "./timings-p-convexity-Z4.txt" using 1:($3 == 1 ? $2 : 1/0) title "FC: P-convex charac. (in Z4)" w p pt 5 lc rgb "blue", "./timings-p-convexity-Z4.txt" using 1:($3 == 0 ? $2 : 1/0) title "non FC: P-convex charac. (in Z4)" w p pt 4 lc rgb "blue", "./timings-fcf-convexity-Z4.txt" using 1:($3 == 1 ? $2 : 1/0) title "FC: cellular charac. (in Z4)" w p pt 7 lc rgb "black", "./timings-fcf-convexity-Z4.txt" using 1:($3 == 0 ? $2 : 1/0) title "non FC: cellular charac. (in Z4)" w p pt 6 lc rgb "black", "./timings-fc-convexity-Z4.txt" using 1:($3 == 1 ? $2 : 1/0) title "FC: discrete morphological charac. (in Z4)" w p pt 13 lc rgb "magenta", "./timings-fc-convexity-Z4.txt" using 1:($3 == 0 ? $2 : 1/0) title "non FC: discrete morphological charac. (in Z4)" w p pt 12 lc rgb "magenta"
379 
380  set terminal eps font "Helvetica,12"
381  set key bottom right
382 
383  plot [1e2:1e7][1e-2:1e4] 1e-6*x*log(x) w l lw 3, "./timings-p-convexity-ncvx-Z2.txt" using 1:2 title "P-convex charac. (in Z2)" w p pt 4 lc rgb "blue", "./timings-fc-convexity-ncvx-Z2.txt" using 1:2 title "discrete morphological charac. (in Z2)" w p pt 12 lc rgb "magenta", "./timings-fcf-convexity-ncvx-Z2.txt" using 1:2 title "cellular charac. (in Z2)" w p pt 6 lc rgb "black"
384 
385  plot [1e2:1e7][1e-2:1e4] 1e-6*x*log(x) w l lw 3, "./timings-p-convexity-ncvx-Z3.txt" using 1:2 title "P-convex charac. (in Z3)" w p pt 4 lc rgb "blue", "./timings-fc-convexity-ncvx-Z3.txt" using 1:2 title "discrete morphological charac. (in Z3)" w p pt 12 lc rgb "magenta", "./timings-fcf-convexity-ncvx-Z3.txt" using 1:2 title "cellular charac. (in Z3)" w p pt 6 lc rgb "black"
386 
387  plot [1e2:1e7][1e-2:1e4] 1e-6*x*log(x) w l lw 3, "./timings-p-convexity-ncvx-Z4.txt" using 1:2 title "P-convex charac. (in Z4)" w p pt 4 lc rgb "blue", "./timings-fc-convexity-ncvx-Z4.txt" using 1:2 title "discrete morphological charac. (in Z4)" w p pt 12 lc rgb "magenta", "./timings-fcf-convexity-ncvx-Z4.txt" using 1:2 title "cellular charac. (in Z4)" w p pt 6 lc rgb "black"
388 
389 
390 */
391 
392 int main( int argc, char* argv[] )
393 {
394  // P-convexity
395  srand( 0 );
396  if ( false )
397  {
398  std::vector< std::tuple< std::size_t, double, bool > > R2;
399  timingsPConvexity<2>( R2, 50, 3, 100, 0.5 );
400  timingsPConvexity<2>( R2, 50, 4, 200, 0.5 );
401  timingsPConvexity<2>( R2, 50, 5, 400, 0.5 );
402  timingsPConvexity<2>( R2, 50, 5, 600, 0.5 );
403  timingsPConvexity<2>( R2, 50, 5, 800, 0.5 );
404  timingsPConvexity<2>( R2, 25, 5,1200, 0.5 );
405  timingsPConvexity<2>( R2, 25, 5,2000, 0.5 );
406  outputResults( 2, R2, "timings-p-convexity-Z2.txt" );
407  }
408  if ( false )
409  {
410  std::vector< std::tuple< std::size_t, double, bool > > R3;
411  timingsPConvexity<3>( R3, 50, 3, 10, 0.5 );
412  timingsPConvexity<3>( R3, 50, 4, 20, 0.5 );
413  timingsPConvexity<3>( R3, 50, 5, 40, 0.5 );
414  timingsPConvexity<3>( R3, 50, 5, 80, 0.5 );
415  timingsPConvexity<3>( R3, 25, 5, 160, 0.5 );
416  timingsPConvexity<3>( R3, 25, 5, 320, 0.5 );
417  outputResults( 3, R3, "timings-p-convexity-Z3.txt" );
418  }
419  if ( false )
420  {
421  std::vector< std::tuple< std::size_t, double, bool > > R4;
422  timingsPConvexity<4>( R4, 50, 5, 10, 0.5 );
423  timingsPConvexity<4>( R4, 50, 5, 15, 0.5 );
424  timingsPConvexity<4>( R4, 50, 5, 20, 0.5 );
425  timingsPConvexity<4>( R4, 50, 5, 30, 0.5 );
426  timingsPConvexity<4>( R4, 25, 5, 40, 0.5 );
427  timingsPConvexity<4>( R4, 25, 5, 60, 0.5 );
428  timingsPConvexity<4>( R4, 15, 6, 80, 0.5 );
429  timingsPConvexity<4>( R4, 15, 6, 100, 0.5 );
430  timingsPConvexity<4>( R4, 15, 6, 120, 0.5 );
431  outputResults( 4, R4, "timings-p-convexity-Z4.txt" );
432  }
433 
434  // Full convexity
435  srand( 0 );
436  if ( false )
437  {
438  std::vector< std::tuple< std::size_t, double, bool > > R2;
439  timingsFullConvexity<2>( R2, 50, 3, 100, 0.5 );
440  timingsFullConvexity<2>( R2, 50, 4, 200, 0.5 );
441  timingsFullConvexity<2>( R2, 50, 5, 400, 0.5 );
442  timingsFullConvexity<2>( R2, 50, 5, 600, 0.5 );
443  timingsFullConvexity<2>( R2, 50, 5, 800, 0.5 );
444  timingsFullConvexity<2>( R2, 25, 5,1200, 0.5 );
445  timingsFullConvexity<2>( R2, 25, 5,2000, 0.5 );
446  outputResults( 2, R2, "timings-fc-convexity-Z2.txt" );
447  }
448  if ( false )
449  {
450  std::vector< std::tuple< std::size_t, double, bool > > R3;
451  timingsFullConvexity<3>( R3, 50, 3, 10, 0.5 );
452  timingsFullConvexity<3>( R3, 50, 4, 20, 0.5 );
453  timingsFullConvexity<3>( R3, 50, 5, 40, 0.5 );
454  timingsFullConvexity<3>( R3, 50, 5, 80, 0.5 );
455  timingsFullConvexity<3>( R3, 25, 5, 160, 0.5 );
456  timingsFullConvexity<3>( R3, 25, 5, 320, 0.5 );
457  outputResults( 3, R3, "timings-fc-convexity-Z3.txt" );
458  }
459  if ( false )
460  {
461  std::vector< std::tuple< std::size_t, double, bool > > R4;
462  timingsFullConvexity<4>( R4, 50, 5, 10, 0.5 );
463  timingsFullConvexity<4>( R4, 50, 5, 15, 0.5 );
464  timingsFullConvexity<4>( R4, 50, 5, 20, 0.5 );
465  timingsFullConvexity<4>( R4, 50, 5, 30, 0.5 );
466  timingsFullConvexity<4>( R4, 25, 5, 40, 0.5 );
467  timingsFullConvexity<4>( R4, 25, 5, 60, 0.5 );
468  timingsFullConvexity<4>( R4, 15, 6, 80, 0.5 );
469  timingsFullConvexity<4>( R4, 10, 6, 100, 0.5 );
470  timingsFullConvexity<4>( R4, 5, 6, 120, 0.5 );
471  outputResults( 4, R4, "timings-fc-convexity-Z4.txt" );
472  }
473 
474  // Full convexity fast
475  srand( 0 );
476  if ( false )
477  {
478  std::vector< std::tuple< std::size_t, double, bool > > R2;
479  timingsFullConvexityFast<2>( R2, 50, 3, 100, 0.5 );
480  timingsFullConvexityFast<2>( R2, 50, 4, 200, 0.5 );
481  timingsFullConvexityFast<2>( R2, 50, 5, 400, 0.5 );
482  timingsFullConvexityFast<2>( R2, 50, 5, 600, 0.5 );
483  timingsFullConvexityFast<2>( R2, 50, 5, 800, 0.5 );
484  timingsFullConvexityFast<2>( R2, 25, 5,1200, 0.5 );
485  timingsFullConvexityFast<2>( R2, 25, 5,2000, 0.5 );
486  outputResults( 2, R2, "timings-fcf-convexity-Z2.txt" );
487  }
488  if ( false )
489  {
490  std::vector< std::tuple< std::size_t, double, bool > > R3;
491  timingsFullConvexityFast<3>( R3, 50, 3, 10, 0.5 );
492  timingsFullConvexityFast<3>( R3, 50, 4, 20, 0.5 );
493  timingsFullConvexityFast<3>( R3, 50, 5, 40, 0.5 );
494  timingsFullConvexityFast<3>( R3, 50, 5, 80, 0.5 );
495  timingsFullConvexityFast<3>( R3, 25, 5, 160, 0.5 );
496  timingsFullConvexityFast<3>( R3, 25, 5, 320, 0.5 );
497  outputResults( 3, R3, "timings-fcf-convexity-Z3.txt" );
498  }
499  if ( false )
500  {
501  std::vector< std::tuple< std::size_t, double, bool > > R4;
502  timingsFullConvexityFast<4>( R4, 50, 5, 10, 0.5 );
503  timingsFullConvexityFast<4>( R4, 50, 5, 15, 0.5 );
504  timingsFullConvexityFast<4>( R4, 50, 5, 20, 0.5 );
505  timingsFullConvexityFast<4>( R4, 50, 5, 30, 0.5 );
506  timingsFullConvexityFast<4>( R4, 25, 5, 40, 0.5 );
507  timingsFullConvexityFast<4>( R4, 25, 5, 60, 0.5 );
508  timingsFullConvexityFast<4>( R4, 15, 6, 80, 0.5 );
509  timingsFullConvexityFast<4>( R4, 10, 6, 100, 0.5 );
510  timingsFullConvexityFast<4>( R4, 5, 6, 120, 0.5 );
511  outputResults( 4, R4, "timings-fcf-convexity-Z4.txt" );
512  }
513 
514  // P-convexity
515  srand( 0 );
516  if ( false )
517  {
518  std::vector< std::tuple< std::size_t, double, bool > > R2;
519  timingsPConvexityNonConvex<2>( R2, 50, 100 );
520  timingsPConvexityNonConvex<2>( R2, 50, 200 );
521  timingsPConvexityNonConvex<2>( R2, 50, 400 );
522  timingsPConvexityNonConvex<2>( R2, 50, 600 );
523  timingsPConvexityNonConvex<2>( R2, 50, 800 );
524  timingsPConvexityNonConvex<2>( R2, 50, 1200 );
525  timingsPConvexityNonConvex<2>( R2, 50, 2000 );
526  outputResults( 2, R2, "timings-p-convexity-ncvx-Z2.txt" );
527  }
528  if ( false )
529  {
530  std::vector< std::tuple< std::size_t, double, bool > > R3;
531  timingsPConvexityNonConvex<3>( R3, 50, 20 );
532  timingsPConvexityNonConvex<3>( R3, 50, 40 );
533  timingsPConvexityNonConvex<3>( R3, 50, 80 );
534  timingsPConvexityNonConvex<3>( R3, 50, 160 );
535  timingsPConvexityNonConvex<3>( R3, 50, 320 );
536  outputResults( 3, R3, "timings-p-convexity-ncvx-Z3.txt" );
537  }
538  if ( false )
539  {
540  std::vector< std::tuple< std::size_t, double, bool > > R4;
541  timingsPConvexityNonConvex<4>( R4, 50, 10 );
542  timingsPConvexityNonConvex<4>( R4, 50, 20 );
543  timingsPConvexityNonConvex<4>( R4, 50, 30 );
544  timingsPConvexityNonConvex<4>( R4, 40, 40 );
545  timingsPConvexityNonConvex<4>( R4, 20, 50 );
546  outputResults( 4, R4, "timings-p-convexity-ncvx-Z4.txt" );
547  }
548  if ( false )
549  {
550  std::vector< std::tuple< std::size_t, double, bool > > R2;
551  timingsFullConvexityNonConvex<2>( R2, 50, 100 );
552  timingsFullConvexityNonConvex<2>( R2, 50, 200 );
553  timingsFullConvexityNonConvex<2>( R2, 50, 400 );
554  timingsFullConvexityNonConvex<2>( R2, 50, 600 );
555  timingsFullConvexityNonConvex<2>( R2, 50, 800 );
556  timingsFullConvexityNonConvex<2>( R2, 50, 1200 );
557  timingsFullConvexityNonConvex<2>( R2, 50, 2000 );
558  outputResults( 2, R2, "timings-fc-convexity-ncvx-Z2.txt" );
559  }
560  if ( false )
561  {
562  std::vector< std::tuple< std::size_t, double, bool > > R3;
563  timingsFullConvexityNonConvex<3>( R3, 50, 20 );
564  timingsFullConvexityNonConvex<3>( R3, 50, 40 );
565  timingsFullConvexityNonConvex<3>( R3, 50, 80 );
566  timingsFullConvexityNonConvex<3>( R3, 40, 160 );
567  timingsFullConvexityNonConvex<3>( R3, 25, 320 );
568  outputResults( 3, R3, "timings-fc-convexity-ncvx-Z3.txt" );
569  }
570  if ( false )
571  {
572  std::vector< std::tuple< std::size_t, double, bool > > R4;
573  timingsFullConvexityNonConvex<4>( R4, 50, 10 );
574  timingsFullConvexityNonConvex<4>( R4, 50, 20 );
575  timingsFullConvexityNonConvex<4>( R4, 50, 30 );
576  timingsFullConvexityNonConvex<4>( R4, 40, 40 );
577  timingsFullConvexityNonConvex<4>( R4, 20, 50 );
578  outputResults( 4, R4, "timings-fc-convexity-ncvx-Z4.txt" );
579  }
580  if ( false )
581  {
582  std::vector< std::tuple< std::size_t, double, bool > > R2;
583  timingsFullConvexityFastNonConvex<2>( R2, 50, 100 );
584  timingsFullConvexityFastNonConvex<2>( R2, 50, 200 );
585  timingsFullConvexityFastNonConvex<2>( R2, 50, 400 );
586  timingsFullConvexityFastNonConvex<2>( R2, 50, 600 );
587  timingsFullConvexityFastNonConvex<2>( R2, 50, 800 );
588  timingsFullConvexityFastNonConvex<2>( R2, 50, 1200 );
589  timingsFullConvexityFastNonConvex<2>( R2, 50, 2000 );
590  outputResults( 2, R2, "timings-fcf-convexity-ncvx-Z2.txt" );
591  }
592  if ( false )
593  {
594  std::vector< std::tuple< std::size_t, double, bool > > R3;
595  timingsFullConvexityFastNonConvex<3>( R3, 50, 20 );
596  timingsFullConvexityFastNonConvex<3>( R3, 50, 40 );
597  timingsFullConvexityFastNonConvex<3>( R3, 50, 80 );
598  timingsFullConvexityFastNonConvex<3>( R3, 40, 160 );
599  timingsFullConvexityFastNonConvex<3>( R3, 25, 320 );
600  outputResults( 3, R3, "timings-fcf-convexity-ncvx-Z3.txt" );
601  }
602  if ( false )
603  {
604  std::vector< std::tuple< std::size_t, double, bool > > R4;
605  timingsFullConvexityFastNonConvex<4>( R4, 50, 10 );
606  timingsFullConvexityFastNonConvex<4>( R4, 50, 20 );
607  timingsFullConvexityFastNonConvex<4>( R4, 50, 30 );
608  timingsFullConvexityFastNonConvex<4>( R4, 40, 40 );
609  timingsFullConvexityFastNonConvex<4>( R4, 20, 50 );
610  outputResults( 4, R4, "timings-fcf-convexity-ncvx-Z4.txt" );
611  }
612 
613 
614  return 0;
615 }
void getPoints(std::vector< Point > &pts) const
bool isFullyConvexFast(const PointRange &X) const
LatticePolytope CvxH(const PointRange &X) const
bool isFullyConvex(const PointRange &X, bool convex0=false) const
PointRange envelope(const PointRange &Z, EnvelopeAlgorithm algo=EnvelopeAlgorithm::DIRECT) const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Aim: A class to check if digital sets are P-convex. The P-convexity is defined as follows: A digital ...
Definition: PConvexity.h:355
bool isPConvex(const std::vector< Point > &X) const
Definition: PConvexity.h:407
std::ostream & warning()
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Definition: Common.h:136
Trace trace
Definition: Common.h:153
int main(int argc, char *argv[])
void timingsFullConvexityNonConvex(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t range)
void timingsFullConvexity(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t nb_vertices, std::size_t range, double fconvexity_probability=0.5)
void outputResults(Dimension dim, const std::vector< std::tuple< std::size_t, double, bool > > &results, const std::string &fname)
void timingsPConvexityNonConvex(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t range)
void timingsFullConvexityFast(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t nb_vertices, std::size_t range, double fconvexity_probability=0.5)
void timingsPConvexity(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t nb_vertices, std::size_t range, double pconvexity_probability=0.5)
void timingsFullConvexityFastNonConvex(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t range)
double rand01()
MyPointD Point
Definition: testClone2.cpp:383
srand(0)
Domain domain
HyperRectDomain< Space > Domain
unsigned int dim(const Vector &z)