Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
tracer.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, 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
34namespace Gecode {
35
37 class TracerBase : public HeapAllocated {
38 protected:
42 };
43
44 template<class View> class ViewTraceRecorder;
45
50 template<class View>
51 class ViewTracer : public TracerBase {
52 template<class ViewForTraceRecorder> friend class ViewTraceRecorder;
53 private:
60 void _init(const Space& home, const ViewTraceRecorder<View>& t);
67 void _prune(const Space& home, const ViewTraceRecorder<View>& t,
68 const ViewTraceInfo& vti,
69 int i, typename TraceTraits<View>::TraceDelta& d);
76 void _fail(const Space& home, const ViewTraceRecorder<View>& t);
82 void _fix(const Space& home, const ViewTraceRecorder<View>& t);
88 void _done(const Space& home, const ViewTraceRecorder<View>& t);
89 public:
98 virtual void init(const Space& home,
99 const ViewTraceRecorder<View>& t) = 0;
109 virtual void prune(const Space& home,
111 const ViewTraceInfo& vti,
112 int i, typename TraceTraits<View>::TraceDelta& d) = 0;
119 virtual void fail(const Space& home,
120 const ViewTraceRecorder<View>& t) = 0;
128 virtual void fix(const Space& home,
129 const ViewTraceRecorder<View>& t) = 0;
136 virtual void done(const Space& home,
137 const ViewTraceRecorder<View>& t) = 0;
139 virtual ~ViewTracer(void);
140 };
141
142
143
144
149 class Tracer : public TracerBase {
150 friend class Space;
151 friend class PostInfo;
152 private:
159 void _propagate(const Space& home, const PropagateTraceInfo& pti);
166 void _commit(const Space& home, const CommitTraceInfo& cti);
173 void _post(const Space& home, const PostTraceInfo& pti);
174 public:
176 Tracer(void);
183 virtual void propagate(const Space& home,
184 const PropagateTraceInfo& pti) = 0;
191 virtual void commit(const Space& home,
192 const CommitTraceInfo& cti) = 0;
199 virtual void post(const Space& home,
200 const PostTraceInfo& pti) = 0;
202 virtual ~Tracer(void);
203 };
204
205
211 protected:
213 std::ostream& os;
214 public:
216 StdTracer(std::ostream& os = std::cerr);
223 virtual void propagate(const Space& home,
224 const PropagateTraceInfo& pti);
231 virtual void commit(const Space& home,
232 const CommitTraceInfo& cti);
239 virtual void post(const Space& home,
240 const PostTraceInfo& pti);
243 };
244
245
246 /*
247 * View tracer
248 */
249
250 template<class View>
254
255 template<class View>
256 forceinline void
257 ViewTracer<View>::_init(const Space& home,
258 const ViewTraceRecorder<View>& t) {
259 Support::Lock l(m);
260 init(home,t);
261 }
262 template<class View>
263 forceinline void
264 ViewTracer<View>::_prune(const Space& home,
265 const ViewTraceRecorder<View>& t,
266 const ViewTraceInfo& vti,
267 int i, typename TraceTraits<View>::TraceDelta& d) {
268 Support::Lock l(m);
269 prune(home,t,vti,i,d);
270 }
271 template<class View>
272 forceinline void
273 ViewTracer<View>::_fail(const Space& home,
274 const ViewTraceRecorder<View>& t) {
275 Support::Lock l(m);
276 fail(home,t);
277 }
278 template<class View>
279 forceinline void
280 ViewTracer<View>::_fix(const Space& home,
281 const ViewTraceRecorder<View>& t) {
282 Support::Lock l(m);
283 fix(home,t);
284 }
285 template<class View>
286 forceinline void
287 ViewTracer<View>::_done(const Space& home,
288 const ViewTraceRecorder<View>& t) {
289 Support::Lock l(m);
290 done(home,t);
291 }
292
293 template<class View>
297
298
299 /*
300 * Tracer
301 */
302
305 }
306
307 forceinline void
308 Tracer::_propagate(const Space& home,
309 const PropagateTraceInfo& pti) {
310 Support::Lock l(m);
311 propagate(home,pti);
312 }
313 forceinline void
314 Tracer::_commit(const Space& home,
315 const CommitTraceInfo& cti) {
316 Support::Lock l(m);
317 commit(home,cti);
318 }
319 forceinline void
320 Tracer::_post(const Space& home,
321 const PostTraceInfo& pti) {
322 Support::Lock l(m);
323 post(home,pti);
324 }
325
328 }
329
330}
331
332// STATISTICS: kernel-trace
Commit trace information.
Definition core.hpp:1007
Base class for heap allocated objects.
Definition heap.hpp:340
Post trace information.
Definition core.hpp:1034
Propagate trace information.
Definition core.hpp:971
Computation spaces.
Definition core.hpp:1744
std::ostream & os
Output stream to use.
Definition tracer.hpp:213
StdTracer(std::ostream &os=std::cerr)
Initialize with output stream os.
Definition tracer.cpp:41
virtual void propagate(const Space &home, const PropagateTraceInfo &pti)
Propagate function.
Definition tracer.cpp:44
static StdTracer def
Default tracer (printing to std::cerr)
Definition tracer.hpp:242
virtual void commit(const Space &home, const CommitTraceInfo &cti)
Commit function.
Definition tracer.cpp:50
virtual void post(const Space &home, const PostTraceInfo &pti)
Post function.
Definition tracer.cpp:59
A lock as a scoped frontend for a mutex.
Definition thread.hpp:191
A mutex for mutual exclausion among several threads.
Definition thread.hpp:96
Traits for tracing.
Definition traits.hpp:49
Class to provide synchronization.
Definition tracer.hpp:37
static Support::Mutex m
Mutex to provide synchronization.
Definition tracer.hpp:41
virtual void commit(const Space &home, const CommitTraceInfo &cti)=0
Commit function.
friend class Space
Definition tracer.hpp:150
virtual void propagate(const Space &home, const PropagateTraceInfo &pti)=0
Propagate function.
virtual ~Tracer(void)
Destructor.
Definition tracer.hpp:327
friend class PostInfo
Definition tracer.hpp:151
Tracer(void)
Constructor.
Definition tracer.hpp:304
virtual void post(const Space &home, const PostTraceInfo &pti)=0
Post function.
View trace information.
Definition core.hpp:910
Propagator for recording view trace information.
Definition recorder.hpp:60
virtual void done(const Space &home, const ViewTraceRecorder< View > &t)=0
Done function.
virtual void prune(const Space &home, const ViewTraceRecorder< View > &t, const ViewTraceInfo &vti, int i, typename TraceTraits< View >::TraceDelta &d)=0
Prune function.
ViewTracer(void)
Constructor.
Definition tracer.hpp:252
virtual void init(const Space &home, const ViewTraceRecorder< View > &t)=0
Init function.
virtual void fail(const Space &home, const ViewTraceRecorder< View > &t)=0
Fail function.
virtual ~ViewTracer(void)
Destructor.
Definition tracer.hpp:295
virtual void fix(const Space &home, const ViewTraceRecorder< View > &t)=0
Fixpoint function.
#define GECODE_KERNEL_EXPORT
Definition kernel.hh:70
ModEvent prune(Space &home, View x, int v)
Exclude value \v from variable view \x.
Gecode toplevel namespace
#define forceinline
Definition config.hpp:194