Generated on Thu Apr 11 13:59:07 2019 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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode { namespace Int { namespace Dom {
00035 
00036   template<class View, ReifyMode rm>
00037   forceinline
00038   ReIntSet<View,rm>::ReIntSet
00039   (Home home, View x, const IntSet& s, BoolView b)
00040     : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,x,b), is(s) {
00041     home.notice(*this,AP_DISPOSE);
00042   }
00043 
00044   template<class View, ReifyMode rm>
00045   forceinline size_t
00046   ReIntSet<View,rm>::dispose(Space& home) {
00047     home.ignore(*this,AP_DISPOSE);
00048     is.~IntSet();
00049     (void) ReUnaryPropagator<View,PC_INT_DOM,BoolView>::dispose(home);
00050     return sizeof(*this);
00051   }
00052 
00053   template<class View, ReifyMode rm>
00054   ExecStatus
00055   ReIntSet<View,rm>::post(Home home, View x, const IntSet& s, BoolView b) {
00056     if (s.ranges() == 0) {
00057       if (rm == RM_PMI)
00058         return ES_OK;
00059       GECODE_ME_CHECK(b.zero(home));
00060     } else if (s.ranges() == 1) {
00061       return ReRange<View,rm>::post(home,x,s.min(),s.max(),b);
00062     } else if (b.one()) {
00063       if (rm == RM_PMI)
00064         return ES_OK;
00065       IntSetRanges i_is(s);
00066       GECODE_ME_CHECK(x.inter_r(home,i_is,false));
00067     } else if (b.zero()) {
00068       if (rm == RM_IMP)
00069         return ES_OK;
00070       IntSetRanges i_is(s);
00071       GECODE_ME_CHECK(x.minus_r(home,i_is,false));
00072     } else {
00073       (void) new (home) ReIntSet<View,rm>(home,x,s,b);
00074     }
00075     return ES_OK;
00076   }
00077 
00078 
00079   template<class View, ReifyMode rm>
00080   forceinline
00081   ReIntSet<View,rm>::ReIntSet(Space& home, ReIntSet& p)
00082     : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,p), is(p.is) {
00083   }
00084 
00085   template<class View, ReifyMode rm>
00086   Actor*
00087   ReIntSet<View,rm>::copy(Space& home) {
00088     return new (home) ReIntSet(home,*this);
00089   }
00090 
00091   template<class View, ReifyMode rm>
00092   ExecStatus
00093   ReIntSet<View,rm>::propagate(Space& home, const ModEventDelta&) {
00094     IntSetRanges i_is(is);
00095     if (b.one()) {
00096       if (rm != RM_PMI)
00097         GECODE_ME_CHECK(x0.inter_r(home,i_is,false));
00098       return home.ES_SUBSUMED(*this);
00099     }
00100     if (b.zero()) {
00101       if (rm != RM_IMP)
00102         GECODE_ME_CHECK(x0.minus_r(home,i_is,false));
00103       return home.ES_SUBSUMED(*this);
00104     }
00105 
00106     {
00107       ViewRanges<View> i_x(x0);
00108 
00109       switch (Iter::Ranges::compare(i_x,i_is)) {
00110       case Iter::Ranges::CS_SUBSET:
00111         if (rm != RM_IMP)
00112           GECODE_ME_CHECK(b.one_none(home));
00113         return home.ES_SUBSUMED(*this);
00114       case Iter::Ranges::CS_DISJOINT:
00115         if (rm != RM_PMI)
00116           GECODE_ME_CHECK(b.zero_none(home));
00117         return home.ES_SUBSUMED(*this);
00118       case Iter::Ranges::CS_NONE:
00119         break;
00120       default: GECODE_NEVER;
00121       }
00122     }
00123     return ES_FIX;
00124   }
00125 
00126 }}}
00127 
00128 // STATISTICS: int-prop
00129