Generated on Sun Feb 17 15:24:27 2019 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     friend class PostInfo;
00152   private:
00159     void _propagate(const Space& home, const PropagateTraceInfo& pti);
00166     void _commit(const Space& home, const CommitTraceInfo& cti);
00173     void _post(const Space& home, const PostTraceInfo& pti);
00174   public:
00176     Tracer(void);
00183     virtual void propagate(const Space& home,
00184                            const PropagateTraceInfo& pti) = 0;
00191     virtual void commit(const Space& home,
00192                         const CommitTraceInfo& cti) = 0;
00199     virtual void post(const Space& home,
00200                       const PostTraceInfo& pti) = 0;
00202     virtual ~Tracer(void);
00203   };
00204 
00205 
00210   class  GECODE_KERNEL_EXPORT StdTracer : public Tracer {
00211   protected:
00213     std::ostream& os;
00214   public:
00216     StdTracer(std::ostream& os = std::cerr);
00223     virtual void propagate(const Space& home,
00224                            const PropagateTraceInfo& pti);
00231     virtual void commit(const Space& home,
00232                         const CommitTraceInfo& cti);
00239     virtual void post(const Space& home,
00240                       const PostTraceInfo& pti);
00242     static StdTracer def;
00243   };
00244 
00245 
00246   /*
00247    * View tracer
00248    */
00249 
00250   template<class View>
00251   forceinline
00252   ViewTracer<View>::ViewTracer(void) {
00253   }
00254 
00255   template<class View>
00256   forceinline void
00257   ViewTracer<View>::_init(const Space& home,
00258                           const ViewTraceRecorder<View>& t) {
00259     Support::Lock l(m);
00260     init(home,t);
00261   }
00262   template<class View>
00263   forceinline void
00264   ViewTracer<View>::_prune(const Space& home,
00265                            const ViewTraceRecorder<View>& t,
00266                            const ViewTraceInfo& vti,
00267                            int i, typename TraceTraits<View>::TraceDelta& d) {
00268     Support::Lock l(m);
00269     prune(home,t,vti,i,d);
00270   }
00271   template<class View>
00272   forceinline void
00273   ViewTracer<View>::_fail(const Space& home,
00274                           const ViewTraceRecorder<View>& t) {
00275     Support::Lock l(m);
00276     fail(home,t);
00277   }
00278   template<class View>
00279   forceinline void
00280   ViewTracer<View>::_fix(const Space& home,
00281                          const ViewTraceRecorder<View>& t) {
00282     Support::Lock l(m);
00283     fix(home,t);
00284   }
00285   template<class View>
00286   forceinline void
00287   ViewTracer<View>::_done(const Space& home,
00288                           const ViewTraceRecorder<View>& t) {
00289     Support::Lock l(m);
00290     done(home,t);
00291   }
00292 
00293   template<class View>
00294   forceinline
00295   ViewTracer<View>::~ViewTracer(void) {
00296   }
00297 
00298 
00299   /*
00300    * Tracer
00301    */
00302 
00303   forceinline
00304   Tracer::Tracer(void) {
00305   }
00306 
00307   forceinline void
00308   Tracer::_propagate(const Space& home,
00309                      const PropagateTraceInfo& pti) {
00310     Support::Lock l(m);
00311     propagate(home,pti);
00312   }
00313   forceinline void
00314   Tracer::_commit(const Space& home,
00315                   const CommitTraceInfo& cti) {
00316     Support::Lock l(m);
00317     commit(home,cti);
00318   }
00319   forceinline void
00320   Tracer::_post(const Space& home,
00321                 const PostTraceInfo& pti) {
00322     Support::Lock l(m);
00323     post(home,pti);
00324   }
00325 
00326   forceinline
00327   Tracer::~Tracer(void) {
00328   }
00329 
00330 }
00331 
00332 // STATISTICS: kernel-trace