Generated on Tue May 22 09:40:10 2018 for Gecode by doxygen 1.6.3

tracer.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2016
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode {
00035 
00037   class TracerBase : public HeapAllocated {
00038   protected:
00040     GECODE_KERNEL_EXPORT
00041     static Support::Mutex m;
00042   };
00043 
00044   template<class View> class ViewTraceRecorder;
00045 
00050   template<class View>
00051   class ViewTracer : public TracerBase {
00052     template<class ViewForTraceRecorder> friend class ViewTraceRecorder;
00053   private:
00060     void _init(const Space& home, const ViewTraceRecorder<View>& t);
00067     void _prune(const Space& home, const ViewTraceRecorder<View>& t,
00068                 const ViewTraceInfo& vti,
00069                 int i, typename TraceTraits<View>::TraceDelta& d);
00076     void _fail(const Space& home, const ViewTraceRecorder<View>& t);
00082     void _fix(const Space& home, const ViewTraceRecorder<View>& t);
00088     void _done(const Space& home, const ViewTraceRecorder<View>& t);
00089   public:
00091     ViewTracer(void);
00098     virtual void init(const Space& home,
00099                       const ViewTraceRecorder<View>& t) = 0;
00109     virtual void prune(const Space& home,
00110                        const ViewTraceRecorder<View>& t,
00111                        const ViewTraceInfo& vti,
00112                        int i, typename TraceTraits<View>::TraceDelta& d) = 0;
00119     virtual void fail(const Space& home,
00120                       const ViewTraceRecorder<View>& t) = 0;
00128     virtual void fix(const Space& home,
00129                      const ViewTraceRecorder<View>& t) = 0;
00136     virtual void done(const Space& home,
00137                       const ViewTraceRecorder<View>& t) = 0;
00139     virtual ~ViewTracer(void);
00140   };
00141 
00142 
00143 
00144 
00149   class Tracer : public TracerBase {
00150     friend class Space;
00151   private:
00158     void _propagate(const Space& home, const PropagateTraceInfo& pti);
00165     void _commit(const Space& home, const CommitTraceInfo& cti);
00166   public:
00168     Tracer(void);
00175     virtual void propagate(const Space& home,
00176                            const PropagateTraceInfo& pti) = 0;
00183     virtual void commit(const Space& home,
00184                         const CommitTraceInfo& cti) = 0;
00186     virtual ~Tracer(void);
00187   };
00188 
00189 
00194   class  GECODE_KERNEL_EXPORT StdTracer : public Tracer {
00195   protected:
00197     std::ostream& os;
00198   public:
00200     StdTracer(std::ostream& os = std::cerr);
00207     virtual void propagate(const Space& home,
00208                            const PropagateTraceInfo& pti);
00215     virtual void commit(const Space& home,
00216                         const CommitTraceInfo& cti);
00218     static StdTracer def;
00219   };
00220 
00221 
00222   /*
00223    * View tracer
00224    */
00225 
00226   template<class View>
00227   forceinline
00228   ViewTracer<View>::ViewTracer(void) {
00229   }
00230 
00231   template<class View>
00232   forceinline void
00233   ViewTracer<View>::_init(const Space& home,
00234                           const ViewTraceRecorder<View>& t) {
00235     m.acquire();
00236     init(home,t);
00237     m.release();
00238   }
00239   template<class View>
00240   forceinline void
00241   ViewTracer<View>::_prune(const Space& home,
00242                            const ViewTraceRecorder<View>& t,
00243                            const ViewTraceInfo& vti,
00244                            int i, typename TraceTraits<View>::TraceDelta& d) {
00245     m.acquire();
00246     prune(home,t,vti,i,d);
00247     m.release();
00248   }
00249   template<class View>
00250   forceinline void
00251   ViewTracer<View>::_fail(const Space& home,
00252                           const ViewTraceRecorder<View>& t) {
00253     m.acquire();
00254     fail(home,t);
00255     m.release();
00256   }
00257   template<class View>
00258   forceinline void
00259   ViewTracer<View>::_fix(const Space& home,
00260                          const ViewTraceRecorder<View>& t) {
00261     m.acquire();
00262     fix(home,t);
00263     m.release();
00264   }
00265   template<class View>
00266   forceinline void
00267   ViewTracer<View>::_done(const Space& home,
00268                           const ViewTraceRecorder<View>& t) {
00269     m.acquire();
00270     done(home,t);
00271     m.release();
00272   }
00273 
00274   template<class View>
00275   forceinline
00276   ViewTracer<View>::~ViewTracer(void) {
00277   }
00278 
00279 
00280   /*
00281    * Tracer
00282    */
00283 
00284   forceinline
00285   Tracer::Tracer(void) {
00286   }
00287 
00288   forceinline void
00289   Tracer::_propagate(const Space& home,
00290                      const PropagateTraceInfo& pti) {
00291     m.acquire();
00292     propagate(home,pti);
00293     m.release();
00294   }
00295   forceinline void
00296   Tracer::_commit(const Space& home,
00297                   const CommitTraceInfo& cti) {
00298     m.acquire();
00299     commit(home,cti);
00300     m.release();
00301   }
00302 
00303   forceinline
00304   Tracer::~Tracer(void) {
00305   }
00306 
00307 }
00308 
00309 // STATISTICS: kernel-trace