Generated on Mon Aug 25 11:35:34 2008 for Gecode by doxygen 1.5.6

singleton.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Patrick Pekczynski <pekczynski@ps.uni-sb.de>
00005  *
00006  *  Copyright:
00007  *     Patrick Pekczynski, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $
00011  *     $Revision: 6017 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace CpltSet {
00039 
00040   template <class View1, class View2>
00041   forceinline
00042   Singleton<View1, View2>::Singleton(Space* home, View1& x0, View2& s0)
00043     : Propagator(home), x(x0), s(s0) {
00044     force(home);
00045     x.subscribe(home, this, Gecode::Int::PC_INT_DOM);
00046     s.subscribe(home, this, PC_CPLTSET_DOM);
00047   }
00048 
00049   template <class View1, class View2>
00050   forceinline
00051   Singleton<View1, View2>::Singleton(Space* home, bool share, Singleton& p)
00052     : Propagator(home,share,p) {
00053     x.update(home, share, p.x);
00054     s.update(home, share, p.s);
00055   }
00056   
00057   template <class View1, class View2>
00058   forceinline PropCost
00059   Singleton<View1, View2>::cost(ModEventDelta) const {
00060     return PC_BINARY_LO;
00061   }
00062 
00063   template <class View1, class View2>
00064   Support::Symbol
00065   Singleton<View1,View2>::ati(void) {
00066     return Reflection::mangle<View1,View2>("Gecode::CpltSet::Singleton");
00067   }
00068 
00069   template <class View1, class View2>
00070   Reflection::ActorSpec
00071   Singleton<View1,View2>::spec(const Space*, Reflection::VarMap&) const {
00072     throw Reflection::ReflectionException("Not implemented");
00073   } 
00074   
00075   template <class View1, class View2>
00076   size_t
00077   Singleton<View1, View2>::dispose(Space* home) {
00078     unforce(home);
00079     if (!home->failed()) {
00080       x.cancel(home, this, Gecode::Int::PC_INT_DOM);
00081       s.cancel(home, this, PC_CPLTSET_DOM);
00082     }
00083     Propagator::dispose(home);
00084     return sizeof(*this);
00085   }
00086 
00087   template <class View1, class View2>
00088   forceinline ExecStatus
00089   Singleton<View1, View2>::post(Space* home, View1& x0, View2& s0) {
00090     (void) new (home) Singleton(home, x0, s0);
00091     return ES_OK;
00092   }
00093 
00094   template <class View1, class View2>
00095   forceinline Actor*
00096   Singleton<View1, View2>::copy(Space* home, bool share) {
00097     return new (home) Singleton(home, share, *this);
00098   }
00099 
00100   template <class View1, class View2>
00101   forceinline ExecStatus 
00102   Singleton<View1, View2>::propagate(Space* home, ModEventDelta) {
00103     if (x.assigned()) {
00104       GECODE_ME_CHECK(s.eq(home, x.val()));
00105       return ES_SUBSUMED(this, home);
00106     } else {
00107       // compute intersection
00108       Gecode::Int::ViewRanges<View1> dom(x);
00109       Set::LubRanges<View2>  lub(s);
00110       Iter::Ranges::Inter<Gecode::Int::ViewRanges<View1>, 
00111                           Set::LubRanges<View2> > common(dom, lub);
00112       if (!common()) {
00113         return ES_FAILED;
00114       }
00115       Iter::Ranges::Cache<
00116         Iter::Ranges::Inter<Gecode::Int::ViewRanges<View1>, 
00117                             Set::LubRanges<View2> > > cache_inter(common);
00118         
00119       GECODE_ME_CHECK(x.inter_r(home, cache_inter));
00120       cache_inter.reset();
00121       GECODE_ME_CHECK(s.intersectI(home, cache_inter));
00122       return ES_FIX;
00123     }
00124   }
00125 
00126 
00127 
00128 }}
00129 
00130 // STATISTICS: cpltset-prop