Generated on Thu Mar 22 10:39:45 2012 for Gecode by doxygen 1.6.3

re-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  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2011
00008  *
00009  *  Last modified:
00010  *     $Date: 2011-08-24 16:34:16 +0200 (Wed, 24 Aug 2011) $ by $Author: tack $
00011  *     $Revision: 12346 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Set { namespace Rel {
00039 
00040   template<class View0, class View1, bool strict>
00041   forceinline
00042   ReLq<View0,View1,strict>::ReLq(Home home, View0 y0, View1 y1,
00043                           Gecode::Int::BoolView y2)
00044     : Propagator(home), x0(y0), x1(y1), b(y2) {
00045     b.subscribe(home,*this, Gecode::Int::PC_INT_VAL);
00046     x0.subscribe(home,*this, PC_SET_ANY);
00047     x1.subscribe(home,*this, PC_SET_ANY);
00048   }
00049 
00050   template<class View0, class View1, bool strict>
00051   forceinline
00052   ReLq<View0,View1,strict>::ReLq(Space& home, bool share, ReLq& p)
00053     : Propagator(home,share,p) {
00054     x0.update(home,share,p.x0);
00055     x1.update(home,share,p.x1);
00056     b.update(home,share,p.b);
00057   }
00058 
00059   template<class View0, class View1, bool strict>
00060   PropCost
00061   ReLq<View0,View1,strict>::cost(const Space&, const ModEventDelta&) const {
00062     return PropCost::ternary(PropCost::LO);
00063   }
00064 
00065   template<class View0, class View1, bool strict>
00066   forceinline size_t
00067   ReLq<View0,View1,strict>::dispose(Space& home) {
00068     b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
00069     x0.cancel(home,*this, PC_SET_ANY);
00070     x1.cancel(home,*this, PC_SET_ANY);
00071     (void) Propagator::dispose(home);
00072     return sizeof(*this);
00073   }
00074 
00075   template<class View0, class View1, bool strict>
00076   ExecStatus
00077   ReLq<View0,View1,strict>::post(Home home, View0 x0, View1 x1,
00078                             Gecode::Int::BoolView b) {
00079     (void) new (home) ReLq<View0,View1,strict>(home,x0,x1,b);
00080     return ES_OK;
00081   }
00082 
00083   template<class View0, class View1, bool strict>
00084   Actor*
00085   ReLq<View0,View1,strict>::copy(Space& home, bool share) {
00086     return new (home) ReLq<View0,View1,strict>(home,share,*this);
00087   }
00088 
00089   template<class View0, class View1, bool strict>
00090   ExecStatus
00091   ReLq<View0,View1,strict>::propagate(Space& home, const ModEventDelta&) {
00092     if (b.one())
00093       GECODE_REWRITE(*this,(Lq<View0,View1,strict>::post(home(*this),x0,x1)));
00094     if (b.zero())
00095       GECODE_REWRITE(*this,(Lq<View1,View0,!strict>::post(home(*this),x1,x0)));
00096 
00097     if (x0.cardMax() == 0) {
00098       if ( (!strict) || x1.cardMin() > 0) {
00099         GECODE_ME_CHECK(b.one_none(home));
00100         return home.ES_SUBSUMED(*this);
00101       }
00102       if (strict && x1.cardMax() == 0) {
00103         GECODE_ME_CHECK(b.zero_none(home));
00104         return home.ES_SUBSUMED(*this);
00105       }
00106     }
00107 
00108     if (x0.assigned() && x1.assigned()) {
00109       // directly test x0<=x1
00110       int min01;
00111       {
00112         GlbRanges<View0> x0l(x0);
00113         GlbRanges<View1> x1l(x1);
00114         Iter::Ranges::Diff<GlbRanges<View1>,GlbRanges<View0> > d(x1l,x0l);
00115         if (!d()) {
00116           if ((!strict) && x0.cardMax() == x1.cardMax()) {
00117             // equal
00118             GECODE_ME_CHECK(b.one_none(home));
00119           } else {
00120             // subset
00121             GECODE_ME_CHECK(b.zero_none(home));
00122           }
00123           return home.ES_SUBSUMED(*this);
00124         }
00125         min01 = d.min();
00126       }
00127       int min10;
00128       {
00129         GlbRanges<View0> x0l(x0);
00130         GlbRanges<View1> x1l(x1);
00131         Iter::Ranges::Diff<GlbRanges<View0>,GlbRanges<View1> > d(x0l,x1l);
00132         if (!d()) {
00133           if (strict && x0.cardMax() == x1.cardMax()) {
00134             // equal
00135             GECODE_ME_CHECK(b.zero_none(home));
00136           } else {
00137             // subset
00138             GECODE_ME_CHECK(b.one_none(home));
00139           }
00140           return home.ES_SUBSUMED(*this);
00141         }
00142         min10 = d.min();
00143       }
00144 
00145       assert(min01 != min10);
00146       if (min01<min10) {
00147         GECODE_ME_CHECK(b.one_none(home));
00148       } else {
00149         GECODE_ME_CHECK(b.zero_none(home));
00150       }
00151       return home.ES_SUBSUMED(*this);
00152     }
00153 
00154     // min(x0lb - x1ub) < min(x1ub) -> b=0
00155     if (x1.cardMax() > 0) {
00156       GlbRanges<View0> x0l(x0);
00157       LubRanges<View1> x1u(x1);
00158       int x1umin=x1u.min();
00159       Iter::Ranges::Diff<GlbRanges<View0>,LubRanges<View1> > d(x0l,x1u);
00160       if (d() && d.min() < x1umin) {
00161         GECODE_ME_CHECK(b.zero_none(home));
00162         return home.ES_SUBSUMED(*this);
00163       }
00164     }
00165     // min(x1lb - x0ub) < min(x0ub) -> b=1
00166     if (x0.cardMax() > 0) {
00167       LubRanges<View0> x0u(x0);
00168       GlbRanges<View1> x1l(x1);
00169       int x0umin=x0u.min();
00170       Iter::Ranges::Diff<GlbRanges<View1>,LubRanges<View0> > d(x1l,x0u);
00171       if (d() && d.min() < x0umin) {
00172         GECODE_ME_CHECK(b.one_none(home));
00173         return home.ES_SUBSUMED(*this);
00174       }
00175     }
00176 
00177     return ES_FIX;
00178   }
00179 
00180 }}}
00181 
00182 // STATISTICS: set-prop