DGtal 1.3.0
Loading...
Searching...
No Matches
testStandardDSLQ0-reversedSmartDSS-benchmark.cpp
Go to the documentation of this file.
1
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
41using namespace std;
42using namespace DGtal;
43
45// Functions for testing class SternBrocot.
47
48template <typename DSL>
49bool checkSubStandardDSLQ0( const DSL & D,
50 const typename DSL::Point & A,
51 const typename DSL::Point & B )
52{
53 DSL S = D.reversedSmartDSS( A, B );
54 // std::cout << D.a() << " " << D.b() << " " << D.mu() << " "
55 // << S.a() << " " << S.b() << " " << S.mu() << " "
56 // << A[0] << " " << A[1] << " " << B[0] << " " << B[1]
57 // << std::endl;
58 return true;
59}
60
61template <typename Fraction>
62bool testSubStandardDSLQ0( unsigned int nbtries,
63 typename Fraction::Integer moda,
64 typename Fraction::Integer modb,
65 typename Fraction::Integer modx )
66{
67 typedef StandardDSLQ0<Fraction> DSL;
68 typedef typename Fraction::Integer Integer;
69 typedef typename DSL::Point Point;
71
72
73
74 std::cout << "# a b mu a1 b1 mu1 Ax Ay Bx By" << std::endl;
75
76
77 clock_t timeBegin, timeEnd;
78 timeBegin = clock();
79
80
81 for ( unsigned int i = 0; i < nbtries; ++i )
82 {
83 //Integer a( rand() % moda + 1 );
84 //Integer b( rand() % modb + 1 );
85
86 Integer b( rand() % modb + 1 );
87 Integer a( rand() % b + 1 );
88
89
90 if ( ic.gcd( a, b ) == 1 )
91 {
92 for ( int j = 0; j < 5; ++j )
93 {
94 Integer mu = rand() % (moda+modb);
95 DSL D( a, b, mu );
96 for ( Integer x = 0; x < 10; ++x )
97 {
98 Integer x1 = rand() % modx;
99 Integer x2 = x1 + 1 + ( rand() % modx );
100 Point A = D.lowestY( x1 );
101 Point B = D.lowestY( x2 );
102 checkSubStandardDSLQ0<DSL>( D, A, B );
103 }
104 }
105 }
106 }
107
108 timeEnd = clock();
109 long double CPUTime;
110 CPUTime = ((double)timeEnd-(double)timeBegin)/((double)CLOCKS_PER_SEC);
111
112 std::cout << " " << (long double) CPUTime/(nbtries*5*10);
113
114
115 return true;
116}
117
118
120// Standard services - public :
121
122int main( int argc, char** argv)
123{
125 typedef SB::Fraction Fraction;
126 typedef Fraction::Integer Integer;
127 unsigned int nbtries = ( argc > 1 ) ? atoi( argv[ 1 ] ) : 10000;
128 Integer moda = ( argc > 2 ) ? atoll( argv[ 2 ] ) : 1000000000000;
129 Integer modb = ( argc > 3 ) ? atoll( argv[ 3 ] ) : 1000000000000;
130 Integer modx = ( argc > 4 ) ? atoll( argv[ 4 ] ) : 1000;
131 testSubStandardDSLQ0<Fraction>( nbtries, moda, modb, modx );
132 return true;
133}
134// //
Aim: This class gathers several types and methods to make computation with integers.
Integer gcd(IntegerParamType a, IntegerParamType b) const
Aim: Represents a digital straight line with slope in the first quadrant (Q0: x >= 0,...
Definition: StandardDSLQ0.h:80
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Definition: SternBrocot.h:78
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383
bool testSubStandardDSLQ0()
bool checkSubStandardDSLQ0(const DSL &D, const typename DSL::Point &A, const typename DSL::Point &B)