/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * * Copyright: * Guido Tack, 2006 * * Last modified: * $Date: 2008-01-29 13:37:51 +0100 (Tue, 29 Jan 2008) $ by $Author: tack $ * $Revision: 5993 $ * * 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 Set { namespace Projection { forceinline CardProjection::CardProjection (Space* home, ViewArray& x0, Gecode::Int::IntView i0, Projector& p0) : Propagator(home), x(x0), i(i0), pc(x.size()), proj(p0) { force(home); Support::DynamicArray scope; for (int i=x0.size(); i--;) scope[i] = PC_SET_ANY + 1; p0.scope(scope); for (int i=x0.size(); i--;) { pc[i] = scope[i]; if (pc[i] != PC_SET_ANY + 1) x[i].subscribe(home, this, pc[i]); } } forceinline CardProjection::CardProjection (Space* home, bool share, CardProjection& p) : Propagator(home,share,p), proj(p.proj) { x.update(home,share,p.x); i.update(home,share,p.i); pc.update(home,share, p.pc); } forceinline PropCost CardProjection::cost(ModEventDelta) const { switch (x.size()) { case 1: return PC_UNARY_HI; case 2: return PC_BINARY_HI; case 3: return PC_TERNARY_HI; default: return PC_LINEAR_HI; } } inline Support::Symbol CardProjection::ati(void) { return Support::Symbol("set.projectors.CardProjection"); } forceinline Reflection::ActorSpec CardProjection::spec(const Space*, Reflection::VarMap&) const { throw Reflection::ReflectionException("Not implemented"); } inline size_t CardProjection::dispose(Space* home) { unforce(home); if (!home->failed()) { for (int i=x.size(); i--;) if (pc[i] != PC_SET_ANY + 1) x[i].cancel(home, this, pc[i]); } proj.~Projector(); pc.~SharedArray(); (void) Propagator::dispose(home); return sizeof(*this); } inline ExecStatus CardProjection::post(Space* home, ViewArray& x, Gecode::Int::IntView i, Projector& p) { (void) new (home) CardProjection(home,x,i,p); return ES_OK; } inline Actor* CardProjection::copy(Space* home, bool share) { return new (home) CardProjection(home,share,*this); } inline ExecStatus CardProjection::propagate(Space* home, ModEventDelta) { bool done = true; for (int j=x.size(); j--;) if (pc[j] != PC_SET_ANY + 1) done = done && x[j].assigned(); { GECODE_ME_CHECK(i.gq(home, static_cast(proj.glbSize(x)))); GECODE_ME_CHECK(i.lq(home, static_cast(proj.lubSize(x)))); } return done ? ES_SUBSUMED(this,home) : ES_FIX; } }}} // STATISTICS: set-prop