/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * 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. * */ namespace Gecode { namespace Int { namespace Count { template forceinline ViewBase::ViewBase(Home home, ViewArray& x0, VY y0, VZ z0, int c0) : Propagator(home), x(x0), y(y0), z(z0), c(c0) { if (isintset(y)) home.notice(*this,AP_DISPOSE); x.subscribe(home,*this,PC_INT_DOM); subscribe(home,*this,y); z.subscribe(home,*this,PC_INT_BND); } template forceinline ViewBase::ViewBase(Space& home, ViewBase& p) : Propagator(home,p), c(p.c) { x.update(home,p.x); update(y,home,p.y); z.update(home,p.z); } template PropCost ViewBase::cost(const Space&, const ModEventDelta&) const { return PropCost::linear(PropCost::LO,x.size()+1); } template void ViewBase::reschedule(Space& home) { x.reschedule(home,*this,PC_INT_DOM); Gecode::Int::Count::reschedule(home,*this,y); z.reschedule(home,*this,PC_INT_BND); } template forceinline size_t ViewBase::dispose(Space& home) { if (isintset(y)) home.ignore(*this,AP_DISPOSE); x.cancel(home,*this,PC_INT_DOM); cancel(home,*this,y); z.cancel(home,*this,PC_INT_BND); (void) Propagator::dispose(home); return sizeof(*this); } template forceinline void ViewBase::count(Space& home) { int n = x.size(); for (int i=n; i--; ) switch (holds(x[i],y)) { case RT_FALSE: x[i].cancel(home,*this,PC_INT_DOM); x[i]=x[--n]; break; case RT_TRUE: x[i].cancel(home,*this,PC_INT_DOM); x[i]=x[--n]; c--; break; case RT_MAYBE: break; default: GECODE_NEVER; } x.size(n); } template forceinline int ViewBase::atleast(void) const { return -c; } template forceinline int ViewBase::atmost(void) const { return x.size()-c; } template forceinline bool shared(const IntSet&, VX) { return false; } template forceinline bool ViewBase::sharing(const ViewArray& x, const VY& y, const VZ& z) { if (shared(y,z)) return true; for (int i=0; i