Generated on Tue Apr 18 10:22:07 2017 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  *  Last modified:
00010  *     $Date: 2017-03-17 23:04:57 +0100 (Fri, 17 Mar 2017) $ by $Author: schulte $
00011  *     $Revision: 15597 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode {
00039 
00041   class TracerBase : public HeapAllocated {
00042   protected:
00044     GECODE_KERNEL_EXPORT
00045     static Support::Mutex m;
00046   };
00047 
00048   template<class View> class ViewTraceRecorder;
00049 
00054   template<class View>
00055   class ViewTracer : public TracerBase {
00056     template<class ViewForTraceRecorder> friend class ViewTraceRecorder;
00057   private:
00064     void _init(const Space& home, const ViewTraceRecorder<View>& t);
00071     void _prune(const Space& home, const ViewTraceRecorder<View>& t,
00072                 const ViewTraceInfo& vti,
00073                 int i, typename TraceTraits<View>::TraceDelta& d);
00080     void _fail(const Space& home, const ViewTraceRecorder<View>& t);
00086     void _fix(const Space& home, const ViewTraceRecorder<View>& t);
00092     void _done(const Space& home, const ViewTraceRecorder<View>& t);
00093   public:
00095     ViewTracer(void);
00102     virtual void init(const Space& home,
00103                       const ViewTraceRecorder<View>& t) = 0;
00113     virtual void prune(const Space& home,
00114                        const ViewTraceRecorder<View>& t,
00115                        const ViewTraceInfo& vti,
00116                        int i, typename TraceTraits<View>::TraceDelta& d) = 0;
00123     virtual void fail(const Space& home,
00124                       const ViewTraceRecorder<View>& t) = 0;
00132     virtual void fix(const Space& home,
00133                      const ViewTraceRecorder<View>& t) = 0;
00140     virtual void done(const Space& home,
00141                       const ViewTraceRecorder<View>& t) = 0;
00143     virtual ~ViewTracer(void);
00144   };
00145 
00146 
00147 
00148 
00153   class Tracer : public TracerBase {
00154     friend class Space;
00155   private:
00162     void _propagate(const Space& home, const PropagateTraceInfo& pti);
00169     void _commit(const Space& home, const CommitTraceInfo& cti);
00170   public:
00172     Tracer(void);
00179     virtual void propagate(const Space& home,
00180                            const PropagateTraceInfo& pti) = 0;
00187     virtual void commit(const Space& home,
00188                         const CommitTraceInfo& cti) = 0;
00190     virtual ~Tracer(void);
00191   };
00192 
00193 
00198   class  GECODE_KERNEL_EXPORT StdTracer : public Tracer {
00199   protected:
00201     std::ostream& os;
00202   public:
00204     StdTracer(std::ostream& os0 = std::cerr);
00211     virtual void propagate(const Space& home,
00212                            const PropagateTraceInfo& pti);
00219     virtual void commit(const Space& home,
00220                         const CommitTraceInfo& cti);
00222     static StdTracer def;
00223   };
00224 
00225 
00226   /*
00227    * View tracer
00228    */
00229 
00230   template<class View>
00231   forceinline
00232   ViewTracer<View>::ViewTracer(void) {
00233   }
00234 
00235   template<class View>
00236   forceinline void
00237   ViewTracer<View>::_init(const Space& home,
00238                           const ViewTraceRecorder<View>& t) {
00239     m.acquire();
00240     init(home,t);
00241     m.release();
00242   }
00243   template<class View>
00244   forceinline void
00245   ViewTracer<View>::_prune(const Space& home,
00246                            const ViewTraceRecorder<View>& t,
00247                            const ViewTraceInfo& vti,
00248                            int i, typename TraceTraits<View>::TraceDelta& d) {
00249     m.acquire();
00250     prune(home,t,vti,i,d);
00251     m.release();
00252   }
00253   template<class View>
00254   forceinline void
00255   ViewTracer<View>::_fail(const Space& home,
00256                           const ViewTraceRecorder<View>& t) {
00257     m.acquire();
00258     fail(home,t);
00259     m.release();
00260   }
00261   template<class View>
00262   forceinline void
00263   ViewTracer<View>::_fix(const Space& home,
00264                          const ViewTraceRecorder<View>& t) {
00265     m.acquire();
00266     fix(home,t);
00267     m.release();
00268   }
00269   template<class View>
00270   forceinline void
00271   ViewTracer<View>::_done(const Space& home,
00272                           const ViewTraceRecorder<View>& t) {
00273     m.acquire();
00274     done(home,t);
00275     m.release();
00276   }
00277 
00278   template<class View>
00279   forceinline
00280   ViewTracer<View>::~ViewTracer(void) {
00281   }
00282 
00283 
00284   /*
00285    * Tracer
00286    */
00287 
00288   forceinline
00289   Tracer::Tracer(void) {
00290   }
00291 
00292   forceinline void
00293   Tracer::_propagate(const Space& home,
00294                      const PropagateTraceInfo& pti) {
00295     m.acquire();
00296     propagate(home,pti);
00297     m.release();
00298   }
00299   forceinline void
00300   Tracer::_commit(const Space& home,
00301                   const CommitTraceInfo& cti) {
00302     m.acquire();
00303     commit(home,cti);
00304     m.release();
00305   }
00306 
00307   forceinline
00308   Tracer::~Tracer(void) {
00309   }
00310 
00311 }
00312 
00313 // STATISTICS: kernel-trace