/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * Christian Schulte * Gabor Szokoli * * Copyright: * Guido Tack, 2004 * Christian Schulte, 2004 * Gabor Szokoli, 2004 * * Last modified: * $Date: 2008-02-06 18:48:22 +0100 (Wed, 06 Feb 2008) $ by $Author: schulte $ * $Revision: 6102 $ * * 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.hh" namespace Gecode { namespace Set { namespace Int { template forceinline ChannelInt::ChannelInt(Space* home, ViewArray& xs0, ViewArray& ys0) : Propagator(home), xs(xs0), ys(ys0) { xs.subscribe(home,this, Gecode::Int::PC_INT_DOM); ys.subscribe(home,this, PC_SET_ANY); } template forceinline ChannelInt::ChannelInt(Space* home, bool share, ChannelInt& p) : Propagator(home,share,p) { xs.update(home,share,p.xs); ys.update(home,share,p.ys); } template forceinline ExecStatus ChannelInt::post(Space* home, ViewArray& xs, ViewArray& ys) { // Sharing of ys is taken care of in the propagator: // The ys are propagated to be disjoint, so shared variables // result in failure. unsigned int xssize = xs.size(); for (int i=ys.size(); i--;) { GECODE_ME_CHECK(ys[i].exclude(home, xssize, Limits::max)); GECODE_ME_CHECK(ys[i].exclude(home, Limits::min, -1)); } unsigned int yssize = ys.size(); if (yssize > static_cast(Gecode::Int::Limits::max)) return ES_FAILED; for (int i=xs.size(); i--;) { GECODE_ME_CHECK(xs[i].gq(home, 0)); GECODE_ME_CHECK(xs[i].le(home, static_cast(yssize))); } (void) new (home) ChannelInt(home,xs,ys); return ES_OK; } template PropCost ChannelInt::cost(ModEventDelta) const { return PC_QUADRATIC_LO; } template size_t ChannelInt::dispose(Space* home) { assert(!home->failed()); xs.cancel(home,this, Gecode::Int::PC_INT_DOM); ys.cancel(home,this, PC_SET_ANY); (void) Propagator::dispose(home); return sizeof(*this); } template Actor* ChannelInt::copy(Space* home, bool share) { return new (home) ChannelInt(home,share,*this); } template ExecStatus ChannelInt::propagate(Space* home, ModEventDelta) { int assigned = 0; for (int v=xs.size(); v--;) { if (xs[v].assigned()) { assigned += 1; for (int i=ys.size(); i--;) { if (i==xs[v].val()) { GECODE_ME_CHECK(ys[i].include(home, v)); } else { GECODE_ME_CHECK(ys[i].exclude(home, v)); } } } else { for (int i=ys.size(); i--;) { if (ys[i].notContains(v)) { GECODE_ME_CHECK(xs[v].nq(home, i)); } if (ys[i].contains(v)) { GECODE_ME_CHECK(xs[v].eq(home, i)); } } Gecode::Int::ViewRanges xsv(xs[v]); int min = 0; for (; xsv(); ++xsv) { for (int i=min; i Support::Symbol ChannelInt::ati(void) { return Reflection::mangle("Gecode::Set::Int::ChannelInt"); } template Reflection::ActorSpec ChannelInt::spec(const Space* home, Reflection::VarMap& m) const { Reflection::ActorSpec s(ati()); return s << xs.spec(home, m) << ys.spec(home, m); } template void ChannelInt::post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec) { spec.checkArity(2); ViewArray x0(home, vars, spec[0]); ViewArray x1(home, vars, spec[1]); (void) new (home) ChannelInt(home,x0,x1); } }}} // STATISTICS: set-prop