dom.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, 2003
*
* 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 <climits>
namespace Gecode { namespace Int { namespace Distinct {
template<class View>
forceinline
Dom<View>::Dom(Home home, ViewArray<View>& x)
: NaryPropagator<View,PC_INT_DOM>(home,x) {}
template<class View>
ExecStatus
Dom<View>::post(Home home, ViewArray<View>& x) {
if (x.size() == 2)
return Rel::Nq<View,View>::post(home,x[0],x[1]);
if (x.size() == 3)
return TerDom<View>::post(home,x[0],x[1],x[2]);
if (x.size() > 3) {
// Do bounds propagation to make view-value graph smaller
GECODE_ES_CHECK(prop_bnd<View>(home,x));
(void) new (home) Dom<View>(home,x);
}
return ES_OK;
}
template<class View>
forceinline
Dom<View>::Dom(Space& home, Dom<View>& p)
: NaryPropagator<View,PC_INT_DOM>(home,p) {}
template<class View>
PropCost
Dom<View>::cost(const Space&, const ModEventDelta& med) const {
if (View::me(med) == ME_INT_VAL)
return PropCost::linear(PropCost::LO, x.size());
else
return PropCost::quadratic(PropCost::HI, x.size());
}
template<class View>
Actor*
Dom<View>::copy(Space& home) {
return new (home) Dom<View>(home,*this);
}
#ifdef GECODE_HAS_CBS
template<class View>
void
Dom<View>::solndistrib(Space& home, Propagator::SendMarginal send) const {
cbsdistinct(home,this->id(),x,send);
}
template<class View>
void
Dom<View>::domainsizesum(Propagator::InDecision in, unsigned int& size,
unsigned int& size_b) const {
cbssize(x,in,size,size_b);
}
#endif
template<class View>
ExecStatus
Dom<View>::propagate(Space& home, const ModEventDelta& med) {
if (View::me(med) == ME_INT_VAL) {
ExecStatus es = prop_val<View,false>(home,x);
GECODE_ES_CHECK(es);
if (x.size() < 2)
return home.ES_SUBSUMED(*this);
if (es == ES_FIX)
return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
es = prop_bnd<View>(home,x);
GECODE_ES_CHECK(es);
if (x.size() < 2)
return home.ES_SUBSUMED(*this);
es = prop_val<View,true>(home,x);
GECODE_ES_CHECK(es);
if (x.size() < 2)
return home.ES_SUBSUMED(*this);
return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
}
if (x.size() == 2)
GECODE_REWRITE(*this,(Rel::Nq<View,View>::post(home(*this),x[0],x[1])));
if (x.size() == 3)
GECODE_REWRITE(*this,TerDom<View>::post(home(*this),x[0],x[1],x[2]));
if (dc.available()) {
GECODE_ES_CHECK(dc.sync());
} else {
GECODE_ES_CHECK(dc.init(home,x));
}
bool assigned;
GECODE_ES_CHECK(dc.propagate(home,assigned));
return ES_FIX;
}
}}}
// STATISTICS: int-prop
Gecode::Actor
Base-class for both propagators and branchers.
Definition core.hpp:628
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::Distinct::Dom
Domain consistent distinct propagator.
Definition distinct.hh:283
Gecode::Int::Distinct::Dom::post
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for views x.
Definition dom.hpp:45
Gecode::Int::Distinct::Dom::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition dom.hpp:96
Gecode::Int::Distinct::Dom::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition dom.hpp:74
Gecode::Int::Distinct::Dom::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition dom.hpp:65
Gecode::Int::Distinct::Dom::Dom
Dom(Space &home, Dom< View > &p)
Constructor for cloning p.
Definition dom.hpp:60
Gecode::Int::Distinct::Dom::dc
DomCtrl< View > dc
Propagation controller.
Definition distinct.hh:287
Gecode::Int::Distinct::TerDom::post
static ExecStatus post(Home home, View x0, View x1, View x2)
Post propagator for views x.
Definition ter-dom.hpp:49
Gecode::Int::Rel::Nq::post
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition nq.hpp:49
Gecode::NaryPropagator< View, PC_INT_DOM >::x
ViewArray< View > x
Definition pattern.hpp:145
Gecode::NaryPropagator< View, PC_INT_DOM >::NaryPropagator
NaryPropagator(Space &home, NaryPropagator &p)
Gecode::PropCost
Propagation cost.
Definition core.hpp:486
Gecode::PropCost::quadratic
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition core.hpp:4787
Gecode::PropCost::linear
static PropCost linear(PropCost::Mod m, unsigned int n)
Linear complexity for modifier pcm and size measure n.
Definition core.hpp:4796
Gecode::PropCost::LO
@ LO
Cheap.
Definition core.hpp:513
Gecode::PropCost::HI
@ HI
Expensive.
Definition core.hpp:514
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
Gecode::Propagator::med
ModEventDelta med
A set of modification events (used during propagation).
Definition core.hpp:1075
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::View
Gecode::ViewArray
View arrays.
Definition array.hpp:253
Gecode::Space::ES_FIX_PARTIAL
ExecStatus ES_FIX_PARTIAL(Propagator &p, const ModEventDelta &med)
Propagator p has computed partial fixpoint
Definition core.hpp:3569
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition core.hpp:3563
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
GECODE_REWRITE
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
GECODE_ES_CHECK
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition macros.hpp:91
Gecode::Int::Distinct
Distinct propagators
Gecode::Int::Distinct::prop_bnd
ExecStatus prop_bnd(Space &home, ViewArray< View > &x, int &min_x, int &max_x)
Perform bounds consistent distinct propagation.
Definition bnd.hpp:308
Gecode::Int::Distinct::prop_val
ExecStatus prop_val(Space &home, ViewArray< View > &)
Eliminate singletons by naive value propagation.
Definition val.hpp:42
Gecode::Int::Dom
Domain propagators.
Gecode::Int
Finite domain integers.
Gecode::Int::PC_INT_DOM
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition var-type.hpp:100
Gecode::Int::ME_INT_VAL
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable).
Definition var-type.hpp:56
Gecode::Int::ME_INT_DOM
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
Definition var-type.hpp:72
Gecode
Gecode toplevel namespace
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
forceinline
#define forceinline
Definition config.hpp:187