tracer.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2016
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
namespace Gecode {
class TracerBase : public HeapAllocated {
protected:
GECODE_KERNEL_EXPORT
static Support::Mutex m;
};
template<class View> class ViewTraceRecorder;
template<class View>
class ViewTracer : public TracerBase {
template<class ViewForTraceRecorder> friend class ViewTraceRecorder;
private:
void _init(const Space& home, const ViewTraceRecorder<View>& t);
void _prune(const Space& home, const ViewTraceRecorder<View>& t,
const ViewTraceInfo& vti,
int i, typename TraceTraits<View>::TraceDelta& d);
void _fail(const Space& home, const ViewTraceRecorder<View>& t);
void _fix(const Space& home, const ViewTraceRecorder<View>& t);
void _done(const Space& home, const ViewTraceRecorder<View>& t);
public:
ViewTracer(void);
virtual void init(const Space& home,
const ViewTraceRecorder<View>& t) = 0;
virtual void prune(const Space& home,
const ViewTraceRecorder<View>& t,
const ViewTraceInfo& vti,
int i, typename TraceTraits<View>::TraceDelta& d) = 0;
virtual void fail(const Space& home,
const ViewTraceRecorder<View>& t) = 0;
virtual void fix(const Space& home,
const ViewTraceRecorder<View>& t) = 0;
virtual void done(const Space& home,
const ViewTraceRecorder<View>& t) = 0;
virtual ~ViewTracer(void);
};
class Tracer : public TracerBase {
friend class Space;
friend class PostInfo;
private:
void _propagate(const Space& home, const PropagateTraceInfo& pti);
void _commit(const Space& home, const CommitTraceInfo& cti);
void _post(const Space& home, const PostTraceInfo& pti);
public:
Tracer(void);
virtual void propagate(const Space& home,
const PropagateTraceInfo& pti) = 0;
virtual void commit(const Space& home,
const CommitTraceInfo& cti) = 0;
virtual void post(const Space& home,
const PostTraceInfo& pti) = 0;
virtual ~Tracer(void);
};
class GECODE_KERNEL_EXPORT StdTracer : public Tracer {
protected:
std::ostream& os;
public:
StdTracer(std::ostream& os = std::cerr);
virtual void propagate(const Space& home,
const PropagateTraceInfo& pti);
virtual void commit(const Space& home,
const CommitTraceInfo& cti);
virtual void post(const Space& home,
const PostTraceInfo& pti);
static StdTracer def;
};
/*
* View tracer
*/
template<class View>
forceinline
ViewTracer<View>::ViewTracer(void) {
}
template<class View>
forceinline void
ViewTracer<View>::_init(const Space& home,
const ViewTraceRecorder<View>& t) {
Support::Lock l(m);
init(home,t);
}
template<class View>
forceinline void
ViewTracer<View>::_prune(const Space& home,
const ViewTraceRecorder<View>& t,
const ViewTraceInfo& vti,
int i, typename TraceTraits<View>::TraceDelta& d) {
Support::Lock l(m);
prune(home,t,vti,i,d);
}
template<class View>
forceinline void
ViewTracer<View>::_fail(const Space& home,
const ViewTraceRecorder<View>& t) {
Support::Lock l(m);
fail(home,t);
}
template<class View>
forceinline void
ViewTracer<View>::_fix(const Space& home,
const ViewTraceRecorder<View>& t) {
Support::Lock l(m);
fix(home,t);
}
template<class View>
forceinline void
ViewTracer<View>::_done(const Space& home,
const ViewTraceRecorder<View>& t) {
Support::Lock l(m);
done(home,t);
}
template<class View>
forceinline
ViewTracer<View>::~ViewTracer(void) {
}
/*
* Tracer
*/
forceinline
Tracer::Tracer(void) {
}
forceinline void
Tracer::_propagate(const Space& home,
const PropagateTraceInfo& pti) {
Support::Lock l(m);
propagate(home,pti);
}
forceinline void
Tracer::_commit(const Space& home,
const CommitTraceInfo& cti) {
Support::Lock l(m);
commit(home,cti);
}
forceinline void
Tracer::_post(const Space& home,
const PostTraceInfo& pti) {
Support::Lock l(m);
post(home,pti);
}
forceinline
Tracer::~Tracer(void) {
}
}
// STATISTICS: kernel-trace
Gecode::CommitTraceInfo
Commit trace information.
Definition core.hpp:1005
Gecode::HeapAllocated
Base class for heap allocated objects.
Definition heap.hpp:340
Gecode::PostTraceInfo
Post trace information.
Definition core.hpp:1032
Gecode::PropagateTraceInfo
Propagate trace information.
Definition core.hpp:969
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::StdTracer::os
std::ostream & os
Output stream to use.
Definition tracer.hpp:213
Gecode::StdTracer::StdTracer
StdTracer(std::ostream &os=std::cerr)
Initialize with output stream os.
Definition tracer.cpp:41
Gecode::StdTracer::propagate
virtual void propagate(const Space &home, const PropagateTraceInfo &pti)
Propagate function.
Definition tracer.cpp:44
Gecode::StdTracer::def
static StdTracer def
Default tracer (printing to std::cerr).
Definition tracer.hpp:242
Gecode::StdTracer::commit
virtual void commit(const Space &home, const CommitTraceInfo &cti)
Commit function.
Definition tracer.cpp:50
Gecode::StdTracer::post
virtual void post(const Space &home, const PostTraceInfo &pti)
Post function.
Definition tracer.cpp:59
Gecode::Support::Lock
A lock as a scoped frontend for a mutex.
Definition thread.hpp:191
Gecode::Support::Mutex
A mutex for mutual exclausion among several threads.
Definition thread.hpp:96
Gecode::TraceTraits
Traits for tracing.
Definition traits.hpp:49
Gecode::TracerBase
Class to provide synchronization.
Definition tracer.hpp:37
Gecode::TracerBase::m
static Support::Mutex m
Mutex to provide synchronization.
Definition tracer.hpp:41
Gecode::Tracer::commit
virtual void commit(const Space &home, const CommitTraceInfo &cti)=0
Commit function.
Gecode::Tracer::Space
friend class Space
Definition tracer.hpp:150
Gecode::Tracer::propagate
virtual void propagate(const Space &home, const PropagateTraceInfo &pti)=0
Propagate function.
Gecode::Tracer::~Tracer
virtual ~Tracer(void)
Destructor.
Definition tracer.hpp:327
Gecode::Tracer::PostInfo
friend class PostInfo
Definition tracer.hpp:151
Gecode::Tracer::Tracer
Tracer(void)
Constructor.
Definition tracer.hpp:304
Gecode::Tracer::post
virtual void post(const Space &home, const PostTraceInfo &pti)=0
Post function.
Gecode::ViewTraceInfo
View trace information.
Definition core.hpp:908
Gecode::ViewTraceRecorder
Propagator for recording view trace information.
Definition recorder.hpp:60
Gecode::ViewTracer::done
virtual void done(const Space &home, const ViewTraceRecorder< View > &t)=0
Done function.
Gecode::ViewTracer::prune
virtual void prune(const Space &home, const ViewTraceRecorder< View > &t, const ViewTraceInfo &vti, int i, typename TraceTraits< View >::TraceDelta &d)=0
Prune function.
Gecode::ViewTracer::ViewTracer
ViewTracer(void)
Constructor.
Definition tracer.hpp:252
Gecode::ViewTracer::init
virtual void init(const Space &home, const ViewTraceRecorder< View > &t)=0
Init function.
Gecode::ViewTracer< Float::FloatView >::ViewTraceRecorder
friend class ViewTraceRecorder
Definition tracer.hpp:52
Gecode::ViewTracer::fail
virtual void fail(const Space &home, const ViewTraceRecorder< View > &t)=0
Fail function.
Gecode::ViewTracer::~ViewTracer
virtual ~ViewTracer(void)
Destructor.
Definition tracer.hpp:295
Gecode::ViewTracer::fix
virtual void fix(const Space &home, const ViewTraceRecorder< View > &t)=0
Fixpoint function.
GECODE_KERNEL_EXPORT
#define GECODE_KERNEL_EXPORT
Definition kernel.hh:70
Gecode::Int::LDSB::prune
ModEvent prune(Space &home, View x, int v)
Exclude value \v from variable view \x.
Gecode
Gecode toplevel namespace
forceinline
#define forceinline
Definition config.hpp:187