Generated on Tue Apr 18 10:21:53 2017 for Gecode by doxygen 1.6.3

set.hpp

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: 2011-11-18 16:02:48 +0100 (Fri, 18 Nov 2011) $ by $Author: schulte $
00011  *     $Revision: 12472 $
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, ReifyMode rm>
00041   forceinline
00042   ReIntSet<View,rm>::ReIntSet
00043   (Home home, View x, const IntSet& s, BoolView b)
00044     : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,x,b), is(s) {
00045     home.notice(*this,AP_DISPOSE);
00046   }
00047 
00048   template<class View, ReifyMode rm>
00049   forceinline size_t
00050   ReIntSet<View,rm>::dispose(Space& home) {
00051     home.ignore(*this,AP_DISPOSE);
00052     is.~IntSet();
00053     (void) ReUnaryPropagator<View,PC_INT_DOM,BoolView>::dispose(home);
00054     return sizeof(*this);
00055   }
00056 
00057   template<class View, ReifyMode rm>
00058   ExecStatus
00059   ReIntSet<View,rm>::post(Home home, View x, const IntSet& s, BoolView b) {
00060     if (s.ranges() == 0) {
00061       if (rm == RM_PMI)
00062         return ES_OK;
00063       GECODE_ME_CHECK(b.zero(home));
00064     } else if (s.ranges() == 1) {
00065       return ReRange<View,rm>::post(home,x,s.min(),s.max(),b);
00066     } else if (b.one()) {
00067       if (rm == RM_PMI)
00068         return ES_OK;
00069       IntSetRanges i_is(s);
00070       GECODE_ME_CHECK(x.inter_r(home,i_is,false));
00071     } else if (b.zero()) {
00072       if (rm == RM_IMP)
00073         return ES_OK;
00074       IntSetRanges i_is(s);
00075       GECODE_ME_CHECK(x.minus_r(home,i_is,false));
00076     } else {
00077       (void) new (home) ReIntSet<View,rm>(home,x,s,b);
00078     }
00079     return ES_OK;
00080   }
00081 
00082 
00083   template<class View, ReifyMode rm>
00084   forceinline
00085   ReIntSet<View,rm>::ReIntSet(Space& home, bool share, ReIntSet& p)
00086     : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,share,p) {
00087     is.update(home,share,p.is);
00088   }
00089 
00090   template<class View, ReifyMode rm>
00091   Actor*
00092   ReIntSet<View,rm>::copy(Space& home, bool share) {
00093     return new (home) ReIntSet(home,share,*this);
00094   }
00095 
00096   template<class View, ReifyMode rm>
00097   ExecStatus
00098   ReIntSet<View,rm>::propagate(Space& home, const ModEventDelta&) {
00099     IntSetRanges i_is(is);
00100     if (b.one()) {
00101       if (rm != RM_PMI)
00102         GECODE_ME_CHECK(x0.inter_r(home,i_is,false));
00103       return home.ES_SUBSUMED(*this);
00104     }
00105     if (b.zero()) {
00106       if (rm != RM_IMP)
00107         GECODE_ME_CHECK(x0.minus_r(home,i_is,false));
00108       return home.ES_SUBSUMED(*this);
00109     }
00110 
00111     {
00112       ViewRanges<View> i_x(x0);
00113 
00114       switch (Iter::Ranges::compare(i_x,i_is)) {
00115       case Iter::Ranges::CS_SUBSET:
00116         if (rm != RM_IMP)
00117           GECODE_ME_CHECK(b.one_none(home));
00118         return home.ES_SUBSUMED(*this);
00119       case Iter::Ranges::CS_DISJOINT:
00120         if (rm != RM_PMI)
00121           GECODE_ME_CHECK(b.zero_none(home));
00122         return home.ES_SUBSUMED(*this);
00123       case Iter::Ranges::CS_NONE:
00124         break;
00125       default: GECODE_NEVER;
00126       }
00127     }
00128     return ES_FIX;
00129   }
00130 
00131 }}}
00132 
00133 // STATISTICS: int-prop
00134