Jpp
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JTools
JCombinatorics.cc
Go to the documentation of this file.
1
#include <string>
2
#include <iostream>
3
#include <iomanip>
4
5
#include "
JTools/JCombinatorics.hh
"
6
#include "
Jeep/JParser.hh
"
7
#include "
Jeep/JMessage.hh
"
8
9
10
/**
11
* \file
12
* Example program to test combinatorics of pairs of indices (class JTOOLS::JCombinatorics).
13
* \author mdejong
14
*/
15
int
main
(
int
argc,
char
**argv)
16
{
17
using namespace
std;
18
19
int
numberOfElements;
20
int
debug
;
21
22
try
{
23
24
JParser<>
zap(
"Example program to test combinatorics of pairs of indices."
);
25
26
zap[
'n'
] =
make_field
(numberOfElements);
27
zap[
'd'
] =
make_field
(
debug
) = 1;
28
29
zap(argc, argv);
30
}
31
catch
(
const
exception &error) {
32
FATAL
(error.what() << endl);
33
}
34
35
36
using namespace
JPP;
37
38
if
(numberOfElements <= 0) {
39
FATAL
(
"Number of elements "
<< numberOfElements <<
" <= 0"
<< endl);
40
}
41
42
43
JCombinatorics combinatorics(numberOfElements);
44
45
int
n
= 0;
46
47
for
(
int
i = 0; i != (int) combinatorics.getNumberOfPairs(); ++i) {
48
49
STATUS
(
"event: "
<< setw(8) << i <<
'\r'
);
DEBUG
(endl);
50
51
JCombinatorics::pair_type
pair
= combinatorics.getPair(i);
52
53
if
(i != combinatorics.getIndex(pair.first, pair.second)) {
54
55
++
n
;
56
57
ERROR
(endl <<
' '
<<
58
setw(3) << pair.first <<
' '
<<
59
setw(3) << pair.second <<
' '
<<
60
setw(4) << combinatorics.getIndex(pair.first, pair.second) << endl);
61
}
62
}
63
DEBUG
(endl);
64
65
NOTICE
(
"Number of elements "
<< setw(8) << right << numberOfElements << endl);
66
NOTICE
(
"Number of pairs "
<< setw(8) << right << combinatorics.getNumberOfPairs() << endl);
67
NOTICE
(
"Number of errors "
<< setw(8) << right <<
n
<< endl);
68
69
ASSERT
(
n
== 0);
70
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1493
std::pair
Definition:
JSTDTypes.hh:15
STATUS
#define STATUS(A)
Definition:
JMessage.hh:63
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition:
JMessage.hh:90
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1954
NOTICE
#define NOTICE(A)
Definition:
JMessage.hh:64
ERROR
#define ERROR(A)
Definition:
JMessage.hh:66
debug
int debug
debug level
Definition:
JSirene.cc:61
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
n
alias put_queue eval echo n
Definition:
qlib.csh:19
DEBUG
#define DEBUG(A)
Message macros.
Definition:
JMessage.hh:62
JCombinatorics.hh
main
int main(int argc, char *argv[])
Definition:
Main.cpp:15
Generated by
1.8.5