Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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
34namespace Gecode { namespace Search {
35
38 public:
40 static void engine(SearchTracer* tracer,
41 SearchTracer::EngineType t, unsigned int n);
42 };
43
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 };
69
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);
104 };
105
108 public:
110 class ID {
111 public:
113 ID(void);
115 ID(unsigned int id);
117 operator unsigned int(void) const;
118 };
119
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);
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
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 */
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
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
295
296 forceinline void
299
301 NoTraceRecorder::operator bool(void) const {
302 return false;
303 }
304
305}}
306
307// STATISTICS: search-trace
Support for tracing search.
Definition search.hh:187
EngineType
Which type of engine.
Definition search.hh:193
void invalidate(void)
Invalidate edge information.
EdgeTraceRecorder(SearchTracer *t)
Initialize.
SearchTracer::EdgeInfo _ei
Edge information.
SearchTracer::EdgeInfo * ei(void)
Provide access to edge information.
unsigned int wid(void) const
Return worker id.
void skip(const SearchTracer::EdgeInfo &ei)
The engine skips an edge.
unsigned int nid(void)
Generate new node id.
void done(void)
The worker is done.
void round(void)
The workers goes to a next round (restart or next iteration in LDS)
void invalidate(void)
Invalidate edge information.
void worker(void)
Register worker.
void node(const SearchTracer::EdgeInfo &ei, const SearchTracer::NodeInfo &ni)
The engine creates a new node with information ei and ni.
void engine(SearchTracer::EngineType t, unsigned int n)
Register engine.
SearchTracer::EdgeInfo * ei(void)
Provide access to edge information.
NoTraceRecorder(SearchTracer *t)
Initialize.
unsigned int _id
The actual identifier.
SearchTracer & tracer
The actual tracer.
unsigned int wid(void) const
Return worker id.
void worker(void)
Register worker.
unsigned int _nid
The next free node id.
unsigned int _eid
The engine id.
void engine(SearchTracer::EngineType t, unsigned int n)
Register engine.
void round(void)
The workers goes to a next round (restart or next iteration in LDS)
void done(void)
The worker is done.
void skip(const SearchTracer::EdgeInfo &ei)
The engine skips an edge.
TraceRecorder(SearchTracer *t)
Initialize.
void node(const SearchTracer::EdgeInfo &ei, const SearchTracer::NodeInfo &ni)
The engine creates a new node with information ei and ni.
unsigned int nid(void)
Generate new node id.
unsigned int _wid
The worker id.
Recorder for engine events (for access control)
static void engine(SearchTracer *tracer, SearchTracer::EngineType t, unsigned int n)
Register engine.
Search engines
Gecode toplevel namespace
#define forceinline
Definition config.hpp:194