Generated on Thu Jan 31 2019 20:56:39 for Gecode by doxygen 1.8.15
trace-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: 2017-03-17 23:04:57 +0100 (Fri, 17 Mar 2017) $ by $Author: schulte $
11  * $Revision: 15597 $
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);
174  TFO(PropagatorGroup g);
176  TFO(BrancherGroup g);
178  TFO(const TFO& o);
180  bool operator ()(const ViewTraceInfo& vti) const;
182  bool operator ()(PropagatorGroup pg) const;
184  bool operator ()(BrancherGroup bg) const;
187  virtual Object* copy(void) const;
190  virtual ~TFO(void);
191  };
192  public:
195  TraceFilter(void);
198  TraceFilter(const TFE& e);
207  TraceFilter(const TraceFilter& tf);
210  TraceFilter& operator =(const TraceFilter& tf);
212  bool operator ()(const ViewTraceInfo& vti) const;
214  bool operator ()(PropagatorGroup pg) const;
216  bool operator ()(BrancherGroup bg) const;
219  static TraceFilter all;
220  };
221 
222 
223 
224  /*
225  * Trace expression filters
226  *
227  */
228 
231  : use(1), l(NULL), r(NULL) {}
233  TFE::TFE(void) : n(NULL) {}
235  TFE::TFE(TFE::Node* n0) : n(n0) {}
236 
238  operator +(TFE l, const TFE& r) {
239  l += r; return l;
240  }
241  forceinline TFE
242  operator +(const TFE& e) {
243  return e;
244  }
245  forceinline TFE
246  operator -(TFE l, const TFE& r) {
247  l -= r; return l;
248  }
249 
250 
251  /*
252  * Trace filters
253  *
254  */
256  TraceFilter::TFO::TFO(void) : n(0), f(NULL) {}
259  : n(e.n->n),
260  f((n == 0) ? NULL : heap.alloc<Filter>(n)) {
261  if (n > 0)
262  fill(e.n);
263  }
266  f = heap.alloc<Filter>(1);
267  f[0].g = g; f[0].neg = false;
268  f[0].what = 1 << ViewTraceInfo::PROPAGATOR;
269 
270  }
273  f = heap.alloc<Filter>(1);
274  f[0].g = g; f[0].neg = false;
275  f[0].what = 1 << ViewTraceInfo::BRANCHER;
276 
277  }
279  TraceFilter::TFO::TFO(const TFO& o) : n(o.n) {
280  if (n > 0) {
281  f = heap.alloc<Filter>(n);
282  for (int i=n; i--; )
283  f[i] = o.f[i];
284  } else {
285  f = NULL;
286  }
287  }
288  forceinline bool
290  if (n == 0)
291  return true;
292  for (int i=n; i--; )
293  if (f[i].what & (1 << vti.what())) {
294  // Group is of the right type
295  switch (vti.what()) {
297  if (f[i].g.in(vti.propagator().group()) != f[i].neg)
298  return true;
299  break;
301  if (f[i].g.in(vti.brancher().group()) != f[i].neg)
302  return true;
303  break;
304  case ViewTraceInfo::POST:
305  if (f[i].g.in(vti.post()) != f[i].neg)
306  return true;
307  break;
309  return true;
310  default:
311  GECODE_NEVER;
312  }
313  }
314  return false;
315  }
316 
317  forceinline bool
319  return static_cast<TFO*>(object())->operator ()(vti);
320  }
321 
322  forceinline bool
324  if (n == 0)
325  return true;
326  for (int i=n; i--; )
327  if ((f[i].what & (1 << ViewTraceInfo::PROPAGATOR)) &&
328  (f[i].g.in(pg) != f[i].neg))
329  return true;
330  return false;
331  }
332 
333  forceinline bool
335  return static_cast<TFO*>(object())->operator ()(pg);
336  }
337 
338  forceinline bool
340  if (n == 0)
341  return true;
342  for (int i=n; i--; )
343  if ((f[i].what & (1 << ViewTraceInfo::BRANCHER)) &&
344  (f[i].g.in(bg) != f[i].neg))
345  return true;
346  return false;
347  }
348 
349  forceinline bool
351  return static_cast<TFO*>(object())->operator ()(bg);
352  }
353 
354 }
355 
356 // STATISTICS: kernel-trace
Node * n
Pointer to trace filter expression node.
FloatVal operator -(const FloatVal &x)
Definition: val.hpp:172
Propagator or brancher group.
virtual Object * copy(void) const
Create a copy.
TFE(void)
Initialize with no node.
int n
Number of leaf groups.
The shared handle.
Definition: core.hpp:79
TFE & operator -=(const TFE &e)
Add expression e as negative expression.
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
static TraceFilter all
Default filter: without any filter.
TFE & operator+=(const TFE &e)
Add expression e.
View trace information.
Definition: core.hpp:974
More than one expression.
TFO(void)
Initialize without any filter and with fixpoint and done tracing.
void propagator(Propagator &p)
Record that propagator p is executing.
Definition: core.hpp:3410
friend TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
A propagator is currently executing.
Definition: core.hpp:981
friend TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Group of branchers.
Definition: core.hpp:865
int n
The number of filters.
bool operator()(const ViewTraceInfo &vti) const
Check whether filter is true for view trace information vti.
void brancher(Brancher &b)
Record that brancher b is executing.
Definition: core.hpp:3414
The actual object storing the shared filters.
TraceFilter & operator=(const TraceFilter &tf)
Assignment operator.
virtual ~TFO(void)
Destructor.
bool neg
Whether the filter is negative.
char w
Which operations to consider for propagator groups.
Node * l
Subexpressions.
void init(Group g, char what)
Initialize with propagator group g and flags what.
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
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
A post function is executing.
Definition: core.hpp:985
bool operator()(const ViewTraceInfo &vti) const
Check whether filter is true for view trace information vti.
FloatVal operator+(const FloatVal &x)
Definition: val.hpp:168
Node for trace filter expression.
Filter * f
The filters.
NodeType t
Type of expression.
TraceFilter(void)
Initialize without any filter.
bool decrement(void)
Decrement reference count and possibly free memory.
Trace filters.
Group baseclass for controlling actors.
Definition: core.hpp:741
#define GECODE_KERNEL_EXPORT
Definition: kernel.hh:74
TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
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:3418
unsigned int use
Nodes are reference counted.
static TFE other(void)
Expression for other than propagator, brancher, or post.
TFE & operator=(const TFE &e)
Assignment operator.
Heap heap
The single global heap.
Definition: heap.cpp:48
#define forceinline
Definition: config.hpp:173
~TFE(void)
Destructor.
void fill(TFE::Node *n)
Fill the filters.
char what
One bit set for each operation type.
The shared object.
Definition: core.hpp:88
StackFrame(void)
Default constructor.
friend TFE operator -(const TFE &r)
Return negative expression of e.
bool neg
Whether it is negated.
Gecode toplevel namespace
What what(void) const
Return what is currently executing.
Definition: core.hpp:3426
Group of propagators.
Definition: core.hpp:794
TFE negate(void) const
Return negated the expresssion.
Node(void)
Default constructor.
A brancher is executing.
Definition: core.hpp:983
NodeType
Type of trace filter expression.
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.
Trace filter expressions.
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.