Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
filter.cpp
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#include <gecode/kernel.hh>
35
36namespace Gecode {
37
38 /*
39 * Trace filter expressions
40 *
41 */
42 bool
44 if (--use == 0) {
45 if ((l != NULL) && l->decrement())
46 delete l;
47 if ((r != NULL) && r->decrement())
48 delete r;
49 return true;
50 }
51 return false;
52 }
53
54
55 forceinline void
56 TFE::init(Group g, char what) {
57 n = new Node;
58 n->t = NT_GROUP;
59 n->g = g;
60 n->n = 1;
61 n->w = what;
62 }
63
64 inline TFE
65 TFE::negate(void) const {
66 Node* m = new Node;
67 m->t = NT_NEGATE;
68 m->n = n->n;
69 m->l = n; n->use++;
70 return TFE(m);
71 }
72
76
80
81 TFE
82 TFE::other(void) {
83 TFE e;
85 return e;
86 }
87
88 TFE::TFE(const TFE& e) : n(e.n) {
89 n->use++;
90 }
91
92 TFE&
93 TFE::operator =(const TFE& e) {
94 if (&e != this) {
95 if (n->decrement())
96 delete n;
97 n = e.n;
98 n->use++;
99 }
100 return *this;
101 }
102
103 TFE&
105 Node* a = new Node;
106 a->t = NT_ADD;
107 a->n = n->n + e.n->n;
108 a->l = n;
109 a->r = e.n; e.n->use++;
110 n = a;
111 return *this;
112 }
113
114 TFE&
116 return operator +=(e.negate());
117 }
118
119 TFE::~TFE(void) {
120 if (n->decrement())
121 delete n;
122 }
123
124
125 TFE
126 operator -(const TFE& e) {
127 return e.negate();
128 }
129
130 TFE
132 TFE e;
134 return e;
135 }
136
137 TFE
139 TFE e;
140 e.init(g,(1 << ViewTraceInfo::POST));
141 return e;
142 }
143
144
145
146 /*
147 * Trace filters
148 *
149 */
150
151
156 : n(n0), neg(neg0) {}
157
158 void
160 Region region;
162 int i=0;
163 next.push(StackFrame(n,false));
164 do {
165 StackFrame s = next.pop();
166 switch (s.n->t) {
167 case TFE::NT_GROUP:
168 f[i].g = s.n->g; f[i].neg = s.neg; f[i].what=s.n->w;
169 i++;
170 break;
171 case TFE::NT_NEGATE:
172 next.push(StackFrame(s.n->l,!s.neg));
173 break;
174 case TFE::NT_ADD:
175 next.push(StackFrame(s.n->l,s.neg));
176 next.push(StackFrame(s.n->r,s.neg));
177 break;
178 default: GECODE_NEVER;
179 }
180 } while (!next.empty());
181 }
182
184 heap.free<Filter>(f,n);
185 }
186
188
190
192
194
196
199 return static_cast<TraceFilter&>(SharedHandle::operator =(tf));
200 }
201
203
204}
205
206// STATISTICS: kernel-trace
Group of branchers.
Definition core.hpp:799
Group baseclass for controlling actors.
Definition core.hpp:673
static Group all
Group of all actors.
Definition core.hpp:717
Group of propagators.
Definition core.hpp:727
Handle to region.
Definition region.hpp:55
SharedHandle & operator=(const SharedHandle &sh)
Assignment operator maintaining reference count.
SharedHandle(void)
Create shared handle with no object pointing to.
Stack with arbitrary number of elements.
void push(const T &x)
Push element x on top of stack.
bool empty(void) const
Test whether stack is empty.
T pop(void)
Pop topmost element from stack and return it.
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
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
static TFE other(void)
Expression for other than propagator, brancher, or post.
Definition filter.cpp:82
~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
@ 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
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
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
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
@ BRANCHER
A brancher is executing.
Definition core.hpp:919
@ POST
A post function is executing.
Definition core.hpp:921
@ PROPAGATOR
A propagator is currently executing.
Definition core.hpp:917
Heap heap
The single global heap.
Definition heap.cpp:44
Gecode toplevel namespace
FloatVal operator-(const FloatVal &x)
Definition val.hpp:168
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
#define forceinline
Definition config.hpp:194
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56