/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Patrick Pekczynski * * Copyright: * Patrick Pekczynski, 2006 * * Last modified: * $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $ * $Revision: 6017 $ * * 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 CpltSet { template forceinline Singleton::Singleton(Space* home, View1& x0, View2& s0) : Propagator(home), x(x0), s(s0) { force(home); x.subscribe(home, this, Gecode::Int::PC_INT_DOM); s.subscribe(home, this, PC_CPLTSET_DOM); } template forceinline Singleton::Singleton(Space* home, bool share, Singleton& p) : Propagator(home,share,p) { x.update(home, share, p.x); s.update(home, share, p.s); } template forceinline PropCost Singleton::cost(ModEventDelta) const { return PC_BINARY_LO; } template Support::Symbol Singleton::ati(void) { return Reflection::mangle("Gecode::CpltSet::Singleton"); } template Reflection::ActorSpec Singleton::spec(const Space*, Reflection::VarMap&) const { throw Reflection::ReflectionException("Not implemented"); } template size_t Singleton::dispose(Space* home) { unforce(home); if (!home->failed()) { x.cancel(home, this, Gecode::Int::PC_INT_DOM); s.cancel(home, this, PC_CPLTSET_DOM); } Propagator::dispose(home); return sizeof(*this); } template forceinline ExecStatus Singleton::post(Space* home, View1& x0, View2& s0) { (void) new (home) Singleton(home, x0, s0); return ES_OK; } template forceinline Actor* Singleton::copy(Space* home, bool share) { return new (home) Singleton(home, share, *this); } template forceinline ExecStatus Singleton::propagate(Space* home, ModEventDelta) { if (x.assigned()) { GECODE_ME_CHECK(s.eq(home, x.val())); return ES_SUBSUMED(this, home); } else { // compute intersection Gecode::Int::ViewRanges dom(x); Set::LubRanges lub(s); Iter::Ranges::Inter, Set::LubRanges > common(dom, lub); if (!common()) { return ES_FAILED; } Iter::Ranges::Cache< Iter::Ranges::Inter, Set::LubRanges > > cache_inter(common); GECODE_ME_CHECK(x.inter_r(home, cache_inter)); cache_inter.reset(); GECODE_ME_CHECK(s.intersectI(home, cache_inter)); return ES_FIX; } } }} // STATISTICS: cpltset-prop