main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
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
* Last modified:
10
* $Date: 2017-03-17 23:04:57 +0100 (Fri, 17 Mar 2017) $ by $Author: schulte $
11
* $Revision: 15597 $
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
#include <
gecode/kernel.hh
>
39
40
namespace
Gecode
{
41
42
/*
43
* Trace filter expressions
44
*
45
*/
46
bool
47
TFE::Node::decrement
(
void
) {
48
if
(--
use
== 0) {
49
if
((
l
!= NULL) &&
l
->
decrement
())
50
delete
l
;
51
if
((
r
!= NULL) &&
r
->
decrement
())
52
delete
r
;
53
return
true
;
54
}
55
return
false
;
56
}
57
58
59
forceinline
void
60
TFE::init
(
Group
g,
char
what) {
61
n
=
new
Node
;
62
n
->
t
=
NT_GROUP
;
63
n
->
g
= g;
64
n
->
n
= 1;
65
n
->
w
= what;
66
}
67
68
inline
TFE
69
TFE::negate
(
void
)
const
{
70
Node
* m =
new
Node
;
71
m->
t
=
NT_NEGATE
;
72
m->
n
=
n
->
n
;
73
m->
l
=
n
;
n
->
use
++;
74
return
TFE
(m);
75
}
76
77
TFE::TFE
(
PropagatorGroup
g) {
78
init
(g,(1 <<
ViewTraceInfo::PROPAGATOR
) | (1 <<
ViewTraceInfo::POST
));
79
}
80
81
TFE::TFE
(
BrancherGroup
g) {
82
init
(g,(1 <<
ViewTraceInfo::BRANCHER
));
83
}
84
85
TFE
86
TFE::other
(
void
) {
87
TFE
e;
88
e.
init
(
Group::all
,(1 <<
ViewTraceInfo::OTHER
));
89
return
e;
90
}
91
92
TFE::TFE
(
const
TFE
& e) :
n
(e.
n
) {
93
n
->
use
++;
94
}
95
96
TFE
&
97
TFE::operator =
(
const
TFE
& e) {
98
if
(&e !=
this
) {
99
if
(
n
->
decrement
())
100
delete
n
;
101
n
= e.
n
;
102
n
->
use
++;
103
}
104
return
*
this
;
105
}
106
107
TFE
&
108
TFE::operator +=
(
const
TFE
& e) {
109
Node
*
a
=
new
Node
;
110
a
->t =
NT_ADD
;
111
a
->n =
n
->
n
+ e.
n
->
n
;
112
a
->l =
n
;
113
a
->r = e.
n
; e.
n
->
use
++;
114
n
=
a
;
115
return
*
this
;
116
}
117
118
TFE
&
119
TFE::operator -=
(
const
TFE
& e) {
120
return
operator +=
(e.
negate
());
121
}
122
123
TFE::~TFE
(
void
) {
124
if
(
n
->
decrement
())
125
delete
n
;
126
}
127
128
129
TFE
130
operator -
(
const
TFE
& e) {
131
return
e.
negate
();
132
}
133
134
TFE
135
propagator
(
PropagatorGroup
g) {
136
TFE
e;
137
e.
init
(g,(1 <<
ViewTraceInfo::PROPAGATOR
));
138
return
e;
139
}
140
141
TFE
142
post
(
PropagatorGroup
g) {
143
TFE
e;
144
e.
init
(g,(1 <<
ViewTraceInfo::POST
));
145
return
e;
146
}
147
148
149
150
/*
151
* Trace filters
152
*
153
*/
154
155
156
forceinline
157
TraceFilter::TFO::StackFrame::StackFrame
(
void
) {}
158
forceinline
159
TraceFilter::TFO::StackFrame::StackFrame
(
TFE::Node
* n0,
bool
neg0)
160
:
n
(n0),
neg
(neg0) {}
161
162
void
163
TraceFilter::TFO::fill
(
TFE::Node
*
n
) {
164
Support::DynamicStack<StackFrame,Heap>
next(
heap
);
165
int
i
=0;
166
next.
push
(
StackFrame
(
n
,
false
));
167
do
{
168
StackFrame
s = next.
pop
();
169
switch
(s.
n
->
t
) {
170
case
TFE::NT_GROUP
:
171
f
[
i
].
g
= s.
n
->
g
;
f
[
i
].
neg
= s.
neg
;
f
[
i
].
what
=s.
n
->
w
;
172
i
++;
173
break
;
174
case
TFE::NT_NEGATE
:
175
next.
push
(
StackFrame
(s.
n
->
l
,!s.
neg
));
176
break
;
177
case
TFE::NT_ADD
:
178
next.
push
(
StackFrame
(s.
n
->
l
,s.
neg
));
179
next.
push
(
StackFrame
(s.
n
->
r
,s.
neg
));
180
break
;
181
default
:
GECODE_NEVER
;
182
}
183
}
while
(!next.
empty
());
184
}
185
186
SharedHandle::Object
*
187
TraceFilter::TFO::copy
(
void
)
const
{
188
return
new
TFO
(*
this
);
189
}
190
TraceFilter::TFO::~TFO
(
void
) {
191
heap
.
free
<
Filter
>(
f
,
n
);
192
}
193
194
TraceFilter::TraceFilter
(
void
) :
SharedHandle
(new
TFO
) {}
195
196
TraceFilter::TraceFilter
(
const
TFE
& e) :
SharedHandle
(new
TFO
(e)) {}
197
198
TraceFilter::TraceFilter
(
PropagatorGroup
g) :
SharedHandle
(new
TFO
(g)) {}
199
200
TraceFilter::TraceFilter
(
BrancherGroup
g) :
SharedHandle
(new
TFO
(g)) {}
201
202
TraceFilter::TraceFilter
(
const
TraceFilter
& tf) :
SharedHandle
(tf) {}
203
204
TraceFilter
&
205
TraceFilter::operator =
(
const
TraceFilter
& tf) {
206
return
static_cast<
TraceFilter
&
>
(
SharedHandle::operator =
(tf));
207
}
208
209
TraceFilter
TraceFilter::all
;
210
211
}
212
213
// STATISTICS: kernel-trace
kernel.hh
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::TraceFilter::TFO
The actual object storing the shared filters.
Definition:
trace-filter.hpp:140
Gecode::TFE::Node::w
char w
Which operations to consider for propagator groups.
Definition:
trace-filter.hpp:70
Gecode::TraceFilter::TFO::Filter::neg
bool neg
Whether the filter is negative.
Definition:
trace-filter.hpp:147
Gecode::ViewTraceInfo::OTHER
@ OTHER
Unknown.
Definition:
core.hpp:987
Gecode::TFE::negate
TFE negate(void) const
Return negated the expresssion.
Definition:
trace-filter.cpp:69
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::TFE::~TFE
~TFE(void)
Destructor.
Definition:
trace-filter.cpp:123
Gecode::SharedHandle::Object
The shared object.
Definition:
core.hpp:88
Gecode::TFE
Trace filter expressions.
Definition:
trace-filter.hpp:46
Gecode::ViewTraceInfo::PROPAGATOR
@ PROPAGATOR
A propagator is currently executing.
Definition:
core.hpp:981
Gecode::TFE::operator-=
TFE & operator-=(const TFE &e)
Add expression e as negative expression.
Definition:
trace-filter.cpp:119
Gecode::TraceFilter::TFO::fill
void fill(TFE::Node *n)
Fill the filters.
Definition:
trace-filter.cpp:163
Gecode::TFE::Node::use
unsigned int use
Nodes are reference counted.
Definition:
trace-filter.hpp:62
Gecode::TFE::TFE
TFE(void)
Initialize with no node.
Definition:
trace-filter.hpp:233
Gecode::TraceFilter::TraceFilter
TraceFilter(void)
Initialize without any filter.
Definition:
trace-filter.cpp:194
Gecode::TFE::Node::r
Node * r
Definition:
trace-filter.hpp:72
Gecode::TraceFilter::TFO::Filter::what
char what
One bit set for each operation type.
Definition:
trace-filter.hpp:149
Gecode
Gecode toplevel namespace
Gecode::Support::DynamicStack::push
void push(const T &x)
Push element x on top of stack.
Definition:
dynamic-stack.hpp:144
Gecode::BrancherGroup
Group of branchers.
Definition:
core.hpp:865
Gecode::TFE::Node
Node for trace filter expression.
Definition:
trace-filter.hpp:59
Gecode::TraceFilter::TFO::Filter::g
Group g
The filter group.
Definition:
trace-filter.hpp:145
Gecode::ViewTraceInfo::POST
@ POST
A post function is executing.
Definition:
core.hpp:985
Gecode::TFE::Node::t
NodeType t
Type of expression.
Definition:
trace-filter.hpp:64
Gecode::Support::DynamicStack::pop
T pop(void)
Pop topmost element from stack and return it.
Definition:
dynamic-stack.hpp:126
a
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Gecode::TraceFilter
Trace filters.
Definition:
trace-filter.hpp:137
Gecode::TFE::NT_NEGATE
@ NT_NEGATE
Negation of expression.
Definition:
trace-filter.hpp:55
Gecode::TraceFilter::all
static TraceFilter all
Default filter: without any filter.
Definition:
trace-filter.hpp:219
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition:
trace-filter.cpp:142
Gecode::TraceFilter::TFO::TFO
TFO(void)
Initialize without any filter and with fixpoint and done tracing.
Definition:
trace-filter.hpp:256
Gecode::Group
Group baseclass for controlling actors.
Definition:
core.hpp:741
Gecode::TraceFilter::TFO::copy
virtual Object * copy(void) const
Create a copy.
Definition:
trace-filter.cpp:187
Gecode::TFE::NT_GROUP
@ NT_GROUP
Propagator or brancher group.
Definition:
trace-filter.hpp:54
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition:
macros.hpp:60
Gecode::TraceFilter::TFO::n
int n
The number of filters.
Definition:
trace-filter.hpp:163
Gecode::operator-
FloatVal operator-(const FloatVal &x)
Definition:
val.hpp:172
Gecode::heap
Heap heap
The single global heap.
Definition:
heap.cpp:48
Gecode::neg
IntRelType neg(IntRelType irt)
Return negated relation type of irt.
Definition:
irt.hpp:56
Gecode::TFE::Node::decrement
bool decrement(void)
Decrement reference count and possibly free memory.
Definition:
trace-filter.cpp:47
Gecode::TFE::Node::g
Group g
Group.
Definition:
trace-filter.hpp:68
Gecode::TraceFilter::TFO::StackFrame::neg
bool neg
Whether it is negated.
Definition:
trace-filter.hpp:156
Gecode::TraceFilter::operator=
TraceFilter & operator=(const TraceFilter &tf)
Assignment operator.
Definition:
trace-filter.cpp:205
Gecode::Group::all
static Group all
Group of all actors.
Definition:
core.hpp:784
Gecode::TFE::NT_ADD
@ NT_ADD
More than one expression.
Definition:
trace-filter.hpp:56
Gecode::Heap::free
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Definition:
heap.hpp:461
Gecode::TraceFilter::TFO::StackFrame::n
TFE::Node * n
The node.
Definition:
trace-filter.hpp:154
Gecode::TFE::init
void init(Group g, char what)
Initialize with propagator group g and flags what.
Definition:
trace-filter.cpp:60
Gecode::Support::DynamicStack::empty
bool empty(void) const
Test whether stack is empty.
Definition:
dynamic-stack.hpp:152
Gecode::Support::DynamicStack
Stack with arbitrary number of elements.
Definition:
dynamic-stack.hpp:46
Gecode::SharedHandle::operator=
SharedHandle & operator=(const SharedHandle &sh)
Assignment operator maintaining reference count.
Definition:
core.hpp:3120
Gecode::TraceFilter::TFO::Filter
Filter information.
Definition:
trace-filter.hpp:143
Gecode::PropagatorGroup
Group of propagators.
Definition:
core.hpp:794
Gecode::SharedHandle
The shared handle.
Definition:
core.hpp:79
Gecode::TraceFilter::TFO::~TFO
virtual ~TFO(void)
Destructor.
Definition:
trace-filter.cpp:190
Gecode::TFE::Node::n
int n
Number of leaf groups.
Definition:
trace-filter.hpp:66
Gecode::ViewTraceInfo::BRANCHER
@ BRANCHER
A brancher is executing.
Definition:
core.hpp:983
Gecode::TFE::n
Node * n
Pointer to trace filter expression node.
Definition:
trace-filter.hpp:80
Gecode::propagator
TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Definition:
trace-filter.cpp:135
Gecode::TraceFilter::TFO::StackFrame::StackFrame
StackFrame(void)
Default constructor.
Definition:
trace-filter.cpp:157
Gecode::TFE::other
static TFE other(void)
Expression for other than propagator, brancher, or post.
Definition:
trace-filter.cpp:86
Gecode::TFE::operator=
TFE & operator=(const TFE &e)
Assignment operator.
Definition:
trace-filter.cpp:97
Gecode::TFE::operator+=
TFE & operator+=(const TFE &e)
Add expression e.
Definition:
trace-filter.cpp:108
Gecode::TraceFilter::TFO::StackFrame
Definition:
trace-filter.hpp:151
Gecode::TFE::Node::l
Node * l
Subexpressions.
Definition:
trace-filter.hpp:72
Gecode::TraceFilter::TFO::f
Filter * f
The filters.
Definition:
trace-filter.hpp:165