Generated on Mon Aug 25 11:35:38 2008 for Gecode by doxygen 1.5.6

nq.icc

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  *  Last modified:
00016  *     $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $
00017  *     $Revision: 6017 $
00018  *
00019  *  This file is part of Gecode, the generic constraint
00020  *  development environment:
00021  *     http://www.gecode.org
00022  *
00023  *  Permission is hereby granted, free of charge, to any person obtaining
00024  *  a copy of this software and associated documentation files (the
00025  *  "Software"), to deal in the Software without restriction, including
00026  *  without limitation the rights to use, copy, modify, merge, publish,
00027  *  distribute, sublicense, and/or sell copies of the Software, and to
00028  *  permit persons to whom the Software is furnished to do so, subject to
00029  *  the following conditions:
00030  *
00031  *  The above copyright notice and this permission notice shall be
00032  *  included in all copies or substantial portions of the Software.
00033  *
00034  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00035  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00036  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00037  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00038  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00039  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00040  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00041  *
00042  */
00043 
00044 namespace Gecode { namespace Set { namespace Rel {
00045 
00046   template <class View0, class View1>
00047   forceinline
00048   Distinct<View0,View1>::Distinct(Space* home, View0 x, View1 y)
00049     : MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>(home,x,y) {}
00050 
00051   template <class View0, class View1>
00052   forceinline
00053   Distinct<View0,View1>::Distinct(Space* home, bool share, Distinct& p)
00054     : MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>
00055         (home,share,p) {}
00056 
00057   template <class View0, class View1>
00058   ExecStatus
00059   Distinct<View0,View1>::post(Space* home, View0 x, View1 y) {
00060     if (x.assigned()) {
00061       GlbRanges<View0> xr(x);
00062       IntSet xs(xr);
00063       ConstantView cv(home, xs);
00064       GECODE_ES_CHECK((DistinctDoit<View1>::post(home,y,cv)));
00065     }
00066     if (y.assigned()) {
00067       GlbRanges<View1> yr(y);
00068       IntSet ys(yr);
00069       ConstantView cv(home, ys);
00070       GECODE_ES_CHECK((DistinctDoit<View0>::post(home,x,cv)));
00071     }
00072     (void) new (home) Distinct<View0,View1>(home,x,y);
00073     return ES_OK;
00074   }
00075 
00076   template <class View0, class View1>
00077   Actor*
00078   Distinct<View0,View1>::copy(Space* home, bool share) {
00079     return new (home) Distinct<View0,View1>(home,share,*this);
00080   }
00081 
00082   template <class View0, class View1>
00083   Support::Symbol
00084   Distinct<View0,View1>::ati(void) {
00085     return Reflection::mangle<View0,View1>("Gecode::Set::Rel::Distinct");
00086   }
00087 
00088   template <class View0, class View1>
00089   Reflection::ActorSpec
00090   Distinct<View0,View1>::spec(const Space* home,
00091                               Reflection::VarMap& m) const {
00092     return MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>
00093       ::spec(home, m, ati());
00094   }
00095 
00096   template <class View0, class View1>
00097   void
00098   Distinct<View0,View1>::post(Space* home, Reflection::VarMap& vars,
00099                               const Reflection::ActorSpec& spec) {
00100     spec.checkArity(2);
00101     View0 x0(home, vars, spec[0]);
00102     View1 x1(home, vars, spec[1]);
00103     (void) new (home) Distinct(home,x0,x1);
00104   }
00105 
00106   template <class View0, class View1>
00107   ExecStatus
00108   Distinct<View0,View1>::propagate(Space* home, ModEventDelta) {
00109     assert(x0.assigned()||x1.assigned());
00110     if (x0.assigned()) {
00111       GlbRanges<View0> xr(x0);
00112       IntSet xs(xr);
00113       ConstantView cv(home, xs);
00114       GECODE_REWRITE(this,(DistinctDoit<View1>::post(home,x1,cv)));
00115     } else {
00116       GlbRanges<View1> yr(x1);
00117       IntSet ys(yr);
00118       ConstantView cv(home, ys);
00119       GECODE_REWRITE(this,(DistinctDoit<View0>::post(home,x0,cv)));
00120     }
00121   }
00122 
00123   template <class View0>
00124   ExecStatus
00125   DistinctDoit<View0>::post(Space* home, View0 x, ConstantView y) {
00126     (void) new (home) DistinctDoit<View0>(home,x,y);
00127     return ES_OK;
00128   }
00129 
00130   template <class View0>
00131   Actor*
00132   DistinctDoit<View0>::copy(Space* home, bool share) {
00133     return new (home) DistinctDoit<View0>(home,share,*this);
00134   }
00135 
00136   template <class View0>
00137   Support::Symbol
00138   DistinctDoit<View0>::ati(void) {
00139     return Reflection::mangle<View0>("Gecode::Set::Rel::DistinctDoit");
00140   }
00141 
00142   template <class View0>
00143   Reflection::ActorSpec
00144   DistinctDoit<View0>::spec(const Space* home, Reflection::VarMap& m) const {
00145     Reflection::ActorSpec s =
00146       UnaryPropagator<View0,PC_SET_ANY>::spec(home, m, ati());
00147     return s << y.spec(home, m);
00148   }
00149 
00150   template <class View0>
00151   void
00152   DistinctDoit<View0>::post(Space* home, Reflection::VarMap& vars,
00153                             const Reflection::ActorSpec& spec) {
00154     spec.checkArity(2);
00155     View0 x0(home, vars, spec[0]);
00156     ConstantView x1(home, vars, spec[1]);
00157     (void) new (home) DistinctDoit(home,x0,x1);
00158   }
00159 
00160   template <class View0>
00161   ExecStatus
00162   DistinctDoit<View0>::propagate(Space* home, ModEventDelta) {
00163     if (x0.assigned()) {
00164       GlbRanges<View0> xi(x0);
00165       GlbRanges<ConstantView> yi(y);
00166       if (Iter::Ranges::equal(xi,yi)) { return ES_FAILED; }
00167       else { return ES_SUBSUMED(this,home); }
00168     }
00169     assert(x0.lubSize()-x0.glbSize() >0);
00170     if (x0.cardMin()>y.cardMax()) { return ES_SUBSUMED(this,home); }
00171     if (x0.cardMax()<y.cardMin()) { return ES_SUBSUMED(this,home); }
00172     //These tests are too expensive, we should only do them
00173     //in the 1 unknown left case.
00174     GlbRanges<View0> xi1(x0);
00175     LubRanges<ConstantView> yi1(y);
00176     if (!Iter::Ranges::subset(xi1,yi1)){ return ES_SUBSUMED(this,home); }
00177     LubRanges<View0> xi2(x0);
00178     GlbRanges<ConstantView> yi2(y);
00179     if (!Iter::Ranges::subset(yi2,xi2)){ return ES_SUBSUMED(this,home); }
00180     // from here, we know y\subseteq lub(x) and glb(x)\subseteq y
00181 
00182     if (x0.lubSize() == y.cardMin() && x0.lubSize() > 0) {
00183       GECODE_ME_CHECK(x0.cardMax(home, x0.lubSize() - 1));
00184       return ES_SUBSUMED(this,home);
00185     }
00186     if (x0.glbSize() == y.cardMin()) {
00187       GECODE_ME_CHECK(x0.cardMin(home, x0.glbSize() + 1));
00188       return ES_SUBSUMED(this,home);
00189     }
00190     return ES_FIX;
00191   }
00192 
00193   template <class View0>
00194   forceinline
00195   DistinctDoit<View0>::DistinctDoit(Space* home, View0 _x, ConstantView _y)
00196     : UnaryPropagator<View0, PC_SET_ANY>(home,_x), y(_y)  {}
00197 
00198   template <class View0>
00199   forceinline
00200   DistinctDoit<View0>::DistinctDoit(Space* home, bool share,
00201                                     DistinctDoit<View0>& p)
00202     : UnaryPropagator<View0, PC_SET_ANY>(home,share,p) {
00203     y.update(home,share,p.y);
00204   }
00205 
00206 }}}
00207 
00208 // STATISTICS: set-prop