Adiar  2.1.0
An External Memory Decision Diagram Library
exec_policy.h
1 #ifndef ADIAR_EXEC_POLICY_H
2 #define ADIAR_EXEC_POLICY_H
3 
4 #include <algorithm>
5 #include <limits>
6 
7 #include <adiar/type_traits.h>
8 
9 namespace adiar
10 {
15 
35  {
36  public:
54  enum class access : char
55  {
57  Auto,
62  };
63 
78  enum class memory : char
79  {
81  Auto,
83  Internal,
85  External
86  };
87 
97  class quantify
98  {
99  public:
103  enum algorithm : char
104  {
108  Singleton
109  };
110 
122  {
123  private:
124  static constexpr float min_val = 0.0f;
125 
126  public:
128  static constexpr transposition_growth
129  min()
130  {
131  return min_val;
132  }
133 
135  static constexpr transposition_growth
136  max()
137  {
138  return std::numeric_limits<float>::max();
139  }
140 
141  private:
142  float _value;
143 
145  static constexpr float
146  from_float(float f)
147  {
148  // Truncate `f` to be in the interval [0.0f, ...)
149  return f < min_val ? min_val : f;
150  }
151 
152  public:
153  constexpr transposition_growth()
154  : _value(1.5f)
155  {}
156 
158  constexpr transposition_growth(float value)
159  : _value(from_float(value))
160  {}
161 
163  operator float() const
164  {
165  return this->_value;
166  }
167  };
168 
173  {
174  public:
176  static constexpr transposition_max
177  min()
178  {
179  return std::numeric_limits<unsigned char>::min();
180  }
181 
184  static constexpr transposition_max
185  max()
186  {
187  return std::numeric_limits<unsigned char>::max();
188  }
189 
190  private:
191  unsigned char _value;
192 
193  public:
195  constexpr transposition_max()
196  : _value(std::numeric_limits<unsigned char>::min())
197  {}
198 
200  constexpr transposition_max(unsigned char value)
201  : _value(value)
202  {}
203 
205  operator unsigned char() const
206  {
207  return this->_value;
208  }
209  };
210  };
211 
212  private:
213  // TODO: Merge all enums into a single 64 bit integer to safe on space?
214 
218  access _access = access::Auto;
219 
223  memory _memory = memory::Auto;
224 
228  quantify::algorithm _quantify__algorithm = quantify::Nested;
229 
233  quantify::transposition_growth _quantify__transposition_growth /*default*/;
234 
238  quantify::transposition_max _quantify__transposition_max /*default*/;
239  ;
240 
241  public:
245  exec_policy() = default;
246 
250  exec_policy(const exec_policy&) = default;
251 
255  exec_policy(exec_policy&&) = default;
256 
260  exec_policy(const access& am)
261  : _access(am)
262  {}
263 
267  exec_policy(const memory& mm)
268  : _memory(mm)
269  {}
270 
275  : _quantify__algorithm(qa)
276  {}
277 
282  : _quantify__transposition_growth(tg)
283  {}
284 
289  : _quantify__transposition_max(tm)
290  {}
291 
292  // TODO: constructor with defaults for a specific 'version number'?
293 
294  public:
298  exec_policy&
299  operator=(const exec_policy&) = default;
300 
304  exec_policy&
305  operator=(exec_policy&&) = default;
306 
307  public:
311  template <typename T>
312  const T&
313  get() const;
314 
315  public:
319  bool
320  operator==(const exec_policy& ep) const
321  {
322  // Order based from the most generic to the most specific setting.
323  return this->_memory == ep._memory && this->_access == ep._access
324  && this->_quantify__algorithm == ep._quantify__algorithm
325  && this->_quantify__transposition_growth == ep._quantify__transposition_growth
326  && this->_quantify__transposition_max == ep._quantify__transposition_max;
327  }
328 
332  bool
333  operator!=(const exec_policy& ep) const
334  {
335  return !(*this == ep);
336  }
337 
338  public:
342  exec_policy&
343  set(const access& am)
344  {
345  this->_access = am;
346  return *this;
347  }
348 
353  operator&(const access& am) const
354  {
355  exec_policy ep = *this;
356  return ep.set(am);
357  }
358 
362  exec_policy&
363  set(const memory& mm)
364  {
365  this->_memory = mm;
366  return *this;
367  }
368 
373  operator&(const memory& mm) const
374  {
375  exec_policy ep = *this;
376  return ep.set(mm);
377  }
378 
382  exec_policy&
384  {
385  this->_quantify__algorithm = qa;
386  return *this;
387  }
388 
394  {
395  exec_policy ep = *this;
396  return ep.set(qa);
397  }
398 
402  exec_policy&
404  {
405  this->_quantify__transposition_growth = tg;
406  return *this;
407  }
408 
414  {
415  exec_policy ep = *this;
416  return ep.set(tg);
417  }
418 
422  exec_policy&
424  {
425  this->_quantify__transposition_max = tm;
426  return *this;
427  }
428 
434  {
435  exec_policy ep = *this;
436  return ep.set(tm);
437  }
438  };
439 
443  template <>
444  inline const exec_policy::access&
445  exec_policy::get<exec_policy::access>() const
446  {
447  return this->_access;
448  }
449 
453  template <>
454  inline const exec_policy::memory&
455  exec_policy::get<exec_policy::memory>() const
456  {
457  return this->_memory;
458  }
459 
463  template <>
465  exec_policy::get<exec_policy::quantify::algorithm>() const
466  {
467  return this->_quantify__algorithm;
468  }
469 
473  template <>
475  exec_policy::get<exec_policy::quantify::transposition_growth>() const
476  {
477  return this->_quantify__transposition_growth;
478  }
479 
483  template <>
485  exec_policy::get<exec_policy::quantify::transposition_max>() const
486  {
487  return this->_quantify__transposition_max;
488  }
489 
492 
494 
498  template <
499  typename A,
500  typename B,
501  typename = enable_if<needs_conversion<A, exec_policy> && needs_conversion<B, exec_policy>>>
502  exec_policy
503  operator&(const A& a, const B& b)
504  {
505  return exec_policy(a) & b;
506  }
507 
509 }
510 
511 #endif // ADIAR_EXEC_POLICY_H
Multiplicative value for the maximal growth of a BDD may during repeated transpostion before switchin...
Definition: exec_policy.h:122
constexpr transposition_growth(float value)
Wrap a float.
Definition: exec_policy.h:158
static constexpr transposition_growth max()
Maximal value.
Definition: exec_policy.h:136
static constexpr transposition_growth min()
Minimal value.
Definition: exec_policy.h:129
Maximum number of repeated transpositions before switching to nested sweeping.
Definition: exec_policy.h:173
constexpr transposition_max()
Default value construction.
Definition: exec_policy.h:195
constexpr transposition_max(unsigned char value)
Wrap an unsigned char
Definition: exec_policy.h:200
static constexpr transposition_max max()
Maximal value (equivalent to using the built-in heuristics based on the graph's meta information).
Definition: exec_policy.h:185
static constexpr transposition_max min()
Minimal value (equivalent to disabling repeated transpositions).
Definition: exec_policy.h:177
Strategies and settings for Adiar to use in quantify/project algorithms.
Definition: exec_policy.h:98
algorithm
to use for quantification and projection.
Definition: exec_policy.h:104
@ Nested
Definition: exec_policy.h:106
@ Singleton
Definition: exec_policy.h:108
Settings to dictate the execution of Adiar's algorithms.
Definition: exec_policy.h:35
exec_policy & set(const quantify::transposition_growth &tg)
Set the quantify strategy.
Definition: exec_policy.h:403
exec_policy(const quantify::transposition_growth &tg)
Conversion construction from quantify transposition growth value.
Definition: exec_policy.h:281
exec_policy operator&(const quantify::transposition_growth &tg) const
Create a copy with the quantify algorithm changed.
Definition: exec_policy.h:413
memory
Whether Adiar should exclusively use internal or external memory or automatically pick either type ba...
Definition: exec_policy.h:79
exec_policy operator&(const access &am) const
Create a copy with the access mode changed.
Definition: exec_policy.h:353
access
Whether Adiar should exclusively use random access or priority queues or automatically pick either wa...
Definition: exec_policy.h:55
exec_policy()=default
Default constructor with all options set to their default value.
exec_policy & operator=(const exec_policy &)=default
Copy assignment.
exec_policy & set(const quantify::algorithm &qa)
Set the quantify algorithm.
Definition: exec_policy.h:383
exec_policy(const memory &mm)
Conversion construction from memory enum.
Definition: exec_policy.h:267
exec_policy operator&(const memory &mm) const
Create a copy with the memory mode changed.
Definition: exec_policy.h:373
exec_policy & set(const access &am)
Set the access mode.
Definition: exec_policy.h:343
exec_policy(const access &am)
Conversion construction from access enum.
Definition: exec_policy.h:260
bool operator==(const exec_policy &ep) const
Check for equality of settings.
Definition: exec_policy.h:320
exec_policy & set(const quantify::transposition_max &tm)
Set the quantify strategy.
Definition: exec_policy.h:423
exec_policy(const quantify::algorithm &qa)
Conversion construction from quantify enum.
Definition: exec_policy.h:274
bool operator!=(const exec_policy &ep) const
Check for at least one mismatch in the settings.
Definition: exec_policy.h:333
exec_policy operator&(const quantify::transposition_max &tm) const
Create a copy with the quantify algorithm changed.
Definition: exec_policy.h:433
exec_policy(exec_policy &&)=default
Move constructor.
exec_policy & operator=(exec_policy &&)=default
Move assignment.
exec_policy & set(const memory &mm)
Set the memory mode.
Definition: exec_policy.h:363
exec_policy(const quantify::transposition_max &tm)
Conversion construction from quantify transposition max runs value.
Definition: exec_policy.h:288
const T & get() const
Obtain a value.
exec_policy(const exec_policy &)=default
Copy constructor.
exec_policy operator&(const quantify::algorithm &qa) const
Create a copy with the quantify algorithm changed.
Definition: exec_policy.h:393
__bdd operator&(const bdd &lhs, const bdd &rhs)
Core types.
Definition: adiar.h:40