DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testStandardDSLQ0-smartDSS-benchmark.cpp
1 
30 
31 #include <cstdlib>
32 #include <iostream>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/kernel/CPointPredicate.h"
35 #include "DGtal/arithmetic/IntegerComputer.h"
36 #include "DGtal/arithmetic/SternBrocot.h"
37 #include "DGtal/arithmetic/Pattern.h"
38 #include "DGtal/arithmetic/StandardDSLQ0.h"
40 
41 using namespace std;
42 using namespace DGtal;
43 
45 // Functions for testing class SternBrocot.
47 
48 template <typename DSL>
49 bool checkSubStandardDSLQ0( const DSL & D,
50  const typename DSL::Point & A,
51  const typename DSL::Point & B )
52 {
53  typedef typename DSL::Fraction Fraction;
54  typedef typename DSL::Integer Integer;
55  typedef typename DSL::Quotient Quotient;
56  typedef typename DSL::Point Point;
57  typedef typename DSL::ConstIterator ConstIterator;
58  typedef typename DSL::Point2I Point2I;
59  typedef typename DSL::Vector2I Vector2I;
60 
61  DSL S = D.smartDSS( A, B );
62  std::cout << D.a() << " " << D.b() << " " << D.mu() << " "
63  << S.a() << " " << S.b() << " " << S.mu() << " "
64  << A[0] << " " << A[1] << " " << B[0] << " " << B[1]
65  << std::endl;
66  return true;
67 }
68 
69 template <typename Fraction>
70 bool testSubStandardDSLQ0( unsigned int nbtries,
71  typename Fraction::Integer moda,
72  typename Fraction::Integer modb,
73  typename Fraction::Integer modx )
74 {
75  typedef StandardDSLQ0<Fraction> DSL;
76  typedef typename Fraction::Integer Integer;
77  typedef typename Fraction::Quotient Quotient;
78  typedef typename DSL::Point Point;
79  typedef typename DSL::ConstIterator ConstIterator;
80  typedef typename DSL::Point2I Point2I;
81  typedef typename DSL::Vector2I Vector2I;
83 
84  std::cout << "# a b mu a1 b1 mu1 Ax Ay Bx By" << std::endl;
85  for ( unsigned int i = 0; i < nbtries; ++i )
86  {
87  Integer a( random() % moda + 1 );
88  Integer b( random() % modb + 1 );
89  if ( ic.gcd( a, b ) == 1 )
90  {
91  for ( Integer mu = 0; mu < 5; ++mu )
92  {
93  DSL D( a, b, random() % (moda+modb) );
94  for ( Integer x = 0; x < 10; ++x )
95  {
96  Integer x1 = random() % modx;
97  Integer x2 = x1 + 1 + ( random() % modx );
98  Point A = D.lowestY( x1 );
99  Point B = D.lowestY( x2 );
100  checkSubStandardDSLQ0<DSL>( D, A, B );
101  }
102  }
103  }
104  }
105  return true;
106 }
107 
109 // Standard services - public :
110 
111 int main( int argc, char** argv)
112 {
114  typedef SB::Fraction Fraction;
115  typedef Fraction::Integer Integer;
116  unsigned int nbtries = ( argc > 1 ) ? atoi( argv[ 1 ] ) : 10000;
117  Integer moda = ( argc > 2 ) ? atoll( argv[ 2 ] ) : 12000;
118  Integer modb = ( argc > 3 ) ? atoll( argv[ 3 ] ) : 12000;
119  Integer modx = ( argc > 4 ) ? atoll( argv[ 4 ] ) : 1000;
120  testSubStandardDSLQ0<Fraction>( nbtries, moda, modb, modx );
121  return true;
122 }
123 // //