channel.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>
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Christian Schulte, 2006
* Guido Tack, 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.
*
*/
#include <gecode/int/channel.hh>
namespace Gecode {
void
channel(Home home, const IntVarArgs& x, int xoff,
const IntVarArgs& y, int yoff,
IntPropLevel ipl) {
using namespace Int;
using namespace Channel;
int n = x.size();
if (n != y.size())
throw ArgumentSizeMismatch("Int::channel");
if (same(x) || same(y))
throw ArgumentSame("Int::channel");
Limits::check(xoff,"Int::channel");
Limits::check(yoff,"Int::channel");
if ((xoff < 0) || (yoff < 0))
throw OutOfLimits("Int::channel");
GECODE_POST;
if (n == 0)
return;
if ((xoff < 2) && (yoff < 2) && (xoff == yoff)) {
if (vbd(ipl) == IPL_DOM) {
DomInfo<IntView,NoOffset<IntView> >* di =
static_cast<Space&>(home).
alloc<DomInfo<IntView,NoOffset<IntView> > >(2*(n+xoff));
for (int i=0; i<n; i++) {
di[xoff+i ].init(x[i],n+xoff);
di[2*xoff+i+n].init(y[i],n+xoff);
}
if (xoff == 1) {
IntVar x0(home,0,0);
di[0].init(x0, n+xoff);
IntVar y0(home,0,0);
di[n+xoff].init(y0, n+xoff);
}
NoOffset<IntView> noff;
if (same(x,y)) {
GECODE_ES_FAIL((Dom<IntView,NoOffset<IntView>,true>
::post(home,n+xoff,di,noff,noff)));
} else {
GECODE_ES_FAIL((Dom<IntView,NoOffset<IntView>,false>
::post(home,n+xoff,di,noff,noff)));
}
} else {
ValInfo<IntView>* vi =
static_cast<Space&>(home).alloc<ValInfo<IntView> >(2*(n+xoff));
for (int i=0; i<n; i++) {
vi[xoff+i ].init(x[i],n+xoff);
vi[2*xoff+i+n].init(y[i],n+xoff);
}
if (xoff == 1) {
IntVar x0(home,0,0);
vi[0].init(x0, n+xoff);
IntVar y0(home,0,0);
vi[n+xoff].init(y0, n+xoff);
}
NoOffset<IntView> noff;
if (same(x,y)) {
GECODE_ES_FAIL((Val<IntView,NoOffset<IntView>,true>
::post(home,n+xoff,vi,noff,noff)));
} else {
GECODE_ES_FAIL((Val<IntView,NoOffset<IntView>,false>
::post(home,n+xoff,vi,noff,noff)));
}
}
} else {
if (vbd(ipl) == IPL_DOM) {
DomInfo<IntView,Offset>* di =
static_cast<Space&>(home).alloc<DomInfo<IntView,Offset> >(2*n);
for (int i=0; i<n; i++) {
di[i ].init(x[i],n);
di[i+n].init(y[i],n);
}
Offset ox(-xoff);
Offset oy(-yoff);
if (same(x,y)) {
GECODE_ES_FAIL((Dom<IntView,Offset,true>
::post(home,n,di,ox,oy)));
} else {
GECODE_ES_FAIL((Dom<IntView,Offset,false>
::post(home,n,di,ox,oy)));
}
} else {
ValInfo<IntView>* vi =
static_cast<Space&>(home).alloc<ValInfo<IntView> >(2*n);
for (int i=0; i<n; i++) {
vi[i ].init(x[i],n);
vi[i+n].init(y[i],n);
}
Offset ox(-xoff);
Offset oy(-yoff);
if (same(x,y)) {
GECODE_ES_FAIL((Val<IntView,Offset,true>
::post(home,n,vi,ox,oy)));
} else {
GECODE_ES_FAIL((Val<IntView,Offset,false>
::post(home,n,vi,ox,oy)));
}
}
}
}
void
channel(Home home, const IntVarArgs& x, const IntVarArgs& y,
IntPropLevel ipl) {
channel(home, x, 0, y, 0, ipl);
}
void
channel(Home home, BoolVar x0, IntVar x1, IntPropLevel) {
using namespace Int;
GECODE_POST;
GECODE_ES_FAIL(Channel::LinkSingle::post(home,x0,x1));
}
void
channel(Home home, const BoolVarArgs& x, IntVar y, int o,
IntPropLevel) {
using namespace Int;
if (same(x))
throw ArgumentSame("Int::channel");
Limits::check(o,"Int::channel");
GECODE_POST;
ViewArray<BoolView> xv(home,x);
GECODE_ES_FAIL(Channel::LinkMulti::post(home,xv,y,o));
}
}
// STATISTICS: int-post
Gecode::ArgArrayBase::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1607
Gecode::BoolVarArgs
Passing Boolean variables.
Definition int.hh:712
Gecode::BoolVar
Boolean integer variables.
Definition int.hh:512
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::IntVarArgs
Passing integer variables.
Definition int.hh:656
Gecode::IntVar
Integer variables.
Definition int.hh:371
Gecode::Int::ArgumentSame
Exception: Arguments contain same variable multiply
Definition exception.hpp:80
Gecode::Int::ArgumentSizeMismatch
Exception: Arguments are of different size
Definition exception.hpp:73
Gecode::Int::Channel::LinkMulti::post
static ExecStatus post(Home home, ViewArray< BoolView > &x, IntView y, int o)
Post propagator for .
Definition link-multi.hpp:53
Gecode::Int::Channel::LinkSingle::post
static ExecStatus post(Home home, BoolView x0, IntView x1)
Post propagator for .
Definition link-single.hpp:42
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::NoOffset
Converter without offsets.
Definition view.hpp:618
Gecode::Int::Offset
Converter with fixed offset.
Definition view.hpp:650
Gecode::Int::OutOfLimits
Exception: Value out of limits
Definition exception.hpp:44
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::Val
Gecode::ViewArray
View arrays.
Definition array.hpp:253
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition macros.hpp:40
GECODE_ES_FAIL
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition macros.hpp:103
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
Gecode::IPL_DOM
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:979
channel.hh
Gecode::Int::Channel
Channel propagators
Gecode::Int::Dom
Domain propagators.
Gecode::Int::Limits::check
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition limits.hpp:46
Gecode::Int
Finite domain integers.
Gecode
Gecode toplevel namespace
Gecode::channel
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition channel.cpp:41
Gecode::vbd
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition ipl.hpp:37
Gecode::same
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition array.hpp:1937
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138