Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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
34namespace Gecode {
35
36 class TraceFilter;
37
42 class TFE {
46 friend class TraceFilter;
47 protected:
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 };
78 TFE(void);
80 TFE(Node* n);
82 void init(Group g, char what);
84 TFE negate(void) const;
85 public:
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 };
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);
203 bool operator ()(const ViewTraceInfo& vti) const;
205 bool operator ()(PropagatorGroup pg) const;
207 bool operator ()(BrancherGroup bg) const;
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 }
232 forceinline TFE
233 operator +(const TFE& e) {
234 return e;
235 }
236 forceinline TFE
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;
260
261 }
264 f = heap.alloc<Filter>(1);
265 f[0].g = g; f[0].neg = false;
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;
286 if (f[i].g.in(vti.post()) != f[i].neg)
287 return true;
288 break;
290 return true;
291 default:
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
NNF * l
Left subtree.
int n
Number of negative literals for node type.
Group of branchers.
Definition core.hpp:799
Group baseclass for controlling actors.
Definition core.hpp:673
Base class for heap allocated objects.
Definition heap.hpp:340
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Definition heap.hpp:431
Group of propagators.
Definition core.hpp:727
The shared handle.
SharedHandle::Object * object(void) const
Access to the shared object.
Node for trace filter expression.
Definition filter.hpp:55
NodeType t
Type of expression.
Definition filter.hpp:60
unsigned int use
Nodes are reference counted.
Definition filter.hpp:58
Node(void)
Default constructor.
Definition filter.hpp:221
Group g
Group.
Definition filter.hpp:64
bool decrement(void)
Decrement reference count and possibly free memory.
Definition filter.cpp:43
Node * l
Subexpressions.
Definition filter.hpp:68
int n
Number of leaf groups.
Definition filter.hpp:62
char w
Which operations to consider for propagator groups.
Definition filter.hpp:66
Trace filter expressions.
Definition filter.hpp:42
TFE & operator+=(const TFE &e)
Add expression e.
Definition filter.cpp:104
friend TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Definition filter.cpp:131
static TFE other(void)
Expression for other than propagator, brancher, or post.
Definition filter.cpp:82
friend TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
~TFE(void)
Destructor.
Definition filter.cpp:119
Node * n
Pointer to trace filter expression node.
Definition filter.hpp:76
void init(Group g, char what)
Initialize with propagator group g and flags what.
Definition filter.cpp:56
TFE & operator-=(const TFE &e)
Add expression e as negative expression.
Definition filter.cpp:115
TFE & operator=(const TFE &e)
Assignment operator.
Definition filter.cpp:93
TFE negate(void) const
Return negated the expresssion.
Definition filter.cpp:65
NodeType
Type of trace filter expression.
Definition filter.hpp:49
@ NT_NEGATE
Negation of expression.
Definition filter.hpp:51
@ NT_GROUP
Propagator or brancher group.
Definition filter.hpp:50
@ NT_ADD
More than one expression.
Definition filter.hpp:52
friend TFE operator-(const TFE &r)
Return negative expression of e.
Definition filter.cpp:126
TFE(void)
Initialize with no node.
Definition filter.hpp:224
StackFrame(void)
Default constructor.
Definition filter.cpp:153
bool neg
Whether it is negated.
Definition filter.hpp:152
The actual object storing the shared filters.
Definition filter.hpp:136
bool operator()(const ViewTraceInfo &vti) const
Check whether filter is true for view trace information vti.
Definition filter.hpp:270
TFO(void)
Initialize without any filter and with fixpoint and done tracing.
Definition filter.hpp:247
int n
The number of filters.
Definition filter.hpp:159
void fill(TFE::Node *n)
Fill the filters.
Definition filter.cpp:159
Filter * f
The filters.
Definition filter.hpp:161
virtual ~TFO(void)
Destructor.
Definition filter.cpp:183
Trace filters.
Definition filter.hpp:133
bool operator()(const ViewTraceInfo &vti) const
Check whether filter is true for view trace information vti.
Definition filter.hpp:299
TraceFilter(void)
Initialize without any filter.
Definition filter.cpp:187
static TraceFilter all
Default filter: without any filter.
Definition filter.hpp:210
TraceFilter & operator=(const TraceFilter &tf)
Assignment operator.
Definition filter.cpp:198
View trace information.
Definition core.hpp:908
What what(void) const
Return what is currently executing.
Definition core.hpp:3332
void brancher(Brancher &b)
Record that brancher b is executing.
Definition core.hpp:3320
@ BRANCHER
A brancher is executing.
Definition core.hpp:917
@ POST
A post function is executing.
Definition core.hpp:919
@ PROPAGATOR
A propagator is currently executing.
Definition core.hpp:915
void propagator(Propagator &p)
Record that propagator p is executing.
Definition core.hpp:3316
void post(PropagatorGroup g)
Record that a post function with propagator group g is executing.
Definition core.hpp:3324
Heap heap
The single global heap.
Definition heap.cpp:44
#define GECODE_KERNEL_EXPORT
Definition kernel.hh:70
Gecode toplevel namespace
FloatVal operator-(const FloatVal &x)
Definition val.hpp:168
FloatVal operator+(const FloatVal &x)
Definition val.hpp:164
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:767
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Definition filter.cpp:131
Group g
The filter group.
Definition filter.hpp:141
bool neg
Whether the filter is negative.
Definition filter.hpp:143
char what
One bit set for each operation type.
Definition filter.hpp:145
#define forceinline
Definition config.hpp:187
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56