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

spec.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2004
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 Int { namespace Dom {
00039 
00040   template <class View>
00041   forceinline
00042   ReIntSet<View>::ReIntSet
00043   (Space* home, View x, const IntSet& s, BoolView b)
00044     : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,x,b), is(s) {
00045     Propagator::force(home);
00046   }
00047 
00048   template <class View>
00049   forceinline size_t
00050   ReIntSet<View>::dispose(Space* home) {
00051     Propagator::unforce(home);
00052     is.~IntSet();
00053     (void) ReUnaryPropagator<View,PC_INT_DOM,BoolView>::dispose(home);
00054     return sizeof(*this);
00055   }
00056 
00057   template <class View>
00058   ExecStatus
00059   ReIntSet<View>::post(Space* home, View x, const IntSet& s, BoolView b) {
00060     if (s.size() == 0) {
00061       GECODE_ME_CHECK(b.zero(home));
00062     } else if (s.size() == 1) {
00063       return ReRange<View>::post(home,x,s.min(),s.max(),b);
00064     } else {
00065       (void) new (home) ReIntSet<View>(home,x,s,b);
00066     }
00067     return ES_OK;
00068   }
00069 
00070 
00071   template <class View>
00072   forceinline
00073   ReIntSet<View>::ReIntSet(Space* home, bool share, ReIntSet& p)
00074     : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,share,p) {
00075     is.update(home,share,p.is);
00076   }
00077 
00078   template <class View>
00079   Actor*
00080   ReIntSet<View>::copy(Space* home, bool share) {
00081     return new (home) ReIntSet(home,share,*this);
00082   }
00083 
00084   template <class View>
00085   inline Support::Symbol
00086   ReIntSet<View>::ati(void) {
00087     return Reflection::mangle<View>("Gecode::Int::Dom::ReIntSet");
00088   }
00089 
00090   template <class View>
00091   Reflection::ActorSpec
00092   ReIntSet<View>::spec(const Space* home, Reflection::VarMap& m) const {
00093     Reflection::ActorSpec s =
00094       ReUnaryPropagator<View,PC_INT_DOM,BoolView>::spec(home, m, ati());
00095     int count=0;
00096     for (IntSetRanges isr(is); isr(); ++isr)
00097       count++;
00098     Reflection::IntArrayArg* a = Reflection::Arg::newIntArray(count*2);
00099     count = 0;
00100     for (IntSetRanges isr(is); isr(); ++isr) {
00101       (*a)[count++] = isr.min();
00102       (*a)[count++] = isr.max();
00103     }
00104     return s << a;
00105   }
00106 
00107   template <class View>
00108   void
00109   ReIntSet<View>::post(Space* home, Reflection::VarMap& vars,
00110                        const Reflection::ActorSpec& spec) {
00111     spec.checkArity(3);
00112     View x0(home, vars, spec[0]);
00113     BoolView b(home, vars, spec[1]);
00114     Reflection::IntArrayArgRanges r(spec[2]->toIntArray());
00115     (void) new (home) ReIntSet<View>(home, x0, IntSet(r), b);
00116   }
00117 
00118   template <class View>
00119   ExecStatus
00120   ReIntSet<View>::propagate(Space* home, ModEventDelta) {
00121     IntSetRanges i_is(is);
00122     if (b.one()) {
00123       GECODE_ME_CHECK(x0.inter_r(home,i_is,false)); goto subsumed;
00124     }
00125     if (b.zero()) {
00126       GECODE_ME_CHECK(x0.minus_r(home,i_is,false)); goto subsumed;
00127     }
00128 
00129     {
00130       ViewRanges<View> i_x(x0);
00131 
00132       switch (Iter::Ranges::subsumes(i_is,i_x)) {
00133       case Iter::Ranges::SS_SUBSUMED:
00134         GECODE_ME_CHECK(b.one_none(home)); goto subsumed;
00135       case Iter::Ranges::SS_EMPTY:
00136         GECODE_ME_CHECK(b.zero_none(home)); goto subsumed;
00137       case Iter::Ranges::SS_NONE:
00138         break;
00139       default: GECODE_NEVER;
00140       }
00141     }
00142 
00143     return ES_FIX;
00144   subsumed:
00145     return ES_SUBSUMED(this,home);
00146   }
00147 
00148 }}}
00149 
00150 // STATISTICS: int-prop
00151