Doxygen Generated Documentation of Ben-Jose Trainable SAT Solver Library
tak_mak.h
1 
2 
3 /*************************************************************
4 
5 ben-jose
6 
7 tak_mak.h
8 
9 ------------------------------------------------------------
10 
11 Adapted 2011 to c++ by
12 QUIROGA BELTRAN, Jose Luis.
13 Id (cedula): 79523732 de Bogota - Colombia.
14 See https://github.com/joseluisquiroga/ben-jose
15 
16 ------------------------------------------------------------
17 
18 Original:
19 
20 A C-program for MT19937, with initialization improved 2002/1/26.
21 Coded by Takuji Nishimura and Makoto Matsumoto.
22 
23 Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
24 All rights reserved.
25 
26 Classes and that implement the pseudo random number generator of
27 Makoto and Takuji.
28 
29 class for the tak_mak pseudo random number generator.
30 
31  tak_mak use:
32 
33  if(key_longs.size() == 1){
34  for_bytes.init_with_long(key_longs[0]);
35  } else {
36  for_bytes.init_with_array(
37  key_longs.get_c_array(),
38  key_longs.get_c_array_sz()
39  );
40  }
41 
42  op = tm_gen.gen_rand_int32();
43  idx1 = tm_gen.gen_rand_int32_ie(0, key_bits.size());
44  idx2 = tm_gen.gen_rand_int32_ie(0, op_bits.size());
45 
46 
47 --------------------------------------------------------------*/
48 
49 
50 #ifndef TAK_MAK_H
51 #define TAK_MAK_H
52 
53 #include <cstdio>
54 
55 #define TAK_MAK_INIT_LONG_1 19650218UL
56 #define TAK_MAK_INIT_LONG_2 5489UL
57 
58 /* Period parameters */
59 #define TAK_MAK_N 624
60 #define TAK_MAK_M 397
61 #define TAK_MAK_MATRIX_A 0x9908b0dfUL /* constant vector a */
62 #define TAK_MAK_UPPER_MASK 0x80000000UL /* most significant w-r bits */
63 #define TAK_MAK_LOWER_MASK 0x7fffffffUL /* least significant r bits */
64 
65 inline
66 long to_interval(long val, long min, long max){
67  long diff = 0, resp = 0;
68  diff = max - min;
69  if(diff <= 0){
70  return min;
71  }
72  long rr = (val % diff);
73  if(rr < 0){ rr = -rr; }
74  resp = min + rr;
75  return resp;
76 }
77 
78 class tak_mak {
79 private:
80  unsigned long mt[TAK_MAK_N]; /* the array for the state vector */
81  int mti; /* mti==TAK_MAK_N+1 means mt[TAK_MAK_N] is not initialized */
82 
83 public:
84  tak_mak(unsigned long ini_val = 0){
85  init_tak_mak();
86  if(ini_val == 0){
87  ini_val = TAK_MAK_INIT_LONG_1;
88  }
89  init_with_long(ini_val);
90  }
91 
92  tak_mak(const unsigned long* init_key, int key_length){
93  init_tak_mak();
94  init_with_array(init_key, key_length);
95  }
96 
97  void init_tak_mak(){
98  mti=TAK_MAK_N+1;
99  }
100 
101  void init_with_long(unsigned long s);
102  void init_with_array(const unsigned long* init_key, int key_length);
103 
104  unsigned long gen_rand_int32(void);
105 
106  double gen_rand_i0_i1(void);
107  double gen_rand_i0_e1(void);
108  double gen_rand_e0_e1(void);
109 
110  long gen_rand_int32_ie(long min, long max){
111  return to_interval(gen_rand_int32(), min, max);
112  }
113 
114 };
115 
116 
117 #endif // TAK_MAK_H
118 
119