-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonotoneBooleanFunction.h
63 lines (40 loc) · 1.41 KB
/
MonotoneBooleanFunction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <bitset>
#include <array>
#include "ShortList.h"
extern std::array<int, (1 << DIMENSION)> bit_count_lookup;
class MonotoneBooleanFunction
{
private:
int weight = 0;
bool functionArray[1 << DIMENSION]{0}; //The function (value of the function for each input)
int up_count[1 << DIMENSION]{0};
int down_count[1 << DIMENSION]{0};
int layerBitsSet[DIMENSION + 1]{0}; // Number of bits set in each layer
static int bit_count_lookup[(1 << DIMENSION)];
static int max_down[(1 << DIMENSION)];
static int layerSize[DIMENSION + 1];
std::mt19937 &rng;
ShortList min_cuts;
bool checkMinCut(int index) const;
void updateMinCuts();
void updateMinCutsFast(int index, bool new_value);
public:
MonotoneBooleanFunction(std::mt19937 &r);
MonotoneBooleanFunction(const MonotoneBooleanFunction &) = delete;
MonotoneBooleanFunction &operator=(const MonotoneBooleanFunction &) = delete;
bool getFunctionValue(int index) const;
void setFunctionValue(int index, bool value);
int getWeight() const;
void flip(int index);
void flipRandom();
void step();
int getRandomMinCut() const;
bool is_mincut(int index);
void update_counts(int index, bool new_value);
void printMinCuts() const;
int minCutSize() const;
int lastEmptyLayer() const;
int firstFullLayer() const;
ShortList getMinCNF();
};