Generated on Tue Jan 19 2021 06:15:49 for Gecode by doxygen 1.8.13
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
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 
75  }
76 
78  init(g,(1 << ViewTraceInfo::BRANCHER));
79  }
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&
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
132  TFE e;
133  e.init(g,(1 << ViewTraceInfo::PROPAGATOR));
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 
197  TraceFilter&
199  return static_cast<TraceFilter&>(SharedHandle::operator =(tf));
200  }
201 
203 
204 }
205 
206 // 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.
static TraceFilter all
Default filter: without any filter.
Definition: filter.hpp:210
TFE & operator+=(const TFE &e)
Add expression e.
Definition: filter.cpp:104
More than one expression.
Definition: filter.hpp:52
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
The actual object storing the shared filters.
Definition: filter.hpp:136
TraceFilter & operator=(const TraceFilter &tf)
Assignment operator.
Definition: filter.cpp:198
virtual ~TFO(void)
Destructor.
Definition: filter.cpp:183
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
Handle to region.
Definition: region.hpp:55
#define forceinline
Definition: config.hpp:185
void init(Group g, char what)
Initialize with propagator group g and flags what.
Definition: filter.cpp:56
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})
Node for trace filter expression.
Definition: filter.hpp:55
Filter * f
The filters.
Definition: filter.hpp:161
T pop(void)
Pop topmost element from stack and return it.
SharedHandle & operator=(const SharedHandle &sh)
Assignment operator maintaining reference count.
NodeType t
Type of expression.
Definition: filter.hpp:60
TraceFilter(void)
Initialize without any filter.
Definition: filter.cpp:187
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
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Definition: heap.hpp:457
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
Stack with arbitrary number of elements.
char what
One bit set for each operation type.
Definition: filter.hpp:145
StackFrame(void)
Default constructor.
Definition: filter.cpp:153
bool neg
Whether it is negated.
Definition: filter.hpp:152
Gecode toplevel namespace
static Group all
Group of all actors.
Definition: core.hpp:715
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
bool empty(void) const
Test whether stack is empty.
#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
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
Group g
Group.
Definition: filter.hpp:64
void push(const T &x)
Push element x on top of stack.
Group g
The filter group.
Definition: filter.hpp:141