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