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

nosubset.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  *     Gabor Szokoli <szokoli@gecode.org>
00007  *
00008  *  Copyright:
00009  *     Guido Tack, 2004
00010  *     Christian Schulte, 2004
00011  *     Gabor Szokoli, 2004
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   /*
00041    * "No Subset" propagator
00042    *
00043    */
00044 
00045   template<class View0, class View1>
00046   forceinline
00047   NoSubset<View0,View1>::NoSubset(Home home, View0 y0, View1 y1)
00048     : MixBinaryPropagator<View0,PC_SET_CLUB,
00049                             View1,PC_SET_CGLB>(home,y0,y1) {}
00050 
00051   template<class View0, class View1>
00052   forceinline
00053   NoSubset<View0,View1>::NoSubset(Space& home, NoSubset<View0,View1>& p)
00054     : MixBinaryPropagator<View0,PC_SET_CLUB,
00055                             View1,PC_SET_CGLB>(home,p) {}
00056 
00057   template<class View0, class View1>
00058   ExecStatus
00059   NoSubset<View0,View1>::post(Home home, View0 x, View1 y) {
00060     if (same(x,y))
00061       return ES_FAILED;
00062     if (me_failed(x.cardMin(home,1)))
00063       return ES_FAILED;
00064     (void) new (home) NoSubset<View0,View1>(home,x,y);
00065     return ES_OK;
00066   }
00067 
00068   template<class View0, class View1>
00069   Actor*
00070   NoSubset<View0,View1>::copy(Space& home) {
00071     return new (home) NoSubset<View0,View1>(home,*this);
00072   }
00073 
00074   template<class View0, class View1>
00075   ExecStatus
00076   NoSubset<View0,View1>::propagate(Space& home, const ModEventDelta&) {
00077     GlbRanges<View0> x0lb(x0);
00078     LubRanges<View1> x1ub(x1);
00079     if (!Iter::Ranges::subset(x0lb, x1ub))
00080       return home.ES_SUBSUMED(*this);
00081     if (x0.cardMin()>x1.cardMax()) { return home.ES_SUBSUMED(*this); }
00082     LubRanges<View0> x0ub(x0);
00083     GlbRanges<View1> x1lb(x1);
00084     Iter::Ranges::Diff<LubRanges<View0>,GlbRanges<View1> >
00085       breakers(x0ub,x1lb);
00086     if (!breakers()) { return ES_FAILED; }
00087     if (breakers.min() == breakers.max()) {
00088       int b1 = breakers.min();
00089       ++breakers;
00090       if (breakers()) { return ES_FIX; }
00091       //Only one subsetness-breaker element left:
00092       GECODE_ME_CHECK( x0.include(home,b1) );
00093       GECODE_ME_CHECK( x1.exclude(home,b1) );
00094       return home.ES_SUBSUMED(*this);
00095     }
00096     return ES_FIX;
00097   }
00098 
00099 }}}
00100 
00101 // STATISTICS: set-prop