Generated on Tue Jan 28 2020 00:00:00 for Gecode by doxygen 1.8.17
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
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 
79  }
80 
82  init(g,(1 << ViewTraceInfo::BRANCHER));
83  }
84 
85  TFE
86  TFE::other(void) {
87  TFE e;
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
136  TFE e;
137  e.init(g,(1 << ViewTraceInfo::PROPAGATOR));
138  return e;
139  }
140 
141  TFE
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 
160  : n(n0), neg(neg0) {}
161 
162  void
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 
188  return new TFO(*this);
189  }
191  heap.free<Filter>(f,n);
192  }
193 
195 
197 
199 
201 
203 
204  TraceFilter&
206  return static_cast<TraceFilter&>(SharedHandle::operator =(tf));
207  }
208 
210 
211 }
212 
213 // STATISTICS: kernel-trace
#define forceinline
Definition: config.hpp:173
The actual object storing the shared filters.
char w
Which operations to consider for propagator groups.
bool neg
Whether the filter is negative.
@ OTHER
Unknown.
Definition: core.hpp:987
TFE negate(void) const
Return negated the expresssion.
Gecode::IntArgs i(4, 1, 2, 3, 4)
~TFE(void)
Destructor.
The shared object.
Definition: core.hpp:88
Trace filter expressions.
@ PROPAGATOR
A propagator is currently executing.
Definition: core.hpp:981
TFE & operator-=(const TFE &e)
Add expression e as negative expression.
void fill(TFE::Node *n)
Fill the filters.
unsigned int use
Nodes are reference counted.
TFE(void)
Initialize with no node.
TraceFilter(void)
Initialize without any filter.
Node * r
char what
One bit set for each operation type.
Gecode toplevel namespace
void push(const T &x)
Push element x on top of stack.
Group of branchers.
Definition: core.hpp:865
Node for trace filter expression.
Group g
The filter group.
@ POST
A post function is executing.
Definition: core.hpp:985
NodeType t
Type of expression.
T pop(void)
Pop topmost element from stack and return it.
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Trace filters.
@ NT_NEGATE
Negation of expression.
static TraceFilter all
Default filter: without any filter.
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
TFO(void)
Initialize without any filter and with fixpoint and done tracing.
Group baseclass for controlling actors.
Definition: core.hpp:741
virtual Object * copy(void) const
Create a copy.
@ NT_GROUP
Propagator or brancher group.
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
int n
The number of filters.
FloatVal operator-(const FloatVal &x)
Definition: val.hpp:172
Heap heap
The single global heap.
Definition: heap.cpp:48
IntRelType neg(IntRelType irt)
Return negated relation type of irt.
Definition: irt.hpp:56
bool decrement(void)
Decrement reference count and possibly free memory.
Group g
Group.
bool neg
Whether it is negated.
TraceFilter & operator=(const TraceFilter &tf)
Assignment operator.
static Group all
Group of all actors.
Definition: core.hpp:784
@ NT_ADD
More than one expression.
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Definition: heap.hpp:461
TFE::Node * n
The node.
void init(Group g, char what)
Initialize with propagator group g and flags what.
bool empty(void) const
Test whether stack is empty.
Stack with arbitrary number of elements.
SharedHandle & operator=(const SharedHandle &sh)
Assignment operator maintaining reference count.
Definition: core.hpp:3120
Filter information.
Group of propagators.
Definition: core.hpp:794
The shared handle.
Definition: core.hpp:79
virtual ~TFO(void)
Destructor.
int n
Number of leaf groups.
@ BRANCHER
A brancher is executing.
Definition: core.hpp:983
Node * n
Pointer to trace filter expression node.
TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
StackFrame(void)
Default constructor.
static TFE other(void)
Expression for other than propagator, brancher, or post.
TFE & operator=(const TFE &e)
Assignment operator.
TFE & operator+=(const TFE &e)
Add expression e.
Node * l
Subexpressions.
Filter * f
The filters.