trace-recorder.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, 2017
*
* 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 { namespace Search {
class WrapTraceRecorder {
public:
static void engine(SearchTracer* tracer,
SearchTracer::EngineType t, unsigned int n);
};
class TraceRecorder {
protected:
SearchTracer& tracer;
unsigned int _eid;
unsigned int _wid;
unsigned int _nid;
public:
class ID {
protected:
unsigned int _id;
public:
ID(void);
ID(unsigned int id);
operator unsigned int(void) const;
};
TraceRecorder(SearchTracer* t);
void engine(SearchTracer::EngineType t, unsigned int n);
void worker(void);
unsigned int nid(void);
unsigned int wid(void) const;
void round(void);
void skip(const SearchTracer::EdgeInfo& ei);
void node(const SearchTracer::EdgeInfo& ei,
const SearchTracer::NodeInfo& ni);
void done(void);
operator bool(void) const;
};
class EdgeTraceRecorder : public TraceRecorder {
protected:
SearchTracer::EdgeInfo _ei;
public:
EdgeTraceRecorder(SearchTracer* t);
void invalidate(void);
SearchTracer::EdgeInfo* ei(void);
};
class NoTraceRecorder {
public:
class ID {
public:
ID(void);
ID(unsigned int id);
operator unsigned int(void) const;
};
NoTraceRecorder(SearchTracer* t);
void engine(SearchTracer::EngineType t, unsigned int n);
void worker(void);
unsigned int wid(void) const;
unsigned int nid(void);
void invalidate(void);
SearchTracer::EdgeInfo* ei(void);
void round(void);
void skip(const SearchTracer::EdgeInfo& ei);
void node(const SearchTracer::EdgeInfo& ei,
const SearchTracer::NodeInfo& ni);
void done(void);
operator bool(void) const;
};
/*
* Recorder for engine events
*
*/
forceinline void
WrapTraceRecorder::engine(SearchTracer* tracer,
SearchTracer::EngineType t, unsigned int n) {
if (tracer) tracer->engine(t,n);
}
/*
* Simple trace recorder for a search tracer
*
*/
forceinline
TraceRecorder::ID::ID(void) {}
forceinline
TraceRecorder::ID::ID(unsigned int id) : _id(id) {}
forceinline
TraceRecorder::ID::operator unsigned int(void) const {
return _id;
}
forceinline
TraceRecorder::TraceRecorder(SearchTracer* t)
: tracer(*t), _eid(0U), _wid(0U), _nid(0U) {}
forceinline void
TraceRecorder::engine(SearchTracer::EngineType t, unsigned int n) {
tracer.engine(t,n);
}
forceinline void
TraceRecorder::worker(void) {
tracer.worker(_wid,_eid);
}
forceinline unsigned int
TraceRecorder::nid(void) {
return _nid++;
}
forceinline unsigned int
TraceRecorder::wid(void) const {
return _wid;
}
forceinline void
TraceRecorder::round(void) {
tracer._round(_eid);
}
forceinline void
TraceRecorder::skip(const SearchTracer::EdgeInfo& ei) {
tracer._skip(ei);
}
forceinline void
TraceRecorder::node(const SearchTracer::EdgeInfo& ei,
const SearchTracer::NodeInfo& ni) {
tracer._node(ei,ni);
}
forceinline void
TraceRecorder::done(void) {
tracer.worker();
}
forceinline
TraceRecorder::operator bool(void) const {
return true;
}
/*
* Recorder for a search tracer with edge information
*
*/
forceinline
EdgeTraceRecorder::EdgeTraceRecorder(SearchTracer* t)
: TraceRecorder(t) {}
forceinline void
EdgeTraceRecorder::invalidate(void) {
_ei.invalidate();
}
forceinline SearchTracer::EdgeInfo*
EdgeTraceRecorder::ei(void) {
return &_ei;
}
/*
* Empty trace recorder
*
*/
forceinline
NoTraceRecorder::ID::ID(void) {}
forceinline
NoTraceRecorder::ID::ID(unsigned int) {}
forceinline
NoTraceRecorder::ID::operator unsigned int(void) const {
return 0U;
}
forceinline
NoTraceRecorder::NoTraceRecorder(SearchTracer*) {}
forceinline void
NoTraceRecorder::engine(SearchTracer::EngineType, unsigned int) {}
forceinline void
NoTraceRecorder::worker(void) {}
forceinline unsigned int
NoTraceRecorder::wid(void) const {
return 0U;
}
forceinline unsigned int
NoTraceRecorder::nid(void) {
return 0U;
}
forceinline void
NoTraceRecorder::invalidate(void) {}
forceinline SearchTracer::EdgeInfo*
NoTraceRecorder::ei(void) {
return nullptr;
}
forceinline void
NoTraceRecorder::round(void) {}
forceinline void
NoTraceRecorder::skip(const SearchTracer::EdgeInfo&) {}
forceinline void
NoTraceRecorder::node(const SearchTracer::EdgeInfo&,
const SearchTracer::NodeInfo&) {
}
forceinline void
NoTraceRecorder::done(void) {
}
forceinline
NoTraceRecorder::operator bool(void) const {
return false;
}
}}
// STATISTICS: search-trace
Gecode::SearchTracer::EdgeInfo
Edge information.
Definition search.hh:242
Gecode::SearchTracer::NodeInfo
Node information.
Definition search.hh:282
Gecode::SearchTracer
Support for tracing search.
Definition search.hh:187
Gecode::SearchTracer::EngineType
EngineType
Which type of engine.
Definition search.hh:193
Gecode::Search::EdgeTraceRecorder::invalidate
void invalidate(void)
Invalidate edge information.
Definition trace-recorder.hpp:233
Gecode::Search::EdgeTraceRecorder::EdgeTraceRecorder
EdgeTraceRecorder(SearchTracer *t)
Initialize.
Definition trace-recorder.hpp:229
Gecode::Search::EdgeTraceRecorder::_ei
SearchTracer::EdgeInfo _ei
Edge information.
Definition trace-recorder.hpp:96
Gecode::Search::EdgeTraceRecorder::ei
SearchTracer::EdgeInfo * ei(void)
Provide access to edge information.
Definition trace-recorder.hpp:238
Gecode::Search::NoTraceRecorder::ID::ID
ID(void)
Do not initialize.
Definition trace-recorder.hpp:248
Gecode::Search::NoTraceRecorder::wid
unsigned int wid(void) const
Return worker id.
Definition trace-recorder.hpp:268
Gecode::Search::NoTraceRecorder::skip
void skip(const SearchTracer::EdgeInfo &ei)
The engine skips an edge.
Definition trace-recorder.hpp:289
Gecode::Search::NoTraceRecorder::nid
unsigned int nid(void)
Generate new node id.
Definition trace-recorder.hpp:273
Gecode::Search::NoTraceRecorder::done
void done(void)
The worker is done.
Definition trace-recorder.hpp:297
Gecode::Search::NoTraceRecorder::round
void round(void)
The workers goes to a next round (restart or next iteration in LDS).
Definition trace-recorder.hpp:286
Gecode::Search::NoTraceRecorder::invalidate
void invalidate(void)
Invalidate edge information.
Definition trace-recorder.hpp:278
Gecode::Search::NoTraceRecorder::worker
void worker(void)
Register worker.
Definition trace-recorder.hpp:265
Gecode::Search::NoTraceRecorder::node
void node(const SearchTracer::EdgeInfo &ei, const SearchTracer::NodeInfo &ni)
The engine creates a new node with information ei and ni.
Definition trace-recorder.hpp:292
Gecode::Search::NoTraceRecorder::engine
void engine(SearchTracer::EngineType t, unsigned int n)
Register engine.
Definition trace-recorder.hpp:262
Gecode::Search::NoTraceRecorder::ei
SearchTracer::EdgeInfo * ei(void)
Provide access to edge information.
Definition trace-recorder.hpp:281
Gecode::Search::NoTraceRecorder::NoTraceRecorder
NoTraceRecorder(SearchTracer *t)
Initialize.
Definition trace-recorder.hpp:259
Gecode::Search::TraceRecorder::ID::_id
unsigned int _id
The actual identifier.
Definition trace-recorder.hpp:60
Gecode::Search::TraceRecorder::ID::ID
ID(void)
Do not initialize.
Definition trace-recorder.hpp:163
Gecode::Search::TraceRecorder::tracer
SearchTracer & tracer
The actual tracer.
Definition trace-recorder.hpp:48
Gecode::Search::TraceRecorder::wid
unsigned int wid(void) const
Return worker id.
Definition trace-recorder.hpp:193
Gecode::Search::TraceRecorder::worker
void worker(void)
Register worker.
Definition trace-recorder.hpp:183
Gecode::Search::TraceRecorder::_nid
unsigned int _nid
The next free node id.
Definition trace-recorder.hpp:54
Gecode::Search::TraceRecorder::_eid
unsigned int _eid
The engine id.
Definition trace-recorder.hpp:50
Gecode::Search::TraceRecorder::engine
void engine(SearchTracer::EngineType t, unsigned int n)
Register engine.
Definition trace-recorder.hpp:178
Gecode::Search::TraceRecorder::round
void round(void)
The workers goes to a next round (restart or next iteration in LDS).
Definition trace-recorder.hpp:198
Gecode::Search::TraceRecorder::done
void done(void)
The worker is done.
Definition trace-recorder.hpp:214
Gecode::Search::TraceRecorder::skip
void skip(const SearchTracer::EdgeInfo &ei)
The engine skips an edge.
Definition trace-recorder.hpp:203
Gecode::Search::TraceRecorder::TraceRecorder
TraceRecorder(SearchTracer *t)
Initialize.
Definition trace-recorder.hpp:174
Gecode::Search::TraceRecorder::node
void node(const SearchTracer::EdgeInfo &ei, const SearchTracer::NodeInfo &ni)
The engine creates a new node with information ei and ni.
Definition trace-recorder.hpp:208
Gecode::Search::TraceRecorder::nid
unsigned int nid(void)
Generate new node id.
Definition trace-recorder.hpp:188
Gecode::Search::TraceRecorder::_wid
unsigned int _wid
The worker id.
Definition trace-recorder.hpp:52
Gecode::Search::WrapTraceRecorder
Recorder for engine events (for access control).
Definition trace-recorder.hpp:37
Gecode::Search::WrapTraceRecorder::engine
static void engine(SearchTracer *tracer, SearchTracer::EngineType t, unsigned int n)
Register engine.
Definition trace-recorder.hpp:152
Gecode::Search
Search engines
Gecode
Gecode toplevel namespace
forceinline
#define forceinline
Definition config.hpp:187