Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JCombinatorics.cc File Reference

Example program to test combinatorics of pairs of indices (class JTOOLS::JCombinatorics). More...

#include <string>
#include <iostream>
#include <iomanip>
#include "JTools/JCombinatorics.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test combinatorics of pairs of indices (class JTOOLS::JCombinatorics).

Author
mdejong

Definition in file JCombinatorics.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 15 of file JCombinatorics.cc.

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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define STATUS(A)
Definition: JMessage.hh:63
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
alias put_queue eval echo n
Definition: qlib.csh:19
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62