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

int-lq.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, 2011
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 #include <gecode/int/distinct.hh>
00036 
00037 namespace Gecode { namespace Int { namespace NValues {
00038 
00039   template<class VY>
00040   forceinline
00041   LqInt<VY>::LqInt(Home home, ValSet& vs, ViewArray<IntView>& x, VY y)
00042     : IntBase<VY>(home,vs,x,y) {
00043     home.notice(*this, AP_WEAKLY);
00044   }
00045 
00046   template<class VY>
00047   inline ExecStatus
00048   LqInt<VY>::post(Home home, ViewArray<IntView>& x, VY y) {
00049     if (x.size() == 0) {
00050       GECODE_ME_CHECK(y.eq(home,0));
00051       return ES_OK;
00052     }
00053 
00054     x.unique();
00055 
00056     GECODE_ME_CHECK(y.gq(home,1));
00057 
00058     if (x.size() == 1)
00059       return ES_OK;
00060 
00061     if (y.max() == 1) {
00062       assert(y.assigned());
00063       return Rel::NaryEqDom<IntView>::post(home,x);
00064     }
00065 
00066     if (y.min() >= x.size())
00067       return ES_OK;
00068 
00069     // Eliminate assigned views and store them into the value set
00070     ValSet vs;
00071     int n = x.size();
00072     for (int i=n; i--; )
00073       if (x[i].assigned()) {
00074         vs.add(home, x[i].val());
00075         x[i] = x[--n];
00076       }
00077 
00078     GECODE_ME_CHECK(y.gq(home,vs.size()));
00079 
00080     if (n == 0) {
00081       assert(y.min() >= vs.size());
00082       return ES_OK;
00083     }
00084 
00085     x.size(n);
00086 
00087     (void) new (home) LqInt<VY>(home, vs, x, y);
00088     return ES_OK;
00089   }
00090 
00091   template<class VY>
00092   forceinline
00093   LqInt<VY>::LqInt(Space& home, LqInt<VY>& p)
00094     : IntBase<VY>(home, p) {}
00095 
00096   template<class VY>
00097   Propagator*
00098   LqInt<VY>::copy(Space& home) {
00099     return new (home) LqInt<VY>(home, *this);
00100   }
00101 
00102   template<class VY>
00103   forceinline size_t
00104   LqInt<VY>::dispose(Space& home) {
00105     home.ignore(*this, AP_WEAKLY);
00106     (void) IntBase<VY>::dispose(home);
00107     return sizeof(*this);
00108   }
00109 
00110   template<class VY>
00111   ExecStatus
00112   LqInt<VY>::propagate(Space& home, const ModEventDelta& med) {
00113     // Add assigned views to value set
00114     if (IntView::me(med) == ME_INT_VAL)
00115       add(home);
00116 
00117     GECODE_ME_CHECK(y.gq(home, vs.size()));
00118 
00119     if (x.size() == 0)
00120       return home.ES_SUBSUMED(*this);
00121 
00122     // All values must be in the value set
00123     if (y.max() == vs.size())
00124       return all_in_valset(home);
00125 
00126     if (x.size() + vs.size() <= y.min())
00127       return home.ES_SUBSUMED(*this);
00128 
00129     // Compute positions of disjoint views
00130     Region r;
00131     int* dis; int n_dis;
00132     disjoint(home,r,dis,n_dis);
00133 
00134     // Some views might have been eliminated as they are subsumed
00135     if (x.size() == 0)
00136       return home.ES_SUBSUMED(*this);
00137 
00138     // No lower bound pruning possible
00139     if (n_dis == 0)
00140       return ES_NOFIX;
00141 
00142     // Do lower bound-based pruning
00143     GECODE_ES_CHECK(prune_lower(home,dis,n_dis));
00144 
00145     return ES_NOFIX;
00146   }
00147 
00148 }}}
00149 
00150 // STATISTICS: int-prop