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