filter.cpp
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.
*
*/
#include <gecode/kernel.hh>
namespace Gecode {
/*
* Trace filter expressions
*
*/
bool
TFE::Node::decrement(void) {
if (--use == 0) {
if ((l != NULL) && l->decrement())
delete l;
if ((r != NULL) && r->decrement())
delete r;
return true;
}
return false;
}
forceinline void
TFE::init(Group g, char what) {
n = new Node;
n->t = NT_GROUP;
n->g = g;
n->n = 1;
n->w = what;
}
inline TFE
TFE::negate(void) const {
Node* m = new Node;
m->t = NT_NEGATE;
m->n = n->n;
m->l = n; n->use++;
return TFE(m);
}
TFE::TFE(PropagatorGroup g) {
init(g,(1 << ViewTraceInfo::PROPAGATOR) | (1 << ViewTraceInfo::POST));
}
TFE::TFE(BrancherGroup g) {
init(g,(1 << ViewTraceInfo::BRANCHER));
}
TFE
TFE::other(void) {
TFE e;
e.init(Group::all,(1 << ViewTraceInfo::OTHER));
return e;
}
TFE::TFE(const TFE& e) : n(e.n) {
n->use++;
}
TFE&
TFE::operator =(const TFE& e) {
if (&e != this) {
if (n->decrement())
delete n;
n = e.n;
n->use++;
}
return *this;
}
TFE&
TFE::operator +=(const TFE& e) {
Node* a = new Node;
a->t = NT_ADD;
a->n = n->n + e.n->n;
a->l = n;
a->r = e.n; e.n->use++;
n = a;
return *this;
}
TFE&
TFE::operator -=(const TFE& e) {
return operator +=(e.negate());
}
TFE::~TFE(void) {
if (n->decrement())
delete n;
}
TFE
operator -(const TFE& e) {
return e.negate();
}
TFE
propagator(PropagatorGroup g) {
TFE e;
e.init(g,(1 << ViewTraceInfo::PROPAGATOR));
return e;
}
TFE
post(PropagatorGroup g) {
TFE e;
e.init(g,(1 << ViewTraceInfo::POST));
return e;
}
/*
* Trace filters
*
*/
forceinline
TraceFilter::TFO::StackFrame::StackFrame(void) {}
forceinline
TraceFilter::TFO::StackFrame::StackFrame(TFE::Node* n0, bool neg0)
: n(n0), neg(neg0) {}
void
TraceFilter::TFO::fill(TFE::Node* n) {
Region region;
Support::DynamicStack<StackFrame,Region> next(region);
int i=0;
next.push(StackFrame(n,false));
do {
StackFrame s = next.pop();
switch (s.n->t) {
case TFE::NT_GROUP:
f[i].g = s.n->g; f[i].neg = s.neg; f[i].what=s.n->w;
i++;
break;
case TFE::NT_NEGATE:
next.push(StackFrame(s.n->l,!s.neg));
break;
case TFE::NT_ADD:
next.push(StackFrame(s.n->l,s.neg));
next.push(StackFrame(s.n->r,s.neg));
break;
default: GECODE_NEVER;
}
} while (!next.empty());
}
TraceFilter::TFO::~TFO(void) {
heap.free<Filter>(f,n);
}
TraceFilter::TraceFilter(void) : SharedHandle(new TFO) {}
TraceFilter::TraceFilter(const TFE& e) : SharedHandle(new TFO(e)) {}
TraceFilter::TraceFilter(PropagatorGroup g) : SharedHandle(new TFO(g)) {}
TraceFilter::TraceFilter(BrancherGroup g) : SharedHandle(new TFO(g)) {}
TraceFilter::TraceFilter(const TraceFilter& tf) : SharedHandle(tf) {}
TraceFilter&
TraceFilter::operator =(const TraceFilter& tf) {
return static_cast<TraceFilter&>(SharedHandle::operator =(tf));
}
TraceFilter TraceFilter::all;
}
// STATISTICS: kernel-trace
Gecode::BrancherGroup
Group of branchers.
Definition core.hpp:799
Gecode::Group
Group baseclass for controlling actors.
Definition core.hpp:673
Gecode::Group::all
static Group all
Group of all actors.
Definition core.hpp:717
Gecode::PropagatorGroup
Group of propagators.
Definition core.hpp:727
Gecode::Region
Handle to region.
Definition region.hpp:55
Gecode::SharedHandle::operator=
SharedHandle & operator=(const SharedHandle &sh)
Assignment operator maintaining reference count.
Definition shared-object.hpp:132
Gecode::SharedHandle::SharedHandle
SharedHandle(void)
Create shared handle with no object pointing to.
Definition shared-object.hpp:122
Gecode::Support::DynamicStack
Stack with arbitrary number of elements.
Definition dynamic-stack.hpp:42
Gecode::Support::DynamicStack::push
void push(const T &x)
Push element x on top of stack.
Definition dynamic-stack.hpp:140
Gecode::Support::DynamicStack::empty
bool empty(void) const
Test whether stack is empty.
Definition dynamic-stack.hpp:148
Gecode::Support::DynamicStack::pop
T pop(void)
Pop topmost element from stack and return it.
Definition dynamic-stack.hpp:122
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::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::other
static TFE other(void)
Expression for other than propagator, brancher, or post.
Definition filter.cpp:82
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::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::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::TFE
TFE(void)
Initialize with no node.
Definition filter.hpp:224
Gecode::TraceFilter::TFO::StackFrame
Definition filter.hpp:147
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::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::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::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::heap
Heap heap
The single global heap.
Definition heap.cpp:44
kernel.hh
Gecode
Gecode toplevel namespace
Gecode::operator-
FloatVal operator-(const FloatVal &x)
Definition val.hpp:168
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
forceinline
#define forceinline
Definition config.hpp:187
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56