Debian Codegraph @

src/include/lowdiscrepancy.hpp

raw symbols SCIP
1 #pragma once
2
3 #include <unistd.h>
4
5 #include <chrono>
6 #include <cmath>
7 #include <iostream>
8 #include <random>
9 #include <thread>
10
11 /** generator for low-discrepancy sequences **/
12
13 class LowDiscrepancy {
14 private:
15 uint64_t _next;
16
17 public:
18 LowDiscrepancy(uint64_t seed) {
19 std::mt19937_64 rng(seed);
20 rng(); // consume one RNG
21 // Initialize the sequence with a value that's in the middle two quartiles.
22 while ((_next < UINT64_MAX / 4) || (_next > UINT64_MAX - UINT64_MAX / 4)) {
23 _next = rng(); // / (float) rng.max();
24 }
25 }
26
27 static inline constexpr uint64_t min() { return 0; }
28 static inline constexpr uint64_t max() { return UINT64_MAX; }
29
30 private:
31 static inline constexpr auto next() {
32 return (
33 uint64_t)((double)UINT64_MAX *
34 0.6180339887498949025257388711906969547271728515625L); // 1 -
35 // golden
36 // ratio
37 }
38
39 public:
40 inline auto operator()() {
41 auto prev = _next;
42 _next = _next + next();
43 #if 0
44 if (_next > 1.0) {
45 _next = _next - 1.0;
46 }
47 #endif
48 return prev;
49 }
50
51 void discard() { (*this)(); }
52 };