Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
trace-recorder.hpp
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, 2017
8  *
9  * Last modified:
10  * $Date$ by $Author$
11  * $Revision$
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 namespace Gecode { namespace Search {
39 
42  public:
44  static void engine(SearchTracer* tracer,
45  SearchTracer::EngineType t, unsigned int n);
46  };
47 
49  class TraceRecorder {
50  protected:
54  unsigned int _eid;
56  unsigned int _wid;
58  unsigned int _nid;
59  public:
61  class ID {
62  protected:
64  unsigned int _id;
65  public:
67  ID(void);
69  ID(unsigned int id);
71  operator unsigned int(void) const;
72  };
76  void engine(SearchTracer::EngineType t, unsigned int n);
78  void worker(void);
80  unsigned int nid(void);
82  unsigned int wid(void) const;
84  void round(void);
86  void skip(const SearchTracer::EdgeInfo& ei);
88  void node(const SearchTracer::EdgeInfo& ei,
89  const SearchTracer::NodeInfo& ni);
91  void done(void);
93  operator bool(void) const;
94  };
95 
98  protected:
101  public:
105  void invalidate(void);
107  SearchTracer::EdgeInfo* ei(void);
108  };
109 
112  public:
114  class ID {
115  public:
117  ID(void);
119  ID(unsigned int id);
121  operator unsigned int(void) const;
122  };
126  void engine(SearchTracer::EngineType t, unsigned int n);
128  void worker(void);
130  unsigned int wid(void) const;
132  unsigned int nid(void);
134  void invalidate(void);
136  SearchTracer::EdgeInfo* ei(void);
138  void round(void);
140  void skip(const SearchTracer::EdgeInfo& ei);
142  void node(const SearchTracer::EdgeInfo& ei,
143  const SearchTracer::NodeInfo& ni);
145  void done(void);
147  operator bool(void) const;
148  };
149 
150 
151  /*
152  * Recorder for engine events
153  *
154  */
155  forceinline void
157  SearchTracer::EngineType t, unsigned int n) {
158  if (tracer) tracer->engine(t,n);
159  }
160 
161 
162  /*
163  * Simple trace recorder for a search tracer
164  *
165  */
168 
170  TraceRecorder::ID::ID(unsigned int id) : _id(id) {}
171 
173  TraceRecorder::ID::operator unsigned int(void) const {
174  return _id;
175  }
176 
179  : tracer(*t), _eid(0U), _wid(0U), _nid(0U) {}
180 
181  forceinline void
183  tracer.engine(t,n);
184  }
185 
186  forceinline void
188  tracer.worker(_wid,_eid);
189  }
190 
191  forceinline unsigned int
193  return _nid++;
194  }
195 
196  forceinline unsigned int
197  TraceRecorder::wid(void) const {
198  return _wid;
199  }
200 
201  forceinline void
203  tracer._round(_eid);
204  }
205 
206  forceinline void
208  tracer._skip(ei);
209  }
210 
211  forceinline void
213  const SearchTracer::NodeInfo& ni) {
214  tracer._node(ei,ni);
215  }
216 
217  forceinline void
219  tracer.worker();
220  }
221 
223  TraceRecorder::operator bool(void) const {
224  return true;
225  }
226 
227 
228  /*
229  * Recorder for a search tracer with edge information
230  *
231  */
234  : TraceRecorder(t) {}
235 
236  forceinline void
238  _ei.invalidate();
239  }
240 
243  return &_ei;
244  }
245 
246 
247  /*
248  * Empty trace recorder
249  *
250  */
253 
255  NoTraceRecorder::ID::ID(unsigned int) {}
256 
258  NoTraceRecorder::ID::operator unsigned int(void) const {
259  return 0U;
260  }
261 
264 
265  forceinline void
267 
268  forceinline void
270 
271  forceinline unsigned int
272  NoTraceRecorder::wid(void) const {
273  return 0U;
274  }
275 
276  forceinline unsigned int
278  return 0U;
279  }
280 
281  forceinline void
283 
286  return nullptr;
287  }
288 
289  forceinline void
291 
292  forceinline void
294 
295  forceinline void
297  const SearchTracer::NodeInfo&) {
298  }
299 
300  forceinline void
302  }
303 
305  NoTraceRecorder::operator bool(void) const {
306  return false;
307  }
308 
309 }}
310 
311 // STATISTICS: search-trace
Edge information.
Definition: search.hh:244
NodeType t
Type of node.
Definition: bool-expr.cpp:234
SearchTracer::EdgeInfo _ei
Edge information.
unsigned int nid(void)
Generate new node id.
void engine(SearchTracer::EngineType t, unsigned int n)
Register engine.
void done(void)
The worker is done.
void invalidate(void)
Invalidate edge information.
void engine(SearchTracer::EngineType t, unsigned int n)
Register engine.
#define forceinline
Definition: config.hpp:182
EngineType
Which type of engine.
Definition: search.hh:195
unsigned int wid(void) const
Return worker id.
void node(const SearchTracer::EdgeInfo &ei, const SearchTracer::NodeInfo &ni)
The engine creates a new node with information ei and ni.
SearchTracer & tracer
The actual tracer.
void worker(void)
Register worker.
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Recorder for a search tracer with edge information.
EdgeTraceRecorder(SearchTracer *t)
Initialize.
SearchTracer::EdgeInfo * ei(void)
Provide access to edge information.
Simple recorder for a search tracer.
NoTraceRecorder(SearchTracer *t)
Initialize.
Class for storing node identifiers.
Class for storing identifiers.
void round(void)
The workers goes to a next round (restart or next iteration in LDS)
Support for tracing search.
Definition: search.hh:189
void round(void)
The workers goes to a next round (restart or next iteration in LDS)
static void engine(SearchTracer *tracer, SearchTracer::EngineType t, unsigned int n)
Register engine.
unsigned int _id
The actual identifier.
unsigned int nid(void)
Generate new node id.
void skip(const SearchTracer::EdgeInfo &ei)
The engine skips an edge.
unsigned int _eid
The engine id.
void done(void)
The worker is done.
unsigned int _nid
The next free node id.
unsigned int wid(void) const
Return worker id.
TraceRecorder(SearchTracer *t)
Initialize.
Node information.
Definition: search.hh:284
void worker(void)
Register worker.
Recorder for engine events (for access control)
Gecode toplevel namespace
void invalidate(void)
Invalidate edge information (for stealing)
Definition: tracer.hpp:106
void node(const SearchTracer::EdgeInfo &ei, const SearchTracer::NodeInfo &ni)
The engine creates a new node with information ei and ni.
void invalidate(void)
Invalidate edge information.
unsigned int _wid
The worker id.
void skip(const SearchTracer::EdgeInfo &ei)
The engine skips an edge.
SearchTracer::EdgeInfo * ei(void)
Provide access to edge information.