/* * Main authors: * Guido Tack * * Copyright: * Guido Tack, 2006 * * Last modified: * $Date: 2006-08-17 11:46:13 +0200 (Thu, 17 Aug 2006) $ by $Author: tack $ * $Revision: 3544 $ * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * See the file "LICENSE" for information on usage and * redistribution of this file, and for a * DISCLAIMER OF ALL WARRANTIES. * */ namespace Gecode { namespace Set { namespace Projection { template forceinline NaryProjection::NaryProjection (Space* home, ViewArray& x0, ProjectorSet& ps0) : Propagator(home,true), x(x0), ps(ps0) { Support::DynamicArray scope; ps.scope(scope); pc.ensure(x.size()); for (int i=x0.size(); i--;) { pc[i] = scope[i]; if (negated) pc[i] = ComplementView::pc_negateset(pc[i]); x[i].subscribe(home, this, pc[i]); } } template forceinline NaryProjection::NaryProjection (Space* home, bool share, NaryProjection& p) : Propagator(home,share,p), ps(p.ps) { x.update(home,share,p.x); pc.update(share, p.pc); } template forceinline PropCost NaryProjection::cost(void) 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; } } template size_t NaryProjection::dispose(Space* home) { if (!home->failed()) { for (int i=x.size(); i--;) if (pc[i] != PC_SET_ANY + 1) x[i].cancel(home, this, pc[i]); } ps.~ProjectorSet(); pc.~SharedArray(); Propagator::dispose(home); return sizeof(*this); } template ExecStatus NaryProjection::post(Space* home, ViewArray& x, ProjectorSet& ps) { if (ps.arity() != x.size()-1) { throw Set::InvalidProjector(""); } (void) new (home) NaryProjection(home,x,ps); return ES_OK; } template Actor* NaryProjection::copy(Space* home, bool share) { return new (home) NaryProjection(home,share,*this); } template ExecStatus NaryProjection::propagate(Space* home) { bool done = true; for (int i=x.size(); i--;) if (!x[i].assigned()) { done = false; break; } ExecStatus es = ps.propagate(home, x); GECODE_ES_CHECK(es); return done ? ES_SUBSUMED : es; } }}} // STATISTICS: set-prop