Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
filter.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2016
8  *
9  * Last modified:
10  * $Date$ by $Author$
11  * $Revision$
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode {
39 
40  class TraceFilter;
41 
46  class TFE {
47  friend GECODE_KERNEL_EXPORT TFE operator -(const TFE& r);
50  friend class TraceFilter;
51  protected:
53  enum NodeType {
57  };
59  class Node : public HeapAllocated {
60  public:
62  unsigned int use;
66  int n;
70  char w;
72  Node *l, *r;
74  Node(void);
77  bool decrement(void);
78  };
80  Node* n;
82  TFE(void);
84  TFE(Node* n);
86  void init(Group g, char what);
88  TFE negate(void) const;
89  public:
95  TFE(BrancherGroup g);
98  static TFE other(void);
101  TFE(const TFE& e);
104  TFE& operator =(const TFE& e);
107  TFE& operator +=(const TFE& e);
110  TFE& operator -=(const TFE& e);
113  ~TFE(void);
114  };
115 
117  TFE operator +(TFE l, const TFE& r);
119  TFE operator +(const TFE& e);
121  TFE operator -(TFE l, const TFE& r);
124  TFE operator -(const TFE& e);
131 
132 
137  class TraceFilter : public SharedHandle {
138  protected:
140  class TFO : public SharedHandle::Object {
141  public:
143  struct Filter {
147  bool neg;
149  char what;
150  };
151  class StackFrame {
152  public:
156  bool neg;
158  StackFrame(void);
160  StackFrame(TFE::Node* n, bool neg);
161  };
163  int n;
168  void fill(TFE::Node* n);
170  TFO(void);
172  TFO(const TFE& e);
178  bool operator ()(const ViewTraceInfo& vti) const;
180  bool operator ()(PropagatorGroup pg) const;
182  bool operator ()(BrancherGroup bg) const;
185  virtual ~TFO(void);
186  };
187  public:
190  TraceFilter(void);
193  TraceFilter(const TFE& e);
202  TraceFilter(const TraceFilter& tf);
205  TraceFilter& operator =(const TraceFilter& tf);
207  bool operator ()(const ViewTraceInfo& vti) const;
209  bool operator ()(PropagatorGroup pg) const;
211  bool operator ()(BrancherGroup bg) const;
214  static TraceFilter all;
215  };
216 
217 
218 
219  /*
220  * Trace expression filters
221  *
222  */
223 
226  : use(1), l(NULL), r(NULL) {}
228  TFE::TFE(void) : n(NULL) {}
230  TFE::TFE(TFE::Node* n0) : n(n0) {}
231 
233  operator +(TFE l, const TFE& r) {
234  l += r; return l;
235  }
237  operator +(const TFE& e) {
238  return e;
239  }
241  operator -(TFE l, const TFE& r) {
242  l -= r; return l;
243  }
244 
245 
246  /*
247  * Trace filters
248  *
249  */
251  TraceFilter::TFO::TFO(void) : n(0), f(NULL) {}
254  : n(e.n->n),
255  f((n == 0) ? NULL : heap.alloc<Filter>(n)) {
256  if (n > 0)
257  fill(e.n);
258  }
261  f = heap.alloc<Filter>(1);
262  f[0].g = g; f[0].neg = false;
263  f[0].what = 1 << ViewTraceInfo::PROPAGATOR;
264 
265  }
268  f = heap.alloc<Filter>(1);
269  f[0].g = g; f[0].neg = false;
270  f[0].what = 1 << ViewTraceInfo::BRANCHER;
271 
272  }
273  forceinline bool
275  if (n == 0)
276  return true;
277  for (int i=n; i--; )
278  if (f[i].what & (1 << vti.what())) {
279  // Group is of the right type
280  switch (vti.what()) {
282  if (f[i].g.in(vti.propagator().group()) != f[i].neg)
283  return true;
284  break;
286  if (f[i].g.in(vti.brancher().group()) != f[i].neg)
287  return true;
288  break;
289  case ViewTraceInfo::POST:
290  if (f[i].g.in(vti.post()) != f[i].neg)
291  return true;
292  break;
294  return true;
295  default:
296  GECODE_NEVER;
297  }
298  }
299  return false;
300  }
301 
302  forceinline bool
304  return static_cast<TFO*>(object())->operator ()(vti);
305  }
306 
307  forceinline bool
309  if (n == 0)
310  return true;
311  for (int i=n; i--; )
312  if ((f[i].what & (1 << ViewTraceInfo::PROPAGATOR)) &&
313  (f[i].g.in(pg) != f[i].neg))
314  return true;
315  return false;
316  }
317 
318  forceinline bool
320  return static_cast<TFO*>(object())->operator ()(pg);
321  }
322 
323  forceinline bool
325  if (n == 0)
326  return true;
327  for (int i=n; i--; )
328  if ((f[i].what & (1 << ViewTraceInfo::BRANCHER)) &&
329  (f[i].g.in(bg) != f[i].neg))
330  return true;
331  return false;
332  }
333 
334  forceinline bool
336  return static_cast<TFO*>(object())->operator ()(bg);
337  }
338 
339 }
340 
341 // STATISTICS: kernel-trace
Node * n
Pointer to trace filter expression node.
Definition: filter.hpp:80
Propagator or brancher group.
Definition: filter.hpp:54
TFE(void)
Initialize with no node.
Definition: filter.hpp:228
int n
Number of leaf groups.
Definition: filter.hpp:66
The shared handle.
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
static TraceFilter all
Default filter: without any filter.
Definition: filter.hpp:214
TFE & operator+=(const TFE &e)
Add expression e.
Definition: filter.cpp:108
View trace information.
Definition: core.hpp:898
More than one expression.
Definition: filter.hpp:56
TFO(void)
Initialize without any filter and with fixpoint and done tracing.
Definition: filter.hpp:251
void propagator(Propagator &p)
Record that propagator p is executing.
Definition: core.hpp:3228
friend TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:142
A propagator is currently executing.
Definition: core.hpp:905
TFE & operator-=(const TFE &e)
Add expression e as negative expression.
Definition: filter.cpp:119
friend TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Definition: filter.cpp:135
Group of branchers.
Definition: core.hpp:789
int n
The number of filters.
Definition: filter.hpp:163
bool operator()(const ViewTraceInfo &vti) const
Check whether filter is true for view trace information vti.
Definition: filter.hpp:303
void brancher(Brancher &b)
Record that brancher b is executing.
Definition: core.hpp:3232
The actual object storing the shared filters.
Definition: filter.hpp:140
bool neg
Whether the filter is negative.
Definition: filter.hpp:147
char w
Which operations to consider for propagator groups.
Definition: filter.hpp:70
Node * l
Subexpressions.
Definition: filter.hpp:72
#define forceinline
Definition: config.hpp:182
void init(Group g, char what)
Initialize with propagator group g and flags what.
Definition: filter.cpp:60
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Definition: heap.hpp:435
Gecode::IntArgs i(4, 1, 2, 3, 4)
IntRelType neg(IntRelType irt)
Return negated relation type of irt.
Definition: irt.hpp:56
A post function is executing.
Definition: core.hpp:909
bool operator()(const ViewTraceInfo &vti) const
Check whether filter is true for view trace information vti.
Definition: filter.hpp:274
FloatVal operator+(const FloatVal &x)
Definition: val.hpp:168
SharedHandle::Object * object(void) const
Access to the shared object.
Node for trace filter expression.
Definition: filter.hpp:59
Filter * f
The filters.
Definition: filter.hpp:165
NodeType t
Type of expression.
Definition: filter.hpp:64
bool decrement(void)
Decrement reference count and possibly free memory.
Definition: filter.cpp:47
Trace filters.
Definition: filter.hpp:137
Group baseclass for controlling actors.
Definition: core.hpp:665
#define GECODE_KERNEL_EXPORT
Definition: kernel.hh:74
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
void post(PropagatorGroup g)
Record that a post function with propagator group g is executing.
Definition: core.hpp:3236
unsigned int use
Nodes are reference counted.
Definition: filter.hpp:62
static TFE other(void)
Expression for other than propagator, brancher, or post.
Definition: filter.cpp:86
friend TFE operator-(const TFE &r)
Return negative expression of e.
Definition: filter.cpp:130
TFE & operator=(const TFE &e)
Assignment operator.
Definition: filter.cpp:97
Heap heap
The single global heap.
Definition: heap.cpp:48
~TFE(void)
Destructor.
Definition: filter.cpp:123
void fill(TFE::Node *n)
Fill the filters.
Definition: filter.cpp:163
char what
One bit set for each operation type.
Definition: filter.hpp:149
bool neg
Whether it is negated.
Definition: filter.hpp:156
Gecode toplevel namespace
What what(void) const
Return what is currently executing.
Definition: core.hpp:3244
Group of propagators.
Definition: core.hpp:718
TFE negate(void) const
Return negated the expresssion.
Definition: filter.cpp:69
Filter information.
Definition: filter.hpp:143
Node(void)
Default constructor.
Definition: filter.hpp:225
A brancher is executing.
Definition: core.hpp:907
NodeType
Type of trace filter expression.
Definition: filter.hpp:53
Base class for heap allocated objects.
Definition: heap.hpp:344
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
Negation of expression.
Definition: filter.hpp:55
Trace filter expressions.
Definition: filter.hpp:46
friend class TraceFilter
Definition: filter.hpp:50
Group g
Group.
Definition: filter.hpp:68
Group g
The filter group.
Definition: filter.hpp:145