main page
modules
namespaces
classes
files
Gecode home
Generated on Wed Jan 1 2020 10:37:59 for Gecode by
doxygen
1.8.16
gecode
kernel
trace
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
36
namespace
Gecode
{
37
38
/*
39
* Trace filter expressions
40
*
41
*/
42
bool
43
TFE::Node::decrement
(
void
) {
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
73
TFE::TFE
(
PropagatorGroup
g) {
74
init
(g,(1 <<
ViewTraceInfo::PROPAGATOR
) | (1 <<
ViewTraceInfo::POST
));
75
}
76
77
TFE::TFE
(
BrancherGroup
g) {
78
init
(g,(1 <<
ViewTraceInfo::BRANCHER
));
79
}
80
81
TFE
82
TFE::other
(
void
) {
83
TFE
e;
84
e.
init
(
Group::all
,(1 <<
ViewTraceInfo::OTHER
));
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
&
104
TFE::operator +=
(
const
TFE
& e) {
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
&
115
TFE::operator -=
(
const
TFE
& e) {
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
131
propagator
(
PropagatorGroup
g) {
132
TFE
e;
133
e.
init
(g,(1 <<
ViewTraceInfo::PROPAGATOR
));
134
return
e;
135
}
136
137
TFE
138
post
(
PropagatorGroup
g) {
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
152
forceinline
153
TraceFilter::TFO::StackFrame::StackFrame
(
void
) {}
154
forceinline
155
TraceFilter::TFO::StackFrame::StackFrame
(
TFE::Node
* n0,
bool
neg0)
156
:
n
(n0),
neg
(neg0) {}
157
158
void
159
TraceFilter::TFO::fill
(
TFE::Node
*
n
) {
160
Region
region;
161
Support::DynamicStack<StackFrame,Region>
next(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
183
TraceFilter::TFO::~TFO
(
void
) {
184
heap
.
free
<
Filter
>(
f
,
n
);
185
}
186
187
TraceFilter::TraceFilter
(
void
) :
SharedHandle
(new
TFO
) {}
188
189
TraceFilter::TraceFilter
(
const
TFE
& e) :
SharedHandle
(new
TFO
(e)) {}
190
191
TraceFilter::TraceFilter
(
PropagatorGroup
g) :
SharedHandle
(new
TFO
(g)) {}
192
193
TraceFilter::TraceFilter
(
BrancherGroup
g) :
SharedHandle
(new
TFO
(g)) {}
194
195
TraceFilter::TraceFilter
(
const
TraceFilter
& tf) :
SharedHandle
(tf) {}
196
197
TraceFilter
&
198
TraceFilter::operator =
(
const
TraceFilter
& tf) {
199
return
static_cast<TraceFilter&>(SharedHandle::operator =(tf));
200
}
201
202
TraceFilter
TraceFilter::all
;
203
204
}
205
206
// STATISTICS: kernel-trace
kernel.hh
Gecode::TraceFilter::TFO
The actual object storing the shared filters.
Definition:
filter.hpp:136
Gecode::TFE::Node::w
char w
Which operations to consider for propagator groups.
Definition:
filter.hpp:66
Gecode::TraceFilter::TFO::Filter::neg
bool neg
Whether the filter is negative.
Definition:
filter.hpp:143
Gecode::ViewTraceInfo::OTHER
Unknown.
Definition:
core.hpp:921
Gecode::TFE::negate
TFE negate(void) const
Return negated the expresssion.
Definition:
filter.cpp:65
Gecode::TFE::~TFE
~TFE(void)
Destructor.
Definition:
filter.cpp:119
Gecode::TFE
Trace filter expressions.
Definition:
filter.hpp:42
Gecode::ViewTraceInfo::PROPAGATOR
A propagator is currently executing.
Definition:
core.hpp:915
Gecode::TFE::operator-=
TFE & operator-=(const TFE &e)
Add expression e as negative expression.
Definition:
filter.cpp:115
Gecode::TraceFilter::TFO::fill
void fill(TFE::Node *n)
Fill the filters.
Definition:
filter.cpp:159
Gecode::TFE::Node::use
unsigned int use
Nodes are reference counted.
Definition:
filter.hpp:58
Gecode::TFE::TFE
TFE(void)
Initialize with no node.
Definition:
filter.hpp:224
Gecode::TraceFilter::TraceFilter
TraceFilter(void)
Initialize without any filter.
Definition:
filter.cpp:187
Gecode::TFE::Node::r
Node * r
Definition:
filter.hpp:68
Gecode::TraceFilter::TFO::Filter::what
char what
One bit set for each operation type.
Definition:
filter.hpp:145
Gecode
Gecode toplevel namespace
Gecode::Support::DynamicStack::push
void push(const T &x)
Push element x on top of stack.
Definition:
dynamic-stack.hpp:140
Gecode::BrancherGroup
Group of branchers.
Definition:
core.hpp:799
Gecode::TFE::Node
Node for trace filter expression.
Definition:
filter.hpp:55
Gecode::TraceFilter::TFO::Filter::g
Group g
The filter group.
Definition:
filter.hpp:141
a
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Gecode::ViewTraceInfo::POST
A post function is executing.
Definition:
core.hpp:919
Gecode::TFE::Node::t
NodeType t
Type of expression.
Definition:
filter.hpp:60
Gecode::Support::DynamicStack::pop
T pop(void)
Pop topmost element from stack and return it.
Definition:
dynamic-stack.hpp:122
Gecode::TraceFilter
Trace filters.
Definition:
filter.hpp:133
Gecode::Region
Handle to region.
Definition:
region.hpp:55
Gecode::TFE::NT_NEGATE
Negation of expression.
Definition:
filter.hpp:51
Gecode::TraceFilter::all
static TraceFilter all
Default filter: without any filter.
Definition:
filter.hpp:210
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition:
filter.cpp:138
Gecode::Group
Group baseclass for controlling actors.
Definition:
core.hpp:673
Gecode::TFE::NT_GROUP
Propagator or brancher group.
Definition:
filter.hpp:50
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition:
macros.hpp:56
Gecode::TraceFilter::TFO::n
int n
The number of filters.
Definition:
filter.hpp:159
Gecode::operator-
FloatVal operator-(const FloatVal &x)
Definition:
val.hpp:168
Gecode::heap
Heap heap
The single global heap.
Definition:
heap.cpp:44
Gecode::neg
IntRelType neg(IntRelType irt)
Return negated relation type of irt.
Definition:
irt.hpp:52
Gecode::TFE::Node::decrement
bool decrement(void)
Decrement reference count and possibly free memory.
Definition:
filter.cpp:43
Gecode::TFE::Node::g
Group g
Group.
Definition:
filter.hpp:64
Gecode::TraceFilter::TFO::StackFrame::neg
bool neg
Whether it is negated.
Definition:
filter.hpp:152
Gecode::TraceFilter::operator=
TraceFilter & operator=(const TraceFilter &tf)
Assignment operator.
Definition:
filter.cpp:198
Gecode::Group::all
static Group all
Group of all actors.
Definition:
core.hpp:717
Gecode::TFE::NT_ADD
More than one expression.
Definition:
filter.hpp:52
Gecode::Heap::free
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Definition:
heap.hpp:457
Gecode::TraceFilter::TFO::StackFrame::n
TFE::Node * n
The node.
Definition:
filter.hpp:150
Gecode::TFE::init
void init(Group g, char what)
Initialize with propagator group g and flags what.
Definition:
filter.cpp:56
Gecode::Support::DynamicStack::empty
bool empty(void) const
Test whether stack is empty.
Definition:
dynamic-stack.hpp:148
Gecode::Support::DynamicStack
Stack with arbitrary number of elements.
Definition:
dynamic-stack.hpp:42
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::TraceFilter::TFO::Filter
Filter information.
Definition:
filter.hpp:139
Gecode::PropagatorGroup
Group of propagators.
Definition:
core.hpp:727
Gecode::SharedHandle
The shared handle.
Definition:
shared-object.hpp:46
Gecode::TraceFilter::TFO::~TFO
virtual ~TFO(void)
Destructor.
Definition:
filter.cpp:183
Gecode::TFE::Node::n
int n
Number of leaf groups.
Definition:
filter.hpp:62
Gecode::ViewTraceInfo::BRANCHER
A brancher is executing.
Definition:
core.hpp:917
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::TFE::n
Node * n
Pointer to trace filter expression node.
Definition:
filter.hpp:76
Gecode::propagator
TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Definition:
filter.cpp:131
Gecode::TraceFilter::TFO::StackFrame::StackFrame
StackFrame(void)
Default constructor.
Definition:
filter.cpp:153
Gecode::TFE::other
static TFE other(void)
Expression for other than propagator, brancher, or post.
Definition:
filter.cpp:82
Gecode::TFE::operator=
TFE & operator=(const TFE &e)
Assignment operator.
Definition:
filter.cpp:93
Gecode::TFE::operator+=
TFE & operator+=(const TFE &e)
Add expression e.
Definition:
filter.cpp:104
Gecode::TraceFilter::TFO::StackFrame
Definition:
filter.hpp:147
Gecode::TFE::Node::l
Node * l
Subexpressions.
Definition:
filter.hpp:68
Gecode::TraceFilter::TFO::f
Filter * f
The filters.
Definition:
filter.hpp:161