Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
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 
34 namespace Gecode {
35 
37  class TracerBase : public HeapAllocated {
38  protected:
41  static Support::Mutex m;
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:
91  ViewTracer(void);
98  virtual void init(const Space& home,
99  const ViewTraceRecorder<View>& t) = 0;
109  virtual void prune(const Space& home,
110  const ViewTraceRecorder<View>& t,
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  private:
158  void _propagate(const Space& home, const PropagateTraceInfo& pti);
165  void _commit(const Space& home, const CommitTraceInfo& cti);
166  public:
168  Tracer(void);
175  virtual void propagate(const Space& home,
176  const PropagateTraceInfo& pti) = 0;
183  virtual void commit(const Space& home,
184  const CommitTraceInfo& cti) = 0;
186  virtual ~Tracer(void);
187  };
188 
189 
195  protected:
197  std::ostream& os;
198  public:
200  StdTracer(std::ostream& os = std::cerr);
207  virtual void propagate(const Space& home,
208  const PropagateTraceInfo& pti);
215  virtual void commit(const Space& home,
216  const CommitTraceInfo& cti);
218  static StdTracer def;
219  };
220 
221 
222  /*
223  * View tracer
224  */
225 
226  template<class View>
229  }
230 
231  template<class View>
232  forceinline void
233  ViewTracer<View>::_init(const Space& home,
234  const ViewTraceRecorder<View>& t) {
235  m.acquire();
236  init(home,t);
237  m.release();
238  }
239  template<class View>
240  forceinline void
241  ViewTracer<View>::_prune(const Space& home,
242  const ViewTraceRecorder<View>& t,
243  const ViewTraceInfo& vti,
244  int i, typename TraceTraits<View>::TraceDelta& d) {
245  m.acquire();
246  prune(home,t,vti,i,d);
247  m.release();
248  }
249  template<class View>
250  forceinline void
251  ViewTracer<View>::_fail(const Space& home,
252  const ViewTraceRecorder<View>& t) {
253  m.acquire();
254  fail(home,t);
255  m.release();
256  }
257  template<class View>
258  forceinline void
259  ViewTracer<View>::_fix(const Space& home,
260  const ViewTraceRecorder<View>& t) {
261  m.acquire();
262  fix(home,t);
263  m.release();
264  }
265  template<class View>
266  forceinline void
267  ViewTracer<View>::_done(const Space& home,
268  const ViewTraceRecorder<View>& t) {
269  m.acquire();
270  done(home,t);
271  m.release();
272  }
273 
274  template<class View>
277  }
278 
279 
280  /*
281  * Tracer
282  */
283 
286  }
287 
288  forceinline void
289  Tracer::_propagate(const Space& home,
290  const PropagateTraceInfo& pti) {
291  m.acquire();
292  propagate(home,pti);
293  m.release();
294  }
295  forceinline void
296  Tracer::_commit(const Space& home,
297  const CommitTraceInfo& cti) {
298  m.acquire();
299  commit(home,cti);
300  m.release();
301  }
302 
305  }
306 
307 }
308 
309 // STATISTICS: kernel-trace
NodeType t
Type of node.
Definition: bool-expr.cpp:230
Tracer that process view trace information.
Definition: tracer.hpp:51
View trace information.
Definition: core.hpp:905
Class to provide synchronization.
Definition: tracer.hpp:37
void acquire(void)
Acquire the mutex and possibly block.
Definition: none.hpp:42
virtual ~ViewTracer(void)
Destructor.
Definition: tracer.hpp:276
static StdTracer def
Default tracer (printing to std::cerr)
Definition: tracer.hpp:218
#define forceinline
Definition: config.hpp:185
Computation spaces.
Definition: core.hpp:1701
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:264
ViewTracer(void)
Constructor.
Definition: tracer.hpp:228
static Support::Mutex m
Mutex to provide synchronization.
Definition: tracer.hpp:41
A mutex for mutual exclausion among several threads.
Definition: thread.hpp:96
Gecode::IntSet d(v, 7)
void release(void)
Release the mutex.
Definition: none.hpp:48
virtual ~Tracer(void)
Destructor.
Definition: tracer.hpp:304
Gecode::IntArgs i(4, 1, 2, 3, 4)
Tracer(void)
Constructor.
Definition: tracer.hpp:285
Commit trace information.
Definition: core.hpp:995
#define GECODE_KERNEL_EXPORT
Definition: kernel.hh:70
Propagate trace information.
Definition: core.hpp:959
Traits for tracing.
Definition: traits.hpp:49
Propagator for recording view trace information.
Definition: recorder.hpp:59
Tracer.
Definition: tracer.hpp:149
Default tracer.
Definition: tracer.hpp:194
Gecode toplevel namespace
std::ostream & os
Output stream to use.
Definition: tracer.hpp:197
Base class for heap allocated objects.
Definition: heap.hpp:340