Generated on Tue Mar 24 2020 14:04:04 for Gecode by doxygen 1.8.17
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  * 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 namespace Gecode { namespace Search {
35 
38  public:
40  static void engine(SearchTracer* tracer,
41  SearchTracer::EngineType t, unsigned int n);
42  };
43 
45  class TraceRecorder {
46  protected:
50  unsigned int _eid;
52  unsigned int _wid;
54  unsigned int _nid;
55  public:
57  class ID {
58  protected:
60  unsigned int _id;
61  public:
63  ID(void);
65  ID(unsigned int id);
67  operator unsigned int(void) const;
68  };
72  void engine(SearchTracer::EngineType t, unsigned int n);
74  void worker(void);
76  unsigned int nid(void);
78  unsigned int wid(void) const;
80  void round(void);
82  void skip(const SearchTracer::EdgeInfo& ei);
84  void node(const SearchTracer::EdgeInfo& ei,
85  const SearchTracer::NodeInfo& ni);
87  void done(void);
89  operator bool(void) const;
90  };
91 
94  protected:
97  public:
101  void invalidate(void);
103  SearchTracer::EdgeInfo* ei(void);
104  };
105 
108  public:
110  class ID {
111  public:
113  ID(void);
115  ID(unsigned int id);
117  operator unsigned int(void) const;
118  };
122  void engine(SearchTracer::EngineType t, unsigned int n);
124  void worker(void);
126  unsigned int wid(void) const;
128  unsigned int nid(void);
130  void invalidate(void);
132  SearchTracer::EdgeInfo* ei(void);
134  void round(void);
136  void skip(const SearchTracer::EdgeInfo& ei);
138  void node(const SearchTracer::EdgeInfo& ei,
139  const SearchTracer::NodeInfo& ni);
141  void done(void);
143  operator bool(void) const;
144  };
145 
146 
147  /*
148  * Recorder for engine events
149  *
150  */
151  forceinline void
153  SearchTracer::EngineType t, unsigned int n) {
154  if (tracer) tracer->engine(t,n);
155  }
156 
157 
158  /*
159  * Simple trace recorder for a search tracer
160  *
161  */
164 
166  TraceRecorder::ID::ID(unsigned int id) : _id(id) {}
167 
169  TraceRecorder::ID::operator unsigned int(void) const {
170  return _id;
171  }
172 
175  : tracer(*t), _eid(0U), _wid(0U), _nid(0U) {}
176 
177  forceinline void
179  tracer.engine(t,n);
180  }
181 
182  forceinline void
184  tracer.worker(_wid,_eid);
185  }
186 
187  forceinline unsigned int
189  return _nid++;
190  }
191 
192  forceinline unsigned int
193  TraceRecorder::wid(void) const {
194  return _wid;
195  }
196 
197  forceinline void
199  tracer._round(_eid);
200  }
201 
202  forceinline void
204  tracer._skip(ei);
205  }
206 
207  forceinline void
209  const SearchTracer::NodeInfo& ni) {
210  tracer._node(ei,ni);
211  }
212 
213  forceinline void
215  tracer.worker();
216  }
217 
219  TraceRecorder::operator bool(void) const {
220  return true;
221  }
222 
223 
224  /*
225  * Recorder for a search tracer with edge information
226  *
227  */
230  : TraceRecorder(t) {}
231 
232  forceinline void
234  _ei.invalidate();
235  }
236 
239  return &_ei;
240  }
241 
242 
243  /*
244  * Empty trace recorder
245  *
246  */
249 
251  NoTraceRecorder::ID::ID(unsigned int) {}
252 
254  NoTraceRecorder::ID::operator unsigned int(void) const {
255  return 0U;
256  }
257 
260 
261  forceinline void
263 
264  forceinline void
266 
267  forceinline unsigned int
268  NoTraceRecorder::wid(void) const {
269  return 0U;
270  }
271 
272  forceinline unsigned int
274  return 0U;
275  }
276 
277  forceinline void
279 
282  return nullptr;
283  }
284 
285  forceinline void
287 
288  forceinline void
290 
291  forceinline void
293  const SearchTracer::NodeInfo&) {
294  }
295 
296  forceinline void
298  }
299 
301  NoTraceRecorder::operator bool(void) const {
302  return false;
303  }
304 
305 }}
306 
307 // STATISTICS: search-trace
void worker(void)
Register worker.
unsigned int wid(void) const
Return worker id.
unsigned int nid(void)
Generate new node id.
void invalidate(void)
Invalidate edge information.
void engine(SearchTracer::EngineType t, unsigned int n)
Register engine.
Class for storing node identifiers.
NodeType t
Type of node.
Definition: bool-expr.cpp:230
void invalidate(void)
Invalidate edge information (for stealing)
Definition: tracer.hpp:102
Simple recorder for a search tracer.
Recorder for a search tracer with edge information.
void round(void)
The workers goes to a next round (restart or next iteration in LDS)
SearchTracer::EdgeInfo _ei
Edge information.
Gecode toplevel namespace
Class for storing identifiers.
unsigned int _nid
The next free node id.
Node information.
Definition: search.hh:282
SearchTracer::EdgeInfo * ei(void)
Provide access to edge information.
Recorder for engine events (for access control)
NoTraceRecorder(SearchTracer *t)
Initialize.
void node(const SearchTracer::EdgeInfo &ei, const SearchTracer::NodeInfo &ni)
The engine creates a new node with information ei and ni.
EdgeTraceRecorder(SearchTracer *t)
Initialize.
void round(void)
The workers goes to a next round (restart or next iteration in LDS)
void skip(const SearchTracer::EdgeInfo &ei)
The engine skips an edge.
ID(void)
Do not initialize.
SearchTracer::EdgeInfo * ei(void)
Provide access to edge information.
Edge information.
Definition: search.hh:242
unsigned int nid(void)
Generate new node id.
void done(void)
The worker is done.
void worker(void)
Register worker.
SearchTracer & tracer
The actual tracer.
void done(void)
The worker is done.
unsigned int _eid
The engine id.
unsigned int wid(void) const
Return worker id.
void skip(const SearchTracer::EdgeInfo &ei)
The engine skips an edge.
TraceRecorder(SearchTracer *t)
Initialize.
#define forceinline
Definition: config.hpp:185
Support for tracing search.
Definition: search.hh:187
unsigned int _wid
The worker id.
void node(const SearchTracer::EdgeInfo &ei, const SearchTracer::NodeInfo &ni)
The engine creates a new node with information ei and ni.
Empty trace recorder.
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
void engine(SearchTracer::EngineType t, unsigned int n)
Register engine.
EngineType
Which type of engine.
Definition: search.hh:193
ID(void)
Do not initialize.
static void engine(SearchTracer *tracer, SearchTracer::EngineType t, unsigned int n)
Register engine.
unsigned int _id
The actual identifier.
void invalidate(void)
Invalidate edge information.