Generated on Thu Apr 11 13:59:12 2019 for Gecode by doxygen 1.6.3

set-op.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, 2009
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 Sequence {
00035 
00037   enum TakesStatus {
00038     TS_NO,   
00039     TS_YES,  
00040     TS_MAYBE 
00041   };
00042 
00044   template<class View>
00045   forceinline TakesStatus
00046   takes(const View& x, int s) {
00047     if (x.in(s))
00048       return x.assigned() ? TS_YES : TS_MAYBE;
00049     else
00050       return TS_NO;
00051   }
00053   template<class View>
00054   forceinline TakesStatus
00055   takes(const View& x, const IntSet& s) {
00056     if ((x.max() < s.min()) || (x.min() > s.max()))
00057       return TS_NO;
00058     ViewRanges<View> ix(x);
00059     IntSetRanges is(s);
00060     switch (Iter::Ranges::compare(ix,is)) {
00061     case Iter::Ranges::CS_SUBSET: return TS_YES;
00062     case Iter::Ranges::CS_DISJOINT: return TS_NO;
00063     case Iter::Ranges::CS_NONE: return TS_MAYBE;
00064     default: GECODE_NEVER;
00065     }
00066     return TS_MAYBE;
00067   }
00068 
00070   template<class View>
00071   forceinline bool
00072   includes(const View& x, int s) {
00073     return x.assigned() && x.in(s);
00074   }
00076   template<class View>
00077   forceinline bool
00078   includes(const View& x, const IntSet& s) {
00079     if ((x.max() < s.min()) || (x.min() > s.max()))
00080       return false;
00081     ViewRanges<View> ix(x);
00082     IntSetRanges is(s);
00083     return Iter::Ranges::subset(ix,is);
00084   }
00085 
00087   template<class View>
00088   forceinline bool
00089   excludes(const View& x, int s) {
00090     return !x.in(s);
00091   }
00093   template<class View>
00094   forceinline bool
00095   excludes(const View& x, const IntSet& s) {
00096     if ((x.max() < s.min()) || (x.min() > s.max()))
00097       return true;
00098     ViewRanges<View> ix(x);
00099     IntSetRanges is(s);
00100     return Iter::Ranges::disjoint(ix,is);
00101   }
00102 
00104   template<class View>
00105   forceinline bool
00106   undecided(const View& x, int s) {
00107     return !x.assigned() && x.in(s);
00108   }
00110   template<class View>
00111   forceinline bool
00112   undecided(const View& x, const IntSet& s) {
00113     if ((x.max() < s.min()) || (x.min() > s.max()))
00114       return false;
00115     ViewRanges<View> ix(x);
00116     IntSetRanges is(s);
00117     return Iter::Ranges::compare(ix,is) == Iter::Ranges::CS_NONE;
00118   }
00119 
00121   template<class View>
00122   forceinline ModEvent
00123   include(Space& home, View& x, int s) {
00124     return x.eq(home,s);
00125   }
00127   template<class View>
00128   forceinline ModEvent
00129   include(Space& home, View& x, const IntSet& s) {
00130     IntSetRanges is(s);
00131     return x.inter_r(home,is,false);
00132   }
00133 
00135   template<class View>
00136   forceinline ModEvent
00137   exclude(Space& home, View& x, int s) {
00138     return x.nq(home,s);
00139   }
00141   template<class View>
00142   forceinline ModEvent
00143   exclude(Space& home, View& x, const IntSet& s) {
00144     IntSetRanges is(s);
00145     return x.minus_r(home,is,false);
00146   }
00147 
00148 }}}
00149 
00150 // STATISTICS: int-prop