/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2006 * * Last modified: * $Date: 2008-07-11 10:46:48 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $ * $Revision: 7346 $ * * 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(Space* home, const IntVarArgs& x, unsigned int xoff, const IntVarArgs& y, unsigned int yoff, IntConLevel icl, PropKind) { using namespace Int; using namespace Channel; int n = x.size(); if (n != y.size()) throw ArgumentSizeMismatch("Int::channel"); if (x.same() || y.same()) throw ArgumentSame("Int::channel"); if (home->failed()) return; if (n == 0) return; if (xoff < 2 && yoff < 2 && xoff == yoff) { if (icl == ICL_DOM) { DomInfo* di = DomInfo::allocate(home,2*(n+xoff)); for (int 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); } if (x.same(y)) { GECODE_ES_FAIL(home,(Dom::post(home,n+xoff,di))); } else { GECODE_ES_FAIL(home,(Dom::post(home,n+xoff,di))); } } else { ValInfo* vi = ValInfo::allocate(home,2*(n+xoff)); for (int 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); } if (x.same(y)) { GECODE_ES_FAIL(home,(Val::post(home,n+xoff,vi))); } else { GECODE_ES_FAIL(home,(Val::post(home,n+xoff,vi))); } } } else { if (icl == ICL_DOM) { DomInfo* di = DomInfo::allocate(home,2*n); for (int i=n; i--; ) { di[i ].init(OffsetView(x[i],-xoff),n); di[i+n].init(OffsetView(y[i],-yoff),n); } if (x.same(y)) { GECODE_ES_FAIL(home,(Dom::post(home,n,di))); } else { GECODE_ES_FAIL(home,(Dom::post(home,n,di))); } } else { ValInfo* vi = ValInfo::allocate(home,2*n); for (int i=n; i--; ) { vi[i ].init(OffsetView(x[i],-xoff),n); vi[i+n].init(OffsetView(y[i],-yoff),n); } if (x.same(y)) { GECODE_ES_FAIL(home,(Val::post(home,n,vi))); } else { GECODE_ES_FAIL(home,(Val::post(home,n,vi))); } } } } void channel(Space* home, const IntVarArgs& x, const IntVarArgs& y, IntConLevel icl, PropKind pk) { channel(home, x, 0, y, 0, icl, pk); } void channel(Space* home, BoolVar x0, IntVar x1, IntConLevel, PropKind) { using namespace Int; if (home->failed()) return; GECODE_ES_FAIL(home,Channel::LinkSingle::post(home,x0,x1)); } void channel(Space* home, const BoolVarArgs& x, IntVar y, int o, IntConLevel, PropKind) { using namespace Int; if (x.same()) throw ArgumentSame("Int::channel"); Limits::check(o,"Int::channel"); if (home->failed()) return; ViewArray xv(home,x); GECODE_ES_FAIL(home,Channel::LinkMulti::post(home,xv,y,o)); } namespace { using namespace Int; GECODE_REGISTER2(Channel::Dom); GECODE_REGISTER2(Channel::Dom); GECODE_REGISTER2(Channel::Val); GECODE_REGISTER2(Channel::Val); GECODE_REGISTER2(Channel::Dom); GECODE_REGISTER2(Channel::Dom); GECODE_REGISTER2(Channel::Val); GECODE_REGISTER2(Channel::Val); GECODE_REGISTER1(Channel::LinkSingle); GECODE_REGISTER1(Channel::LinkMulti); } } // STATISTICS: int-post