/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2007 * * Last modified: * $Date: 2008-07-11 10:26:26 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $ * $Revision: 7330 $ * * 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 Circuit { /* * The actual propagator * */ template forceinline Val::Val(Space* home, ViewArray& x) : Base(home,x) {} template forceinline Val::Val(Space* home, bool share, Val& p) : Base(home,share,p) {} template Actor* Val::copy(Space* home, bool share) { return new (home) Val(home,share,*this); } template PropCost Val::cost(ModEventDelta) const { return PC_LINEAR_HI; } template Support::Symbol Val::ati(void) { return Reflection::mangle("Gecode::Int::Circuit::Val"); } template Reflection::ActorSpec Val::spec(const Space* home, Reflection::VarMap& m) const { return Base::spec(home, m, ati()); } template void Val::post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec) { spec.checkArity(1); ViewArray x(home, vars, spec[0]); (void) new (home) Val(home, x); } template ExecStatus Val::propagate(Space* home, ModEventDelta) { GECODE_ES_CHECK((Distinct::prop_val(home,y))); ExecStatus esc = connected(home); if (esc != ES_FIX) return esc; /* * One cannot have a single unassigned view as the views constitute * a permutation. */ if (y.size() < 2) return ES_SUBSUMED(this,home); return path(home); } template ExecStatus Val::post(Space* home, ViewArray& x) { int n = x.size(); if (n == 1) { GECODE_ME_CHECK(x[0].eq(home,0)); } else if (n == 2) { GECODE_ME_CHECK(x[0].eq(home,1)); GECODE_ME_CHECK(x[1].eq(home,0)); } else { for (int i=n; i--; ) { GECODE_ME_CHECK(x[i].gq(home,0)); GECODE_ME_CHECK(x[i].le(home,n)); GECODE_ME_CHECK(x[i].nq(home,i)); } (void) new (home) Val(home,x); } return ES_OK; } }}} // STATISTICS: int-prop