Generated on Wed Jan 24 2018 21:22:26 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  * Last modified:
10  * $Date: 2017-03-17 23:04:57 +0100 (Fri, 17 Mar 2017) $ by $Author: schulte $
11  * $Revision: 15597 $
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 {
39 
41  class TracerBase : public HeapAllocated {
42  protected:
45  static Support::Mutex m;
46  };
47 
48  template<class View> class ViewTraceRecorder;
49 
54  template<class View>
55  class ViewTracer : public TracerBase {
56  template<class ViewForTraceRecorder> friend class ViewTraceRecorder;
57  private:
64  void _init(const Space& home, const ViewTraceRecorder<View>& t);
71  void _prune(const Space& home, const ViewTraceRecorder<View>& t,
72  const ViewTraceInfo& vti,
73  int i, typename TraceTraits<View>::TraceDelta& d);
80  void _fail(const Space& home, const ViewTraceRecorder<View>& t);
86  void _fix(const Space& home, const ViewTraceRecorder<View>& t);
92  void _done(const Space& home, const ViewTraceRecorder<View>& t);
93  public:
95  ViewTracer(void);
102  virtual void init(const Space& home,
103  const ViewTraceRecorder<View>& t) = 0;
113  virtual void prune(const Space& home,
114  const ViewTraceRecorder<View>& t,
115  const ViewTraceInfo& vti,
116  int i, typename TraceTraits<View>::TraceDelta& d) = 0;
123  virtual void fail(const Space& home,
124  const ViewTraceRecorder<View>& t) = 0;
132  virtual void fix(const Space& home,
133  const ViewTraceRecorder<View>& t) = 0;
140  virtual void done(const Space& home,
141  const ViewTraceRecorder<View>& t) = 0;
143  virtual ~ViewTracer(void);
144  };
145 
146 
147 
148 
153  class Tracer : public TracerBase {
154  friend class Space;
155  private:
162  void _propagate(const Space& home, const PropagateTraceInfo& pti);
169  void _commit(const Space& home, const CommitTraceInfo& cti);
170  public:
172  Tracer(void);
179  virtual void propagate(const Space& home,
180  const PropagateTraceInfo& pti) = 0;
187  virtual void commit(const Space& home,
188  const CommitTraceInfo& cti) = 0;
190  virtual ~Tracer(void);
191  };
192 
193 
199  protected:
201  std::ostream& os;
202  public:
204  StdTracer(std::ostream& os0 = std::cerr);
211  virtual void propagate(const Space& home,
212  const PropagateTraceInfo& pti);
219  virtual void commit(const Space& home,
220  const CommitTraceInfo& cti);
222  static StdTracer def;
223  };
224 
225 
226  /*
227  * View tracer
228  */
229 
230  template<class View>
233  }
234 
235  template<class View>
236  forceinline void
237  ViewTracer<View>::_init(const Space& home,
238  const ViewTraceRecorder<View>& t) {
239  m.acquire();
240  init(home,t);
241  m.release();
242  }
243  template<class View>
244  forceinline void
245  ViewTracer<View>::_prune(const Space& home,
246  const ViewTraceRecorder<View>& t,
247  const ViewTraceInfo& vti,
248  int i, typename TraceTraits<View>::TraceDelta& d) {
249  m.acquire();
250  prune(home,t,vti,i,d);
251  m.release();
252  }
253  template<class View>
254  forceinline void
255  ViewTracer<View>::_fail(const Space& home,
256  const ViewTraceRecorder<View>& t) {
257  m.acquire();
258  fail(home,t);
259  m.release();
260  }
261  template<class View>
262  forceinline void
263  ViewTracer<View>::_fix(const Space& home,
264  const ViewTraceRecorder<View>& t) {
265  m.acquire();
266  fix(home,t);
267  m.release();
268  }
269  template<class View>
270  forceinline void
271  ViewTracer<View>::_done(const Space& home,
272  const ViewTraceRecorder<View>& t) {
273  m.acquire();
274  done(home,t);
275  m.release();
276  }
277 
278  template<class View>
281  }
282 
283 
284  /*
285  * Tracer
286  */
287 
290  }
291 
292  forceinline void
293  Tracer::_propagate(const Space& home,
294  const PropagateTraceInfo& pti) {
295  m.acquire();
296  propagate(home,pti);
297  m.release();
298  }
299  forceinline void
300  Tracer::_commit(const Space& home,
301  const CommitTraceInfo& cti) {
302  m.acquire();
303  commit(home,cti);
304  m.release();
305  }
306 
309  }
310 
311 }
312 
313 // STATISTICS: kernel-trace
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Tracer that process view trace information.
Definition: tracer.hpp:55
View trace information.
Definition: core.hpp:974
Class to provide synchronization.
Definition: tracer.hpp:41
void acquire(void)
Acquire the mutex and possibly block.
Definition: none.hpp:46
virtual ~ViewTracer(void)
Destructor.
Definition: tracer.hpp:280
static StdTracer def
Default tracer (printing to std::cerr)
Definition: tracer.hpp:222
Computation spaces.
Definition: core.hpp:1748
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:257
ViewTracer(void)
Constructor.
Definition: tracer.hpp:232
static Support::Mutex m
Mutex to provide synchronization.
Definition: tracer.hpp:45
A mutex for mutual exclausion among several threads.
Definition: thread.hpp:99
Gecode::IntSet d(v, 7)
void release(void)
Release the mutex.
Definition: none.hpp:52
virtual ~Tracer(void)
Destructor.
Definition: tracer.hpp:308
Gecode::IntArgs i(4, 1, 2, 3, 4)
Tracer(void)
Constructor.
Definition: tracer.hpp:289
Commit trace information.
Definition: core.hpp:1064
#define GECODE_KERNEL_EXPORT
Definition: kernel.hh:74
Propagate trace information.
Definition: core.hpp:1028
Traits for tracing.
Propagator for recording view trace information.
#define forceinline
Definition: config.hpp:173
Tracer.
Definition: tracer.hpp:153
Default tracer.
Definition: tracer.hpp:198
Gecode toplevel namespace
std::ostream & os
Output stream to use.
Definition: tracer.hpp:201
Base class for heap allocated objects.
Definition: heap.hpp:344