box.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, 2011
*
* 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 Int { namespace NoOverlap {
/*
* Mandatory boxes
*
*/
template<class Dim, int n>
forceinline const Dim&
ManBox<Dim,n>::operator [](int i) const {
assert((i >= 0) && (i < n));
return d[i];
}
template<class Dim, int n>
forceinline Dim&
ManBox<Dim,n>::operator [](int i) {
assert((i >= 0) && (i < n));
return d[i];
}
template<class Dim, int n>
forceinline int
ManBox<Dim,n>::dim(void) {
return n;
}
template<class Dim, int n>
forceinline bool
ManBox<Dim,n>::mandatory(void) const {
return true;
}
template<class Dim, int n>
forceinline bool
ManBox<Dim,n>::excluded(void) const {
return false;
}
template<class Dim, int n>
forceinline bool
ManBox<Dim,n>::optional(void) const {
return false;
}
template<class Dim, int n>
forceinline ExecStatus
ManBox<Dim,n>::exclude(Space&) {
return ES_FAILED;
}
template<class Dim, int n>
forceinline bool
ManBox<Dim,n>::nooverlap(const ManBox<Dim,n>& box) const {
for (int i=0; i<n; i++)
if ((d[i].lec() <= box.d[i].ssc()) || (box.d[i].lec() <= d[i].ssc()))
return true;
return false;
}
template<class Dim, int n>
forceinline bool
ManBox<Dim,n>::overlap(const ManBox<Dim,n>& box) const {
for (int i=0; i<n; i++)
if ((d[i].sec() <= box.d[i].lsc()) || (box.d[i].sec() <= d[i].lsc()))
return false;
return true;
}
template<class Dim, int n>
forceinline ExecStatus
ManBox<Dim,n>::nooverlap(Space& home, ManBox<Dim,n>& box) {
for (int i=0; i<n; i++)
if ((d[i].sec() <= box.d[i].lsc()) ||
(box.d[i].sec() <= d[i].lsc())) {
// Does not overlap for dimension i
for (int j=i+1; j<n; j++)
if ((d[j].sec() <= box.d[j].lsc()) ||
(box.d[j].sec() <= d[j].lsc()))
return ES_OK;
// Does not overlap for only dimension i, hence propagate
d[i].nooverlap(home, box.d[i]);
box.d[i].nooverlap(home, d[i]);
return ES_OK;
}
// Overlaps in all dimensions
return ES_FAILED;
}
template<class Dim, int n>
forceinline void
ManBox<Dim,n>::update(Space& home, ManBox<Dim,n>& b) {
for (int i=0; i<n; i++)
d[i].update(home,b.d[i]);
}
template<class Dim, int n>
forceinline void
ManBox<Dim,n>::subscribe(Space& home, Propagator& p) {
for (int i=0; i<n; i++)
d[i].subscribe(home,p);
}
template<class Dim, int n>
forceinline void
ManBox<Dim,n>::cancel(Space& home, Propagator& p) {
for (int i=0; i<n; i++)
d[i].cancel(home,p);
}
template<class Dim, int n>
forceinline void
ManBox<Dim,n>::reschedule(Space& home, Propagator& p) {
for (int i=0; i<n; i++)
d[i].reschedule(home,p);
}
/*
* Optional boxes
*
*/
template<class Dim, int n>
forceinline void
OptBox<Dim,n>::optional(BoolView o0) {
o = o0;
}
template<class Dim, int n>
forceinline bool
OptBox<Dim,n>::mandatory(void) const {
return o.one();
}
template<class Dim, int n>
forceinline bool
OptBox<Dim,n>::excluded(void) const {
return o.zero();
}
template<class Dim, int n>
forceinline bool
OptBox<Dim,n>::optional(void) const {
return o.none();
}
template<class Dim, int n>
forceinline ExecStatus
OptBox<Dim,n>::exclude(Space& home) {
GECODE_ME_CHECK(o.zero(home));
return ES_OK;
}
template<class Dim, int n>
forceinline void
OptBox<Dim,n>::update(Space& home, OptBox<Dim,n>& b) {
ManBox<Dim,n>::update(home, b);
o.update(home, b.o);
}
template<class Dim, int n>
forceinline void
OptBox<Dim,n>::subscribe(Space& home, Propagator& p) {
ManBox<Dim,n>::subscribe(home,p);
o.subscribe(home, p, PC_BOOL_VAL);
}
template<class Dim, int n>
forceinline void
OptBox<Dim,n>::cancel(Space& home, Propagator& p) {
ManBox<Dim,n>::cancel(home,p);
o.cancel(home, p, PC_BOOL_VAL);
}
template<class Dim, int n>
forceinline void
OptBox<Dim,n>::reschedule(Space& home, Propagator& p) {
ManBox<Dim,n>::reschedule(home,p);
o.reschedule(home, p, PC_BOOL_VAL);
}
}}}
// STATISTICS: int-prop
Gecode::Int::BoolView
Boolean view for Boolean variables.
Definition view.hpp:1380
Gecode::Int::NoOverlap::ManBox
Mandatory box class.
Definition no-overlap.hh:146
Gecode::Int::NoOverlap::ManBox::d
Dim d[n]
Dimensions.
Definition no-overlap.hh:149
Gecode::Int::NoOverlap::ManBox::dim
static int dim(void)
Return number of dimensions.
Definition box.hpp:54
Gecode::Int::NoOverlap::ManBox::nooverlap
bool nooverlap(const ManBox< Dim, n > &b) const
Check whether this box does not any longer overlap with b.
Definition box.hpp:82
Gecode::Int::NoOverlap::ManBox::operator[]
const Dim & operator[](int i) const
Access to dimension i.
Definition box.hpp:42
Gecode::Int::NoOverlap::ManBox::reschedule
void reschedule(Space &home, Propagator &p)
Schedule propagator p.
Definition box.hpp:139
Gecode::Int::NoOverlap::ManBox::update
void update(Space &home, ManBox< Dim, n > &r)
Update box during cloning.
Definition box.hpp:120
Gecode::Int::NoOverlap::ManBox::overlap
bool overlap(const ManBox< Dim, n > &b) const
Check whether this box overlaps with b.
Definition box.hpp:91
Gecode::Int::NoOverlap::ManBox::excluded
bool excluded(void) const
Whether box is excluded.
Definition box.hpp:65
Gecode::Int::NoOverlap::ManBox::mandatory
bool mandatory(void) const
Whether box is mandatory.
Definition box.hpp:60
Gecode::Int::NoOverlap::ManBox::subscribe
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to box.
Definition box.hpp:127
Gecode::Int::NoOverlap::ManBox::optional
bool optional(void) const
Whether box is optional.
Definition box.hpp:70
Gecode::Int::NoOverlap::ManBox::exclude
ExecStatus exclude(Space &home)
Exclude box.
Definition box.hpp:76
Gecode::Int::NoOverlap::ManBox::cancel
void cancel(Space &home, Propagator &p)
Cancel propagator p from box.
Definition box.hpp:133
Gecode::Int::NoOverlap::OptBox
Optional box class.
Definition no-overlap.hh:191
Gecode::Int::NoOverlap::OptBox::update
void update(Space &home, OptBox< Dim, n > &r)
Update box during cloning.
Definition box.hpp:179
Gecode::Int::NoOverlap::OptBox::o
BoolView o
Whether box is optional or not.
Definition no-overlap.hh:195
Gecode::Int::NoOverlap::OptBox::optional
bool optional(void) const
Whether box is optional.
Definition box.hpp:166
Gecode::Int::NoOverlap::OptBox::mandatory
bool mandatory(void) const
Whether box is mandatory.
Definition box.hpp:156
Gecode::Int::NoOverlap::OptBox::exclude
ExecStatus exclude(Space &home)
Exclude box.
Definition box.hpp:172
Gecode::Int::NoOverlap::OptBox::reschedule
void reschedule(Space &home, Propagator &p)
Schedule propagator p.
Definition box.hpp:198
Gecode::Int::NoOverlap::OptBox::subscribe
void subscribe(Space &home, Propagator &p)
Subscribe propagator p to box.
Definition box.hpp:186
Gecode::Int::NoOverlap::OptBox::cancel
void cancel(Space &home, Propagator &p)
Cancel propagator p from box.
Definition box.hpp:192
Gecode::Int::NoOverlap::OptBox::excluded
bool excluded(void) const
Whether box is excluded.
Definition box.hpp:161
Gecode::Propagator
Base-class for propagators.
Definition core.hpp:1064
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::Int::OffsetView::update
void update(const NoOffset &)
Integer-precision integer scale view.
Definition view.hpp:638
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
Gecode::Int::NoOverlap
No-overlap propagators
Definition no-overlap.cpp:38
Gecode::Int
Finite domain integers.
Gecode::Int::PC_BOOL_VAL
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value).
Definition var-type.hpp:126
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_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
forceinline
#define forceinline
Definition config.hpp:187