Jpp
18.2.1
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JTools
JPermutation.cc
Go to the documentation of this file.
1
2
#include <string>
3
#include <iostream>
4
#include <iomanip>
5
#include <vector>
6
#include <set>
7
#include <algorithm>
8
9
#include "
JTools/JPermutation.hh
"
10
#include "
JMath/JMathToolkit.hh
"
11
12
#include "
Jeep/JParser.hh
"
13
#include "
Jeep/JMessage.hh
"
14
15
16
/**
17
* \file
18
*
19
* Example program to test permutations (JTOOLS::next_permutation).
20
* \author mdejong
21
*/
22
int
main
(
int
argc,
char
**argv)
23
{
24
using namespace
std;
25
26
vector<int>
buffer;
27
unsigned
int
N
;
28
int
debug
;
29
30
try
{
31
32
JParser<>
zap(
"Example program to test permutations."
);
33
34
zap[
'i'
] =
make_field
(buffer);
35
zap[
'N'
] =
make_field
(
N
);
36
zap[
'd'
] =
make_field
(
debug
) = 1;
37
38
zap(argc, argv);
39
}
40
catch
(
const
exception &error) {
41
FATAL
(error.what() << endl);
42
}
43
44
45
using namespace
JPP;
46
47
48
if
(
N
> buffer.size()) {
49
FATAL
(
"Number of elements "
<<
N
<<
" > "
<< buffer.size() << endl);
50
}
51
52
sort(buffer.begin(), buffer.end(), less<int>());
53
54
vector<int>::iterator
p = buffer.begin();
55
56
advance
(p,
N
);
57
58
vector< set<int>
>
data
;
59
60
int
n
= 0;
61
62
do
{
63
64
++
n
;
65
66
DEBUG
(
'['
<< setw(3) <<
n
<<
']'
);
67
68
for
(
vector<int>::const_iterator
i
= buffer.begin();
i
!= p; ++
i
) {
69
DEBUG
(
' '
<< setw(3) << *
i
);
70
}
71
72
data
.push_back(
set<int>
());
73
74
for
(
vector<int>::const_iterator
i
= buffer.begin();
i
!= p; ++
i
) {
75
data
.rbegin()->insert(*
i
);
76
}
77
78
DEBUG
(
" |"
);
79
80
for
(
vector<int>::const_iterator
i
= p;
i
!= buffer.end(); ++
i
) {
81
DEBUG
(
' '
<< setw(3) << *
i
);
82
}
83
84
DEBUG
(endl);
85
86
}
while
(
next_permutation
(buffer.begin(), p, buffer.end(), less<int>()));
87
88
89
for
(
vector
<
set<int>
>::const_iterator p =
data
.begin(); p !=
data
.end(); ++p) {
90
for
(
vector
<
set<int>
>::const_iterator q = p; ++q !=
data
.end(); ) {
91
ASSERT
(*p != *q);
92
}
93
}
94
95
96
NOTICE
(
"number of permutations "
<<
n
<<
' '
<<
factorial
(buffer.size(),
N
) << endl);
97
98
ASSERT
(
n
==
factorial
(buffer.size(),
N
));
99
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1514
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
JMathToolkit.hh
Auxiliary methods for geometrical methods.
JMATH::factorial
long long int factorial(const long long int n)
Determine factorial.
Definition:
JMathToolkit.hh:42
std::vector< int >
JTOOLS::n
const int n
Definition:
JPolint.hh:786
i
then rm i
Definition:
JEvtReweightMupageParameterScan.sh:309
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition:
JMessage.hh:90
JPermutation.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1989
NOTICE
#define NOTICE(A)
Definition:
JMessage.hh:64
JMessage.hh
General purpose messaging.
JROOT::advance
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
Definition:
JROOT/JCounter.hh:35
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
N
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition:
JMuonPostfit.sh:40
JParser.hh
Utility class to parse command line options.
std::set< int >
JTOOLS::next_permutation
bool next_permutation(T __begin, T __last, T __end, JComparator_t compare, std::bidirectional_iterator_tag)
Implementation of method next_permutation for bidirectional iterators.
Definition:
JPermutation.hh:20
applications.data
tuple data
Definition:
applications.py:8
debug
int debug
debug level
Definition:
archive-put-wiki-detectors.sh:92
DEBUG
#define DEBUG(A)
Message macros.
Definition:
JMessage.hh:62
Generated by
1.8.5