6 #include <gsl/gsl_permutation.h> 29 ostream& operator <<(ostream& os, const vector<Int_t>&
v)
32 for ( vector<Int_t>::const_iterator i =
v.begin(); i !=
v.end() ; ++i) {
43 for (
Int_t i = 0; i <
n; i++) {
46 sort(array.begin(), array.end());
53 vector<Int_t> original(n);
62 copy(original.begin(), original.end(), vM.begin());
63 copy(original.begin(), original.end(), vS.begin());
67 std::next_permutation(&vS[0], &vS[n]);
69 equals &=
equal(vM.begin(), vM.end(), vS.begin());
73 std::next_permutation(vS.begin(), vS.end());
81 vector<Int_t> original(n);
90 for (
int j = 0; j <
npass; ++j) {
91 copy(original.begin(), original.end(), v.begin());
96 cout <<
"TMath::Permute time :\t " << t.
RealTime();
100 for (
int j = 0; j <
npass; ++j) {
101 copy(original.begin(), original.end(), v.begin());
102 while ( std::next_permutation(&v[0], &v[n]) ) {}
106 cout <<
" std::next_permutation time :\t " << t.
RealTime();
113 gsl_permutation *original = gsl_permutation_alloc(n);
114 gsl_permutation *p = gsl_permutation_alloc(n);
116 gsl_permutation_init(original);
119 for (
int j = 0; j <
npass; ++j) {
120 gsl_permutation_memcpy(p, original);
129 cout <<
" gsl_permutation_next time :\t " << t.
RealTime();
131 gsl_permutation_free(p);
132 gsl_permutation_free(original);
147 cout <<
"checkPermute()...." 148 << (equals?
"OK" :
"FAILED")
151 status += (equals ==
false);
166 TCanvas*
c1 =
new TCanvas(
"c1",
"Comparision of Permutation Time", 600, 400);
180 gS->
SetTitle(
"std::next_permutation()");
186 gG->
SetTitle(
"gsl_permutation_next()");
190 legend->
AddEntry(gM,
"TMath::Permute()");
191 legend->
AddEntry(gS,
"std::next_permutation()");
192 legend->
AddEntry(gG,
"gsl_permutation_next()");
202 cout <<
"Test Done!" << endl;
207 int main(
int argc,
char **argv)
212 for (
Int_t i=1 ; i<argc ; i++) {
213 std::string arg = argv[i] ;
222 cerr <<
"Usage: " << argv[0] <<
" [-g] [-v]\n";
224 cerr <<
" -g : graphics mode\n";
225 cerr <<
" -v : verbose mode";
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
This class displays a legend box (TPaveText) containing several legend entries.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
bool equal(double d1, double d2, double stol=10000)
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
virtual void SetTitle(const char *title="")
Set graph title.
int equals(Double_t n1, Double_t n2, double ERRORLIMIT=1.E-10)
void permuteTime(const int n, double *tTMath, double *tStd)
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
void Stop()
Stop the stopwatch.
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
virtual UInt_t Integer(UInt_t imax)
Returns a random integer on [ 0, imax-1 ].
virtual void SetLineColor(Color_t lcolor)
Set the line color.
void initArray(Int_t n, vector< Int_t > &array)
virtual void Draw(Option_t *option="")
Draw this histogram with options.
tomato 2-D histogram with a float per channel (see TH1 documentation)}
Bool_t Permute(Int_t n, Int_t *a)
Simple recursive algorithm to find the permutations of n natural numbers, not necessarily all distinc...
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
void testGSLPermute(Int_t n, double *tGSL)
A Graph is a graphics object made of two arrays X and Y with npoints each.
int main(int argc, char **argv)
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.