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

int-gq.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   GqInt<VY>::GqInt(Home home, ValSet& vs, ViewArray<IntView>& x, VY y)
00042     : IntBase<VY>(home,vs,x,y) {}
00043 
00044   template<class VY>
00045   inline ExecStatus
00046   GqInt<VY>::post(Home home, ViewArray<IntView>& x, VY y) {
00047     if (x.size() == 0) {
00048       GECODE_ME_CHECK(y.lq(home,0));
00049       return ES_OK;
00050     }
00051 
00052     x.unique();
00053 
00054     if (x.size() == 1) {
00055       GECODE_ME_CHECK(y.lq(home,1));
00056       return ES_OK;
00057     }
00058 
00059     GECODE_ME_CHECK(y.lq(home,x.size()));
00060 
00061     if (y.max() <= 1)
00062       return ES_OK;
00063 
00064     if (y.min() == x.size()) {
00065       assert(y.assigned());
00066       return Distinct::Dom<IntView>::post(home,x);
00067     }
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.lq(home,n + vs.size()));
00079 
00080     if (n == 0) {
00081       assert(vs.size() >= y.max());
00082       return ES_OK;
00083     }
00084 
00085     x.size(n);
00086 
00087     (void) new (home) GqInt<VY>(home, vs, x, y);
00088     return ES_OK;
00089   }
00090 
00091   template<class VY>
00092   forceinline
00093   GqInt<VY>::GqInt(Space& home, GqInt<VY>& p)
00094     : IntBase<VY>(home, p) {}
00095 
00096   template<class VY>
00097   Propagator*
00098   GqInt<VY>::copy(Space& home) {
00099     return new (home) GqInt<VY>(home, *this);
00100   }
00101 
00102   template<class VY>
00103   ExecStatus
00104   GqInt<VY>::propagate(Space& home, const ModEventDelta& med) {
00105     if (IntView::me(med) == ME_INT_VAL)
00106       add(home);
00107 
00108     // Eliminate subsumed views
00109     eliminate(home);
00110 
00111     GECODE_ME_CHECK(y.lq(home, x.size() + vs.size()));
00112 
00113     if (x.size() == 0)
00114       return home.ES_SUBSUMED(*this);
00115 
00116     if (vs.size() >= y.max())
00117       return home.ES_SUBSUMED(*this);
00118 
00119     GECODE_ES_CHECK(prune_upper(home,g));
00120 
00121     return ES_NOFIX;
00122   }
00123 
00124 }}}
00125 
00126 // STATISTICS: int-prop