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

nq.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *     Christian Schulte <schulte@gecode.org>
00006  *
00007  *  Contributing authors:
00008  *     Gabor Szokoli <szokoli@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Guido Tack, 2004
00012  *     Christian Schulte, 2004
00013  *     Gabor Szokoli, 2004
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 namespace Gecode { namespace Set { namespace Rel {
00041 
00042   template<class View0, class View1>
00043   forceinline
00044   Distinct<View0,View1>::Distinct(Home home, View0 x, View1 y)
00045     : MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>(home,x,y) {}
00046 
00047   template<class View0, class View1>
00048   forceinline
00049   Distinct<View0,View1>::Distinct(Space& home, Distinct& p)
00050     : MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>
00051         (home,p) {}
00052 
00053   template<class View0, class View1>
00054   ExecStatus
00055   Distinct<View0,View1>::post(Home home, View0 x, View1 y) {
00056     if (same(x,y))
00057       return ES_FAILED;
00058     if (x.assigned()) {
00059       GlbRanges<View0> xr(x);
00060       IntSet xs(xr);
00061       ConstSetView cv(home, xs);
00062       GECODE_ES_CHECK((DistinctDoit<View1>::post(home,y,cv)));
00063     }
00064     if (y.assigned()) {
00065       GlbRanges<View1> yr(y);
00066       IntSet ys(yr);
00067       ConstSetView cv(home, ys);
00068       GECODE_ES_CHECK((DistinctDoit<View0>::post(home,x,cv)));
00069     }
00070     (void) new (home) Distinct<View0,View1>(home,x,y);
00071     return ES_OK;
00072   }
00073 
00074   template<class View0, class View1>
00075   Actor*
00076   Distinct<View0,View1>::copy(Space& home) {
00077     return new (home) Distinct<View0,View1>(home,*this);
00078   }
00079 
00080   template<class View0, class View1>
00081   ExecStatus
00082   Distinct<View0,View1>::propagate(Space& home, const ModEventDelta&) {
00083     assert(x0.assigned()||x1.assigned());
00084     if (x0.assigned()) {
00085       GlbRanges<View0> xr(x0);
00086       IntSet xs(xr);
00087       ConstSetView cv(home, xs);
00088       GECODE_REWRITE(*this,(DistinctDoit<View1>::post(home(*this),x1,cv)));
00089     } else {
00090       GlbRanges<View1> yr(x1);
00091       IntSet ys(yr);
00092       ConstSetView cv(home, ys);
00093       GECODE_REWRITE(*this,(DistinctDoit<View0>::post(home(*this),x0,cv)));
00094     }
00095   }
00096 
00097   template<class View0>
00098   ExecStatus
00099   DistinctDoit<View0>::post(Home home, View0 x, ConstSetView y) {
00100     (void) new (home) DistinctDoit<View0>(home,x,y);
00101     return ES_OK;
00102   }
00103 
00104   template<class View0>
00105   Actor*
00106   DistinctDoit<View0>::copy(Space& home) {
00107     return new (home) DistinctDoit<View0>(home,*this);
00108   }
00109 
00110   template<class View0>
00111   ExecStatus
00112   DistinctDoit<View0>::propagate(Space& home, const ModEventDelta&) {
00113     if (x0.assigned()) {
00114       GlbRanges<View0> xi(x0);
00115       GlbRanges<ConstSetView> yi(y);
00116       if (Iter::Ranges::equal(xi,yi)) { return ES_FAILED; }
00117       else { return home.ES_SUBSUMED(*this); }
00118     }
00119     assert(x0.lubSize()-x0.glbSize() >0);
00120     if (x0.cardMin()>y.cardMax()) { return home.ES_SUBSUMED(*this); }
00121     if (x0.cardMax()<y.cardMin()) { return home.ES_SUBSUMED(*this); }
00122     //These tests are too expensive, we should only do them
00123     //in the 1 unknown left case.
00124     GlbRanges<View0> xi1(x0);
00125     LubRanges<ConstSetView> yi1(y);
00126     if (!Iter::Ranges::subset(xi1,yi1)) { return home.ES_SUBSUMED(*this); }
00127     LubRanges<View0> xi2(x0);
00128     GlbRanges<ConstSetView> yi2(y);
00129     if (!Iter::Ranges::subset(yi2,xi2)) { return home.ES_SUBSUMED(*this); }
00130     // from here, we know y\subseteq lub(x) and glb(x)\subseteq y
00131 
00132     if (x0.lubSize() == y.cardMin() && x0.lubSize() > 0) {
00133       GECODE_ME_CHECK(x0.cardMax(home, x0.lubSize() - 1));
00134       return home.ES_SUBSUMED(*this);
00135     }
00136     if (x0.glbSize() == y.cardMin()) {
00137       GECODE_ME_CHECK(x0.cardMin(home, x0.glbSize() + 1));
00138       return home.ES_SUBSUMED(*this);
00139     }
00140     return ES_FIX;
00141   }
00142 
00143   template<class View0>
00144   forceinline
00145   DistinctDoit<View0>::DistinctDoit(Home home, View0 _x, ConstSetView _y)
00146     : UnaryPropagator<View0, PC_SET_ANY>(home,_x), y(_y)  {}
00147 
00148   template<class View0>
00149   forceinline
00150   DistinctDoit<View0>::DistinctDoit(Space& home, DistinctDoit<View0>& p)
00151     : UnaryPropagator<View0, PC_SET_ANY>(home,p) {
00152     y.update(home,p.y);
00153   }
00154 
00155 }}}
00156 
00157 // STATISTICS: set-prop