filter.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 TraceFilter;
class TFE {
friend GECODE_KERNEL_EXPORT TFE operator -(const TFE& r);
friend GECODE_KERNEL_EXPORT TFE propagator(PropagatorGroup g);
friend GECODE_KERNEL_EXPORT TFE post(PropagatorGroup g);
friend class TraceFilter;
protected:
enum NodeType {
NT_GROUP,
NT_NEGATE,
NT_ADD
};
class Node : public HeapAllocated {
public:
unsigned int use;
NodeType t;
int n;
Group g;
char w;
Node *l, *r;
Node(void);
GECODE_KERNEL_EXPORT
bool decrement(void);
};
Node* n;
TFE(void);
TFE(Node* n);
void init(Group g, char what);
TFE negate(void) const;
public:
GECODE_KERNEL_EXPORT
TFE(PropagatorGroup g);
GECODE_KERNEL_EXPORT
TFE(BrancherGroup g);
GECODE_KERNEL_EXPORT
static TFE other(void);
GECODE_KERNEL_EXPORT
TFE(const TFE& e);
GECODE_KERNEL_EXPORT
TFE& operator =(const TFE& e);
GECODE_KERNEL_EXPORT
TFE& operator +=(const TFE& e);
GECODE_KERNEL_EXPORT
TFE& operator -=(const TFE& e);
GECODE_KERNEL_EXPORT
~TFE(void);
};
TFE operator +(TFE l, const TFE& r);
TFE operator +(const TFE& e);
TFE operator -(TFE l, const TFE& r);
GECODE_KERNEL_EXPORT
TFE operator -(const TFE& e);
GECODE_KERNEL_EXPORT
TFE propagator(PropagatorGroup g);
GECODE_KERNEL_EXPORT
TFE post(PropagatorGroup g);
class TraceFilter : public SharedHandle {
protected:
class TFO : public SharedHandle::Object {
public:
struct Filter {
Group g;
bool neg;
char what;
};
class StackFrame {
public:
TFE::Node* n;
bool neg;
StackFrame(void);
StackFrame(TFE::Node* n, bool neg);
};
int n;
Filter* f;
GECODE_KERNEL_EXPORT
void fill(TFE::Node* n);
TFO(void);
TFO(const TFE& e);
TFO(PropagatorGroup g);
TFO(BrancherGroup g);
bool operator ()(const ViewTraceInfo& vti) const;
bool operator ()(PropagatorGroup pg) const;
bool operator ()(BrancherGroup bg) const;
GECODE_KERNEL_EXPORT
virtual ~TFO(void);
};
public:
GECODE_KERNEL_EXPORT
TraceFilter(void);
GECODE_KERNEL_EXPORT
TraceFilter(const TFE& e);
GECODE_KERNEL_EXPORT
TraceFilter(PropagatorGroup g);
GECODE_KERNEL_EXPORT
TraceFilter(BrancherGroup g);
GECODE_KERNEL_EXPORT
TraceFilter(const TraceFilter& tf);
GECODE_KERNEL_EXPORT
TraceFilter& operator =(const TraceFilter& tf);
bool operator ()(const ViewTraceInfo& vti) const;
bool operator ()(PropagatorGroup pg) const;
bool operator ()(BrancherGroup bg) const;
GECODE_KERNEL_EXPORT
static TraceFilter all;
};
/*
* Trace expression filters
*
*/
forceinline
TFE::Node::Node(void)
: use(1), l(NULL), r(NULL) {}
forceinline
TFE::TFE(void) : n(NULL) {}
forceinline
TFE::TFE(TFE::Node* n0) : n(n0) {}
forceinline TFE
operator +(TFE l, const TFE& r) {
l += r; return l;
}
forceinline TFE
operator +(const TFE& e) {
return e;
}
forceinline TFE
operator -(TFE l, const TFE& r) {
l -= r; return l;
}
/*
* Trace filters
*
*/
forceinline
TraceFilter::TFO::TFO(void) : n(0), f(NULL) {}
forceinline
TraceFilter::TFO::TFO(const TFE& e)
: n(e.n->n),
f((n == 0) ? NULL : heap.alloc<Filter>(n)) {
if (n > 0)
fill(e.n);
}
forceinline
TraceFilter::TFO::TFO(PropagatorGroup g) : n(1) {
f = heap.alloc<Filter>(1);
f[0].g = g; f[0].neg = false;
f[0].what = 1 << ViewTraceInfo::PROPAGATOR;
}
forceinline
TraceFilter::TFO::TFO(BrancherGroup g) : n(1) {
f = heap.alloc<Filter>(1);
f[0].g = g; f[0].neg = false;
f[0].what = 1 << ViewTraceInfo::BRANCHER;
}
forceinline bool
TraceFilter::TFO::operator ()(const ViewTraceInfo& vti) const {
if (n == 0)
return true;
for (int i=0; i<n; i++)
if (f[i].what & (1 << vti.what())) {
// Group is of the right type
switch (vti.what()) {
case ViewTraceInfo::PROPAGATOR:
if (f[i].g.in(vti.propagator().group()) != f[i].neg)
return true;
break;
case ViewTraceInfo::BRANCHER:
if (f[i].g.in(vti.brancher().group()) != f[i].neg)
return true;
break;
case ViewTraceInfo::POST:
if (f[i].g.in(vti.post()) != f[i].neg)
return true;
break;
case ViewTraceInfo::OTHER:
return true;
default:
GECODE_NEVER;
}
}
return false;
}
forceinline bool
TraceFilter::operator ()(const ViewTraceInfo& vti) const {
return static_cast<TFO*>(object())->operator ()(vti);
}
forceinline bool
TraceFilter::TFO::operator ()(PropagatorGroup pg) const {
if (n == 0)
return true;
for (int i=0; i<n; i++)
if ((f[i].what & (1 << ViewTraceInfo::PROPAGATOR)) &&
(f[i].g.in(pg) != f[i].neg))
return true;
return false;
}
forceinline bool
TraceFilter::operator ()(PropagatorGroup pg) const {
return static_cast<TFO*>(object())->operator ()(pg);
}
forceinline bool
TraceFilter::TFO::operator ()(BrancherGroup bg) const {
if (n == 0)
return true;
for (int i=0; i<n; i++)
if ((f[i].what & (1 << ViewTraceInfo::BRANCHER)) &&
(f[i].g.in(bg) != f[i].neg))
return true;
return false;
}
forceinline bool
TraceFilter::operator ()(BrancherGroup bg) const {
return static_cast<TFO*>(object())->operator ()(bg);
}
}
// STATISTICS: kernel-trace
Gecode::BrancherGroup
Group of branchers.
Definition core.hpp:799
Gecode::Group
Group baseclass for controlling actors.
Definition core.hpp:673
Gecode::HeapAllocated
Base class for heap allocated objects.
Definition heap.hpp:340
Gecode::PropagatorGroup
Group of propagators.
Definition core.hpp:727
Gecode::SharedHandle::Object
The shared object.
Definition shared-object.hpp:53
Gecode::SharedHandle::SharedHandle
SharedHandle(void)
Create shared handle with no object pointing to.
Definition shared-object.hpp:122
Gecode::SharedHandle::object
SharedHandle::Object * object(void) const
Access to the shared object.
Definition shared-object.hpp:102
Gecode::TFE::Node
Node for trace filter expression.
Definition filter.hpp:55
Gecode::TFE::Node::t
NodeType t
Type of expression.
Definition filter.hpp:60
Gecode::TFE::Node::use
unsigned int use
Nodes are reference counted.
Definition filter.hpp:58
Gecode::TFE::Node::Node
Node(void)
Default constructor.
Definition filter.hpp:221
Gecode::TFE::Node::g
Group g
Group.
Definition filter.hpp:64
Gecode::TFE::Node::decrement
bool decrement(void)
Decrement reference count and possibly free memory.
Definition filter.cpp:43
Gecode::TFE::Node::l
Node * l
Subexpressions.
Definition filter.hpp:68
Gecode::TFE::Node::r
Node * r
Definition filter.hpp:68
Gecode::TFE::Node::n
int n
Number of leaf groups.
Definition filter.hpp:62
Gecode::TFE::Node::w
char w
Which operations to consider for propagator groups.
Definition filter.hpp:66
Gecode::TFE
Trace filter expressions.
Definition filter.hpp:42
Gecode::TFE::operator+=
TFE & operator+=(const TFE &e)
Add expression e.
Definition filter.cpp:104
Gecode::TFE::propagator
friend TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Definition filter.cpp:131
Gecode::TFE::other
static TFE other(void)
Expression for other than propagator, brancher, or post.
Definition filter.cpp:82
Gecode::TFE::post
friend TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
Gecode::TFE::~TFE
~TFE(void)
Destructor.
Definition filter.cpp:119
Gecode::TFE::n
Node * n
Pointer to trace filter expression node.
Definition filter.hpp:76
Gecode::TFE::TraceFilter
friend class TraceFilter
Definition filter.hpp:46
Gecode::TFE::init
void init(Group g, char what)
Initialize with propagator group g and flags what.
Definition filter.cpp:56
Gecode::TFE::operator-=
TFE & operator-=(const TFE &e)
Add expression e as negative expression.
Definition filter.cpp:115
Gecode::TFE::operator=
TFE & operator=(const TFE &e)
Assignment operator.
Definition filter.cpp:93
Gecode::TFE::negate
TFE negate(void) const
Return negated the expresssion.
Definition filter.cpp:65
Gecode::TFE::NodeType
NodeType
Type of trace filter expression.
Definition filter.hpp:49
Gecode::TFE::NT_NEGATE
@ NT_NEGATE
Negation of expression.
Definition filter.hpp:51
Gecode::TFE::NT_GROUP
@ NT_GROUP
Propagator or brancher group.
Definition filter.hpp:50
Gecode::TFE::NT_ADD
@ NT_ADD
More than one expression.
Definition filter.hpp:52
Gecode::TFE::operator-
friend TFE operator-(const TFE &r)
Return negative expression of e.
Definition filter.cpp:126
Gecode::TFE::TFE
TFE(void)
Initialize with no node.
Definition filter.hpp:224
Gecode::TraceFilter::TFO::StackFrame::n
TFE::Node * n
The node.
Definition filter.hpp:150
Gecode::TraceFilter::TFO::StackFrame::StackFrame
StackFrame(void)
Default constructor.
Definition filter.cpp:153
Gecode::TraceFilter::TFO::StackFrame::neg
bool neg
Whether it is negated.
Definition filter.hpp:152
Gecode::TraceFilter::TFO
The actual object storing the shared filters.
Definition filter.hpp:136
Gecode::TraceFilter::TFO::operator()
bool operator()(const ViewTraceInfo &vti) const
Check whether filter is true for view trace information vti.
Definition filter.hpp:270
Gecode::TraceFilter::TFO::TFO
TFO(void)
Initialize without any filter and with fixpoint and done tracing.
Definition filter.hpp:247
Gecode::TraceFilter::TFO::n
int n
The number of filters.
Definition filter.hpp:159
Gecode::TraceFilter::TFO::fill
void fill(TFE::Node *n)
Fill the filters.
Definition filter.cpp:159
Gecode::TraceFilter::TFO::f
Filter * f
The filters.
Definition filter.hpp:161
Gecode::TraceFilter::TFO::~TFO
virtual ~TFO(void)
Destructor.
Definition filter.cpp:183
Gecode::TraceFilter
Trace filters.
Definition filter.hpp:133
Gecode::TraceFilter::operator()
bool operator()(const ViewTraceInfo &vti) const
Check whether filter is true for view trace information vti.
Definition filter.hpp:299
Gecode::TraceFilter::TraceFilter
TraceFilter(void)
Initialize without any filter.
Definition filter.cpp:187
Gecode::TraceFilter::all
static TraceFilter all
Default filter: without any filter.
Definition filter.hpp:210
Gecode::TraceFilter::operator=
TraceFilter & operator=(const TraceFilter &tf)
Assignment operator.
Definition filter.cpp:198
Gecode::ViewTraceInfo
View trace information.
Definition core.hpp:908
Gecode::ViewTraceInfo::what
What what(void) const
Return what is currently executing.
Definition core.hpp:3332
Gecode::ViewTraceInfo::brancher
void brancher(Brancher &b)
Record that brancher b is executing.
Definition core.hpp:3320
Gecode::ViewTraceInfo::BRANCHER
@ BRANCHER
A brancher is executing.
Definition core.hpp:917
Gecode::ViewTraceInfo::OTHER
@ OTHER
Unknown.
Definition core.hpp:921
Gecode::ViewTraceInfo::POST
@ POST
A post function is executing.
Definition core.hpp:919
Gecode::ViewTraceInfo::PROPAGATOR
@ PROPAGATOR
A propagator is currently executing.
Definition core.hpp:915
Gecode::ViewTraceInfo::propagator
void propagator(Propagator &p)
Record that propagator p is executing.
Definition core.hpp:3316
Gecode::ViewTraceInfo::post
void post(PropagatorGroup g)
Record that a post function with propagator group g is executing.
Definition core.hpp:3324
Gecode::heap
Heap heap
The single global heap.
Definition heap.cpp:44
GECODE_KERNEL_EXPORT
#define GECODE_KERNEL_EXPORT
Definition kernel.hh:70
Gecode
Gecode toplevel namespace
Gecode::operator-
FloatVal operator-(const FloatVal &x)
Definition val.hpp:168
Gecode::operator+
FloatVal operator+(const FloatVal &x)
Definition val.hpp:164
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
Gecode::propagator
TFE propagator(PropagatorGroup g)
Only propagators (but not post functions) from g are considered.
Definition filter.cpp:131
Gecode::TraceFilter::TFO::Filter
Filter information.
Definition filter.hpp:139
Gecode::TraceFilter::TFO::Filter::g
Group g
The filter group.
Definition filter.hpp:141
Gecode::TraceFilter::TFO::Filter::neg
bool neg
Whether the filter is negative.
Definition filter.hpp:143
Gecode::TraceFilter::TFO::Filter::what
char what
One bit set for each operation type.
Definition filter.hpp:145
forceinline
#define forceinline
Definition config.hpp:187
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56