Generated on Tue Jan 19 2021 06:15:49 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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 namespace Gecode {
35 
36  class TraceFilter;
37 
42  class TFE {
43  friend GECODE_KERNEL_EXPORT TFE operator -(const TFE& r);
46  friend class TraceFilter;
47  protected:
49  enum NodeType {
53  };
55  class Node : public HeapAllocated {
56  public:
58  unsigned int use;
62  int n;
66  char w;
68  Node *l, *r;
70  Node(void);
73  bool decrement(void);
74  };
76  Node* n;
78  TFE(void);
80  TFE(Node* n);
82  void init(Group g, char what);
84  TFE negate(void) const;
85  public:
91  TFE(BrancherGroup g);
94  static TFE other(void);
97  TFE(const TFE& e);
100  TFE& operator =(const TFE& e);
103  TFE& operator +=(const TFE& e);
106  TFE& operator -=(const TFE& e);
109  ~TFE(void);
110  };
111 
113  TFE operator +(TFE l, const TFE& r);
115  TFE operator +(const TFE& e);
117  TFE operator -(TFE l, const TFE& r);
120  TFE operator -(const TFE& e);
127 
128 
133  class TraceFilter : public SharedHandle {
134  protected:
136  class TFO : public SharedHandle::Object {
137  public:
139  struct Filter {
143  bool neg;
145  char what;
146  };
147  class StackFrame {
148  public:
152  bool neg;
154  StackFrame(void);
156  StackFrame(TFE::Node* n, bool neg);
157  };
159  int n;
164  void fill(TFE::Node* n);
166  TFO(void);
168  TFO(const TFE& e);
174  bool operator ()(const ViewTraceInfo& vti) const;
176  bool operator ()(PropagatorGroup pg) const;
178  bool operator ()(BrancherGroup bg) const;
181  virtual ~TFO(void);
182  };
183  public:
186  TraceFilter(void);
189  TraceFilter(const TFE& e);
198  TraceFilter(const TraceFilter& tf);
201  TraceFilter& operator =(const TraceFilter& tf);
203  bool operator ()(const ViewTraceInfo& vti) const;
205  bool operator ()(PropagatorGroup pg) const;
207  bool operator ()(BrancherGroup bg) const;
210  static TraceFilter all;
211  };
212 
213 
214 
215  /*
216  * Trace expression filters
217  *
218  */
219 
222  : use(1), l(NULL), r(NULL) {}
224  TFE::TFE(void) : n(NULL) {}
226  TFE::TFE(TFE::Node* n0) : n(n0) {}
227 
229  operator +(TFE l, const TFE& r) {
230  l += r; return l;
231  }
233  operator +(const TFE& e) {
234  return e;
235  }
237  operator -(TFE l, const TFE& r) {
238  l -= r; return l;
239  }
240 
241 
242  /*
243  * Trace filters
244  *
245  */
247  TraceFilter::TFO::TFO(void) : n(0), f(NULL) {}
250  : n(e.n->n),
251  f((n == 0) ? NULL : heap.alloc<Filter>(n)) {
252  if (n > 0)
253  fill(e.n);
254  }
257  f = heap.alloc<Filter>(1);
258  f[0].g = g; f[0].neg = false;
259  f[0].what = 1 << ViewTraceInfo::PROPAGATOR;
260 
261  }
264  f = heap.alloc<Filter>(1);
265  f[0].g = g; f[0].neg = false;
266  f[0].what = 1 << ViewTraceInfo::BRANCHER;
267 
268  }
269  forceinline bool
271  if (n == 0)
272  return true;
273  for (int i=0; i<n; i++)
274  if (f[i].what & (1 << vti.what())) {
275  // Group is of the right type
276  switch (vti.what()) {
278  if (f[i].g.in(vti.propagator().group()) != f[i].neg)
279  return true;
280  break;
282  if (f[i].g.in(vti.brancher().group()) != f[i].neg)
283  return true;
284  break;
285  case ViewTraceInfo::POST:
286  if (f[i].g.in(vti.post()) != f[i].neg)
287  return true;
288  break;
290  return true;
291  default:
292  GECODE_NEVER;
293  }
294  }
295  return false;
296  }
297 
298  forceinline bool
300  return static_cast<TFO*>(object())->operator ()(vti);
301  }
302 
303  forceinline bool
305  if (n == 0)
306  return true;
307  for (int i=0; i<n; i++)
308  if ((f[i].what & (1 << ViewTraceInfo::PROPAGATOR)) &&
309  (f[i].g.in(pg) != f[i].neg))
310  return true;
311  return false;
312  }
313 
314  forceinline bool
316  return static_cast<TFO*>(object())->operator ()(pg);
317  }
318 
319  forceinline bool
321  if (n == 0)
322  return true;
323  for (int i=0; i<n; i++)
324  if ((f[i].what & (1 << ViewTraceInfo::BRANCHER)) &&
325  (f[i].g.in(bg) != f[i].neg))
326  return true;
327  return false;
328  }
329 
330  forceinline bool
332  return static_cast<TFO*>(object())->operator ()(bg);
333  }
334 
335 }
336 
337 // STATISTICS: kernel-trace
Node * n
Pointer to trace filter expression node.
Definition: filter.hpp:76
Propagator or brancher group.
Definition: filter.hpp:50
TFE(void)
Initialize with no node.
Definition: filter.hpp:224
int n
Number of leaf groups.
Definition: filter.hpp:62
The shared handle.
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
static TraceFilter all
Default filter: without any filter.
Definition: filter.hpp:210
TFE & operator+=(const TFE &e)
Add expression e.
Definition: filter.cpp:104
View trace information.
Definition: core.hpp:905
More than one expression.
Definition: filter.hpp:52
TFO(void)
Initialize without any filter and with fixpoint and done tracing.
Definition: filter.hpp:247
void propagator(Propagator &p)
Record that propagator p is executing.
Definition: core.hpp:3273
friend TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:138
A propagator is currently executing.
Definition: core.hpp:912
TFE & operator-=(const TFE &e)
Add expression e as negative expression.
Definition: filter.cpp:115
friend TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Definition: filter.cpp:131
Group of branchers.
Definition: core.hpp:796
int n
The number of filters.
Definition: filter.hpp:159
bool operator()(const ViewTraceInfo &vti) const
Check whether filter is true for view trace information vti.
Definition: filter.hpp:299
void brancher(Brancher &b)
Record that brancher b is executing.
Definition: core.hpp:3277
The actual object storing the shared filters.
Definition: filter.hpp:136
bool neg
Whether the filter is negative.
Definition: filter.hpp:143
char w
Which operations to consider for propagator groups.
Definition: filter.hpp:66
Node * l
Subexpressions.
Definition: filter.hpp:68
#define forceinline
Definition: config.hpp:185
void init(Group g, char what)
Initialize with propagator group g and flags what.
Definition: filter.cpp:56
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Definition: heap.hpp:431
IntRelType neg(IntRelType irt)
Return negated relation type of irt.
Definition: irt.hpp:52
A post function is executing.
Definition: core.hpp:916
Gecode::IntArgs i({1, 2, 3, 4})
bool operator()(const ViewTraceInfo &vti) const
Check whether filter is true for view trace information vti.
Definition: filter.hpp:270
FloatVal operator+(const FloatVal &x)
Definition: val.hpp:164
SharedHandle::Object * object(void) const
Access to the shared object.
Node for trace filter expression.
Definition: filter.hpp:55
Filter * f
The filters.
Definition: filter.hpp:161
NodeType t
Type of expression.
Definition: filter.hpp:60
bool decrement(void)
Decrement reference count and possibly free memory.
Definition: filter.cpp:43
Trace filters.
Definition: filter.hpp:133
Group baseclass for controlling actors.
Definition: core.hpp:672
#define GECODE_KERNEL_EXPORT
Definition: kernel.hh:70
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
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:3281
unsigned int use
Nodes are reference counted.
Definition: filter.hpp:58
static TFE other(void)
Expression for other than propagator, brancher, or post.
Definition: filter.cpp:82
friend TFE operator-(const TFE &r)
Return negative expression of e.
Definition: filter.cpp:126
TFE & operator=(const TFE &e)
Assignment operator.
Definition: filter.cpp:93
Heap heap
The single global heap.
Definition: heap.cpp:44
~TFE(void)
Destructor.
Definition: filter.cpp:119
void fill(TFE::Node *n)
Fill the filters.
Definition: filter.cpp:159
char what
One bit set for each operation type.
Definition: filter.hpp:145
bool neg
Whether it is negated.
Definition: filter.hpp:152
Gecode toplevel namespace
What what(void) const
Return what is currently executing.
Definition: core.hpp:3289
Group of propagators.
Definition: core.hpp:725
TFE negate(void) const
Return negated the expresssion.
Definition: filter.cpp:65
Filter information.
Definition: filter.hpp:139
Node(void)
Default constructor.
Definition: filter.hpp:221
A brancher is executing.
Definition: core.hpp:914
NodeType
Type of trace filter expression.
Definition: filter.hpp:49
Base class for heap allocated objects.
Definition: heap.hpp:340
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
Negation of expression.
Definition: filter.hpp:51
Trace filter expressions.
Definition: filter.hpp:42
friend class TraceFilter
Definition: filter.hpp:46
Group g
Group.
Definition: filter.hpp:64
Group g
The filter group.
Definition: filter.hpp:141