Empirical
SolveState.h
Go to the documentation of this file.
1 
12 #ifndef EMP_SOLVE_STATE_H
13 #define EMP_SOLVE_STATE_H
14 
15 #include "../base/assert.h"
16 
17 #include "BitVector.h"
18 
19 namespace emp {
20 
26 
27  class SolveState {
28  private:
29  BitVector in_items;
30  BitVector unk_items;
31 
32  public:
33  SolveState(size_t state_size=0) : in_items(state_size), unk_items(state_size) {
34  unk_items.SetAll();
35  }
36  SolveState(const SolveState & in) : in_items(in.in_items), unk_items(in.unk_items) { ; }
37  ~SolveState() { ; }
38 
41  in_items = in.in_items;
42  unk_items = in.unk_items;
43  return *this;
44  }
45 
47  size_t GetSize() const { return in_items.GetSize(); }
48 
51  bool IsIn(size_t id) const { return in_items[id]; }
52 
55  bool IsUnk(size_t id) const { return unk_items[id]; }
56 
59  bool IsOut(size_t id) const { return !(IsIn(id) | IsUnk(id)); }
60 
62  bool IsFinal() const { return unk_items.None(); }
63 
65  size_t CountIn() const { return in_items.CountOnes(); }
66 
68  size_t CountUnk() const { return unk_items.CountOnes(); }
69 
71  size_t CountOut() const { return in_items.GetSize() - CountIn() - CountUnk(); }
72 
74  const BitVector & GetInVector() const { return in_items; }
75 
77  const BitVector & GetUnkVector() const { return unk_items; }
78 
80  BitVector GetOutVector() const { return ~in_items & ~unk_items; }
81 
83  int GetNextUnk(size_t prev_unk) const {
84  return unk_items.FindBit(prev_unk+1);
85  }
86 
88  void Include(size_t id) {
89  emp_assert(id >= 0 && id < in_items.size());
90  unk_items.Set(id, false);
91  in_items.Set(id, true);
92  }
93 
95  void Exclude(size_t id) {
96  emp_assert(id >= 0 && id < in_items.size());
97  unk_items.Set(id, false);
98  }
99 
102  void ForceExclude(size_t id) {
103  unk_items.Set(id, false);
104  in_items.Set(id, false);
105  }
106 
108  void IncludeSet(const BitVector & inc_set) {
109  emp_assert(inc_set.GetSize() == in_items.GetSize());
110  in_items |= inc_set;
111  unk_items &= ~inc_set;
112  }
113 
115  void ExcludeSet(const BitVector & inc_set) {
116  emp_assert(inc_set.GetSize() == in_items.GetSize());
117  unk_items &= ~inc_set;
118  }
119  };
120 
121 }
122 
123 #endif
void SetAll()
Set all bits to 1.
Definition: BitVector.h:484
size_t size() const
Function to allow drop-in replacement with std::vector<bool>.
Definition: BitVector.h:765
size_t CountOnes() const
Count the number of ones in the BitVector.
Definition: BitVector.h:544
bool IsUnk(size_t id) const
Definition: SolveState.h:55
~SolveState()
Definition: SolveState.h:37
A drop-in replacement for std::vector<bool>, but with extra bitwise logic features.
Definition: BitVector.h:39
A drop-in replacement for std::vector<bool>, with additional bitwise logic features.
void IncludeSet(const BitVector &inc_set)
Include ALL of the items specified in the provided BitVector.
Definition: SolveState.h:108
bool None() const
Return true if NO bits are set to 1, otherwise return false.
Definition: BitVector.h:463
int FindBit() const
Return the position of the first one; return -1 if no ones in vector.
Definition: BitVector.h:547
size_t CountIn() const
How many items have been included for sure?
Definition: SolveState.h:65
int GetNextUnk(size_t prev_unk) const
Get the ID of the next unknown item.
Definition: SolveState.h:83
size_t CountOut() const
How many items have been excluded for sure.
Definition: SolveState.h:71
void Exclude(size_t id)
Mark a specific item as to be excluded.
Definition: SolveState.h:95
SolveState & operator=(const SolveState &in)
Set this SolveState to be identical to another.
Definition: SolveState.h:40
bool IsOut(size_t id) const
Definition: SolveState.h:59
SolveState(size_t state_size=0)
Definition: SolveState.h:33
const BitVector & GetInVector() const
Get the BitVector associated with which items have been included for sure.
Definition: SolveState.h:74
bool IsFinal() const
Test if all items have been decided upon (none are still in the "unknown" state)
Definition: SolveState.h:62
void Include(size_t id)
Mark a specific item as to be included.
Definition: SolveState.h:88
SolveState(const SolveState &in)
Definition: SolveState.h:36
void ExcludeSet(const BitVector &inc_set)
Exclude ALL of the items specified in the provided BitVector.
Definition: SolveState.h:115
size_t GetSize() const
How many items are being considered in the current SolveState?
Definition: SolveState.h:47
If we are in emscripten, make sure to include the header.
Definition: array.h:37
bool IsIn(size_t id) const
Definition: SolveState.h:51
size_t CountUnk() const
How many items have yet to be decided upon (are "unknown")
Definition: SolveState.h:68
#define emp_assert(...)
Definition: assert.h:199
Definition: SolveState.h:27
void ForceExclude(size_t id)
Definition: SolveState.h:102
BitVector GetOutVector() const
Get the BitVector associated with which iterm have been excluded for sure.
Definition: SolveState.h:80
void Set(size_t index, bool value=true)
Update the bit value at the specified index.
Definition: BitVector.h:379
const BitVector & GetUnkVector() const
Get the BitVector associated with which items have yet to be decided upon.
Definition: SolveState.h:77
size_t GetSize() const
How many bits do we currently have?
Definition: BitVector.h:368