Generated on Fri Oct 19 11:25:04 2018 for Gecode by doxygen 1.6.3

range.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 #include <gecode/int/rel.hh>
00035 
00036 namespace Gecode { namespace Int { namespace Dom {
00037 
00038   template<class View, ReifyMode rm>
00039   forceinline
00040   ReRange<View,rm>::ReRange(Home home, View x, int min0, int max0, BoolView b)
00041     : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,x,b),
00042       min(min0), max(max0) {}
00043 
00044   template<class View, ReifyMode rm>
00045   ExecStatus
00046   ReRange<View,rm>::post(Home home, View x, int min, int max, BoolView b) {
00047     if (min == max) {
00048       return Rel::ReEqDomInt<View,BoolView,rm>::post(home,x,min,b);
00049     } else if ((min > max) || (max < x.min()) || (min > x.max())) {
00050       if (rm == RM_PMI)
00051         return ES_OK;
00052       GECODE_ME_CHECK(b.zero(home));
00053     } else if ((min <= x.min()) && (x.max() <= max)) {
00054       if (rm == RM_IMP)
00055         return ES_OK;
00056       GECODE_ME_CHECK(b.one(home));
00057     } else if (b.one()) {
00058       if (rm == RM_PMI)
00059         return ES_OK;
00060       GECODE_ME_CHECK(x.gq(home,min));
00061       GECODE_ME_CHECK(x.lq(home,max));
00062     } else if (b.zero()) {
00063       if (rm == RM_IMP)
00064         return ES_OK;
00065       Iter::Ranges::Singleton r(min,max);
00066       GECODE_ME_CHECK(x.minus_r(home,r,false));
00067     } else {
00068       (void) new (home) ReRange<View,rm>(home,x,min,max,b);
00069     }
00070     return ES_OK;
00071   }
00072 
00073 
00074   template<class View, ReifyMode rm>
00075   forceinline
00076   ReRange<View,rm>::ReRange(Space& home, ReRange& p)
00077     : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,p),
00078       min(p.min), max(p.max) {}
00079 
00080   template<class View, ReifyMode rm>
00081   Actor*
00082   ReRange<View,rm>::copy(Space& home) {
00083     return new (home) ReRange<View,rm>(home,*this);
00084   }
00085 
00086   template<class View, ReifyMode rm>
00087   ExecStatus
00088   ReRange<View,rm>::propagate(Space& home, const ModEventDelta&) {
00089     if (b.one()) {
00090       if (rm != RM_PMI) {
00091         GECODE_ME_CHECK(x0.gq(home,min));
00092         GECODE_ME_CHECK(x0.lq(home,max));
00093       }
00094       return home.ES_SUBSUMED(*this);
00095     } else if (b.zero()) {
00096       if (rm != RM_IMP) {
00097         Iter::Ranges::Singleton r(min,max);
00098         GECODE_ME_CHECK(x0.minus_r(home,r,false));
00099       }
00100       return home.ES_SUBSUMED(*this);
00101     } else if ((x0.max() <= max) && (x0.min() >= min)) {
00102       if (rm != RM_IMP)
00103         GECODE_ME_CHECK(b.one_none(home));
00104       return home.ES_SUBSUMED(*this);
00105     } else if ((x0.max() < min) || (x0.min() > max)) {
00106       if (rm != RM_PMI)
00107         GECODE_ME_CHECK(b.zero_none(home));
00108       return home.ES_SUBSUMED(*this);
00109     } else if (!x0.range()) {
00110       ViewRanges<View> i_x(x0);
00111       Iter::Ranges::Singleton i_mm(min,max);
00112 
00113       switch (Iter::Ranges::compare(i_x,i_mm)) {
00114       case Iter::Ranges::CS_SUBSET:
00115         if (rm != RM_IMP)
00116           GECODE_ME_CHECK(b.one_none(home));
00117         return home.ES_SUBSUMED(*this);
00118       case Iter::Ranges::CS_DISJOINT:
00119         if (rm != RM_PMI)
00120           GECODE_ME_CHECK(b.zero_none(home));
00121         return home.ES_SUBSUMED(*this);
00122       case Iter::Ranges::CS_NONE:
00123         break;
00124       default: GECODE_NEVER;
00125       }
00126       return ES_FIX;
00127     }
00128     return ES_FIX;
00129   }
00130 
00131 }}}
00132 
00133 // STATISTICS: int-prop
00134