libboloq
A library to replesent binary functions using Binary Decision Diagram.
 全て クラス 名前空間 関数 型定義 ページ
combination.h
1 #pragma once
2 
3 namespace boloq {
4 
8 template<class T>
10 private:
11  using table_type = T;
13  friend std::hash<self_type>;
14 
15 public:
19  using node_ptr = typename table_type::node_ptr;
20 
26  using label_type = typename table_type::node_type::label_type;
27 
28 private:
29  node_ptr _root;
30 
31  explicit basic_combination(const node_ptr& r) :
32  _root(r)
33  {}
34 
35  static table_type& table() {
36  static table_type instance;
37  return instance;
38  }
39 
40  template<class V, typename R, typename ...Args>
41  R visit_result(const Args& ...args) const {
42  V v(args...);
43  this->accept(v);
44  return v.result();
45  }
46 
47 public:
48 
49  basic_combination() : _root(nullptr) {}
50 
54  explicit basic_combination(const label_type& _label) :
55  _root(table().new_var(_label))
56  {}
57 
61  static const self_type one() {
62  return self_type(table().one());
63  }
64 
68  static const self_type zero() {
69  return self_type(table().zero());
70  }
71 
76  _root = table().apply_change(_root, v);
77  return *this;
78  }
79 
84  return self_type(table().apply_change(_root, v));
85  }
86 
92  bool operator==(const self_type& o) const {
93  return _root->index() == o._root->index();
94  }
95 
101  bool operator!=(const self_type& o) const {
102  return _root->index() != o._root->index();
103  }
104 
108  self_type operator+(const self_type& o) const {
109  return self_type(table().apply_union(_root, o._root));
110  }
111 
116  _root = table().apply_union(_root, o.root);
117  return *this;
118  }
119 
123  self_type operator-(const self_type& o) const {
124  return self_type(table().apply_subtract(_root, o._root));
125  }
126 
131  _root = table().apply_subtract(_root, o.root);
132  return *this;
133  }
134 
138  self_type operator&(const self_type& o) const {
139  return self_type(table().apply_intersection(_root, o._root));
140  }
141 
146  _root = table().apply_intersection(_root, o._root);
147  return *this;
148  }
149 
155  template<class V>
156  void accept(V& visitor) const {
157  _root->accept(visitor);
158  }
159 
163  template<class AssignT>
164  bool contain(const AssignT& assign) const {
165  return visit_result<contain_visitor<self_type, AssignT>, bool>(assign);
166  }
167 
168 };
169 
174 
175 }
176 
177 namespace std {
178 
179 template<class T>
180 struct hash<boloq::basic_combination<T>> {
181  std::hash<typename boloq::basic_combination<T>::node_ptr> hash_fn;
182  size_t operator()(const boloq::basic_combination<T>& bf) const {
183  return hash_fn(bf._root);
184  }
185 };
186 
187 }
void accept(V &visitor) const
visitorを受理します
Definition: combination.h:156
self_type & operator+=(const self_type &o)
union を適用します
Definition: combination.h:115
basic_combination(const label_type &_label)
コンストラクタ
Definition: combination.h:54
boloq の名前空間
Definition: boolean_function.h:3
static const self_type one()
0 定節点
Definition: combination.h:61
Definition: boolean_function.h:215
self_type operator-(const self_type &o) const
subtract を行った結果を返します
Definition: combination.h:123
bool operator!=(const self_type &o) const
違う組み合わせ集合を表現しているか比較します
Definition: combination.h:101
self_type & operator&=(const self_type &o)
intersection を適用します
Definition: combination.h:145
self_type & operator-=(const self_type &o)
subtract を適用します
Definition: combination.h:130
typename table_type::node_ptr node_ptr
実際に操作されるノードの型
Definition: combination.h:19
self_type operator+(const self_type &o) const
union を行った結果を返します
Definition: combination.h:108
static const self_type zero()
1 定節点
Definition: combination.h:68
self_type operator&(const self_type &o) const
intersection の結果を返します
Definition: combination.h:138
bool operator==(const self_type &o) const
同じ組み合わせ集合を表現しているか比較します
Definition: combination.h:92
bool contain(const AssignT &assign) const
組み合わせ集合を評価します
Definition: combination.h:164
self_type & change(const label_type &v)
特定のアイテムの存在を反転させます
Definition: combination.h:75
self_type changed(const label_type &v)
特定のアイテムの存在を反転させた結果を返します
Definition: combination.h:83
typename table_type::node_type::label_type label_type
ラベルの型を表します
Definition: combination.h:26
二分決定図を操作する基本的なクラスです
Definition: combination.h:9