Generated on Thu Mar 16 2017 03:24:22 for Gecode by doxygen 1.8.13
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: 2016-06-17 15:43:08 +0200 (Fri, 17 Jun 2016) $ by $Author: schulte $
11  * $Revision: 15116 $
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  TFO(const TFO& o);
180  bool operator ()(const ExecInfo& ei) const;
183  virtual Object* copy(void) const;
186  virtual ~TFO(void);
187  };
188  public:
191  TraceFilter(void);
194  TraceFilter(const TFE& e);
203  TraceFilter(const TraceFilter& tf);
206  TraceFilter& operator =(const TraceFilter& tf);
208  bool operator ()(const ExecInfo& ei) const;
211  static TraceFilter all;
212  };
213 
214 
215 
216  /*
217  * Trace expression filters
218  *
219  */
220 
223  : use(1), l(NULL), r(NULL) {}
225  TFE::TFE(void) : n(NULL) {}
227  TFE::TFE(TFE::Node* n0) : n(n0) {}
228 
230  operator +(TFE l, const TFE& r) {
231  l += r; return l;
232  }
234  operator +(const TFE& e) {
235  return e;
236  }
238  operator -(TFE l, const TFE& r) {
239  l -= r; return l;
240  }
241 
242 
243  /*
244  * Trace filters
245  *
246  */
248  TraceFilter::TFO::TFO(void) : n(0), f(NULL) {}
251  : n(e.n->n),
252  f((n == 0) ? NULL : heap.alloc<Filter>(n)) {
253  if (n > 0)
254  fill(e.n);
255  }
258  f = heap.alloc<Filter>(1);
259  f[0].g = g; f[0].neg = false;
260  f[0].what = 1 << ExecInfo::PROPAGATOR;
261 
262  }
265  f = heap.alloc<Filter>(1);
266  f[0].g = g; f[0].neg = false;
267  f[0].what = 1 << ExecInfo::BRANCHER;
268 
269  }
271  TraceFilter::TFO::TFO(const TFO& o) : n(o.n) {
272  if (n > 0) {
273  f = heap.alloc<Filter>(n);
274  for (int i=n; i--; )
275  f[i] = o.f[i];
276  } else {
277  f = NULL;
278  }
279  }
280  forceinline bool
282  if (n == 0)
283  return true;
284  for (int i=n; i--; )
285  if (f[i].what & (1 << ei.what())) {
286  // Group is of the right type
287  switch (ei.what()) {
289  if (f[i].g.in(ei.propagator().group()) != f[i].neg)
290  return true;
291  break;
292  case ExecInfo::BRANCHER:
293  if (f[i].g.in(ei.brancher().group()) != f[i].neg)
294  return true;
295  break;
296  case ExecInfo::POST:
297  if (f[i].g.in(ei.post()) != f[i].neg)
298  return true;
299  break;
300  case ExecInfo::OTHER:
301  return true;
302  default:
303  GECODE_NEVER;
304  }
305  }
306  return false;
307  }
308 
309  forceinline bool
311  return static_cast<TFO*>(object())->operator ()(ei);
312  }
313 
314 }
315 
316 // STATISTICS: kernel-other
Node * n
Pointer to trace filter expression node.
Propagator or brancher group.
TFE(void)
Initialize with no node.
int n
Number of leaf groups.
void brancher(Brancher &b)
Record that brancher b is executing.
Definition: core.hpp:3341
The shared handle.
Definition: core.hpp:79
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.
More than one expression.
TFO(void)
Initialize without any filter and with fixpoint and done tracing.
friend TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
TFE & operator-=(const TFE &e)
Add expression e as negative expression.
friend TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Group of branchers.
Definition: core.hpp:848
A brancher is executing.
Definition: core.hpp:966
A post function is executing.
Definition: core.hpp:968
int n
The number of filters.
The actual object storing the shared filters.
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.
What what(void) const
Return what is currently executing.
Definition: core.hpp:3353
bool operator()(const ExecInfo &ei) const
Check whether filter is true for execution information ei.
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)
bool operator()(const ExecInfo &ei) const
Check whether filter is true for execution information ei.
FloatVal operator+(const FloatVal &x)
Definition: val.hpp:168
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
SharedHandle::Object * object(void) const
Access to the shared object.
Definition: core.hpp:3005
Node for trace filter expression.
Filter * f
The filters.
A propagator is currently executing.
Definition: core.hpp:964
NodeType t
Type of expression.
void post(PropagatorGroup g)
Record that a post function with propagator group g is executing.
Definition: core.hpp:3345
bool decrement(void)
Decrement reference count and possibly free memory.
Trace filters.
Group baseclass for controlling actors.
Definition: core.hpp:727
#define GECODE_KERNEL_EXPORT
Definition: kernel.hh:70
Execution information.
Definition: core.hpp:957
unsigned int use
Nodes are reference counted.
static TFE other(void)
Expression for other than propagator, brancher, or post.
friend TFE operator-(const TFE &r)
Return negative expression of e.
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
bool neg
Whether it is negated.
Gecode toplevel namespace
Group of propagators.
Definition: core.hpp:778
TFE negate(void) const
Return negated the expresssion.
Node(void)
Default constructor.
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.
friend class TraceFilter
Group g
Group.
void propagator(Propagator &p)
Record that propagator p is executing.
Definition: core.hpp:3337
bool neg
Is atomic formula negative.
Definition: bool-expr.cpp:251
Group g
The filter group.