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

rel.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, 2003
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 
00036 namespace Gecode { namespace Int { namespace Count {
00037 
00038   /*
00039    * Counting domain consistent equality
00040    *
00041    */
00042 
00043   template<class VY>
00044   forceinline bool
00045   isintset(VY y) {
00046     (void) y;
00047     return false;
00048   }
00049   template<>
00050   forceinline bool
00051   isintset(IntSet y) {
00052     (void) y;
00053     return true;
00054   }
00055 
00056 
00057   template<class VY>
00058   forceinline bool
00059   isval(VY y) {
00060     return y.assigned();
00061   }
00062   template<>
00063   forceinline bool
00064   isval(IntSet y) {
00065     (void) y;
00066     return true;
00067   }
00068 
00069 
00070   forceinline void
00071   subscribe(Space& home, Propagator& p, IntSet& y) {
00072     (void) home; (void) p; (void) y;
00073   }
00074   template<class VY>
00075   forceinline void
00076   subscribe(Space& home, Propagator& p, VY y) {
00077     y.subscribe(home, p, PC_INT_DOM);
00078   }
00079 
00080   forceinline void
00081   cancel(Space& home, Propagator& p, IntSet& y) {
00082     (void) home; (void) p;
00083     y.~IntSet();
00084   }
00085   template<class VY>
00086   forceinline void
00087   cancel(Space& home, Propagator& p, VY y) {
00088     y.cancel(home, p, PC_INT_DOM);
00089   }
00090 
00091   forceinline void
00092   reschedule(Space& home, Propagator& p, IntSet& y) {
00093     (void) home; (void) p; (void) y;
00094   }
00095   template<class VY>
00096   forceinline void
00097   reschedule(Space& home, Propagator& p, VY y) {
00098     (void) y; // To satisy MSVC
00099     y.schedule(home, p, PC_INT_DOM);
00100   }
00101 
00102   forceinline void
00103   update(IntSet& y, Space& home, IntSet& py) {
00104     (void) home;
00105     y=py;
00106   }
00107   template<class VY>
00108   forceinline void
00109   update(VY& y, Space& home, VY py) {
00110     y.update(home, py);
00111   }
00112 
00113   template<class VX>
00114   forceinline RelTest
00115   holds(VX x, ConstIntView y) {
00116     return rtest_eq_dom(x,y.val());
00117   }
00118   template<class VX>
00119   forceinline RelTest
00120   holds(VX x, ZeroIntView) {
00121     return rtest_eq_dom(x,0);
00122   }
00123   template<class VX>
00124   forceinline RelTest
00125   holds(VX x, const IntSet& y) {
00126     if ((x.max() < y.min()) || (y.max() < x.min()))
00127       return RT_FALSE;
00128     ViewRanges<VX> rx(x);
00129     IntSetRanges ry(y);
00130     switch (Iter::Ranges::compare(rx,ry)) {
00131     case Iter::Ranges::CS_SUBSET:
00132       return RT_TRUE;
00133     case Iter::Ranges::CS_DISJOINT:
00134       return RT_FALSE;
00135     case Iter::Ranges::CS_NONE:
00136       return RT_MAYBE;
00137     default:
00138       GECODE_NEVER;
00139     }
00140     GECODE_NEVER;
00141     return RT_MAYBE;
00142   }
00143   template<class VX>
00144   forceinline RelTest
00145   holds(VX x, VX y) {
00146     return rtest_eq_dom(x,y);
00147   }
00148 
00149   template<class VX>
00150   forceinline ExecStatus
00151   post_true(Home home, VX x, ConstIntView y) {
00152     GECODE_ME_CHECK(x.eq(home,y.val()));
00153     return ES_OK;
00154   }
00155   template<class VX>
00156   forceinline ExecStatus
00157   post_true(Home home, VX x, ZeroIntView) {
00158     GECODE_ME_CHECK(x.eq(home,0));
00159     return ES_OK;
00160   }
00161   template<class VX>
00162   forceinline ExecStatus
00163   post_true(Home home, VX x, const IntSet& y) {
00164     IntSetRanges ry(y);
00165     GECODE_ME_CHECK(x.inter_r(home,ry,false));
00166     return ES_OK;
00167   }
00168   template<class VX>
00169   forceinline ExecStatus
00170   post_true(Home home, ViewArray<VX>& x, ConstIntView y) {
00171     for (int i=0; i<x.size(); i++)
00172       GECODE_ME_CHECK(x[i].eq(home,y.val()));
00173     return ES_OK;
00174   }
00175   template<class VX>
00176   forceinline ExecStatus
00177   post_true(Home home, ViewArray<VX>& x, ZeroIntView) {
00178     for (int i=0; i<x.size(); i++)
00179       GECODE_ME_CHECK(x[i].eq(home,0));
00180     return ES_OK;
00181   }
00182   template<class VX>
00183   forceinline ExecStatus
00184   post_true(Home home, ViewArray<VX>& x, const IntSet& y) {
00185     for (int i=0; i<x.size(); i++) {
00186       IntSetRanges ry(y);
00187       GECODE_ME_CHECK(x[i].inter_r(home,ry,false));
00188     }
00189     return ES_OK;
00190   }
00191 
00192   template<class VX>
00193   forceinline ExecStatus
00194   post_false(Home home, VX x, ConstIntView y) {
00195     GECODE_ME_CHECK(x.nq(home,y.val()));
00196     return ES_OK;
00197   }
00198   template<class VX>
00199   forceinline ExecStatus
00200   post_false(Home home, VX x, ZeroIntView) {
00201     GECODE_ME_CHECK(x.nq(home,0));
00202     return ES_OK;
00203   }
00204   template<class VX>
00205   forceinline ExecStatus
00206   post_false(Home home, VX x, const IntSet& y) {
00207     IntSetRanges ry(y);
00208     GECODE_ME_CHECK(x.minus_r(home,ry,false));
00209     return ES_OK;
00210   }
00211   template<class VX>
00212   forceinline ExecStatus
00213   post_false(Home home, ViewArray<VX>& x, ConstIntView y) {
00214     for (int i=0; i<x.size(); i++)
00215       GECODE_ME_CHECK(x[i].nq(home,y.val()));
00216     return ES_OK;
00217   }
00218   template<class VX>
00219   forceinline ExecStatus
00220   post_false(Home home, ViewArray<VX>& x, ZeroIntView) {
00221     for (int i=0; i<x.size(); i++)
00222       GECODE_ME_CHECK(x[i].nq(home,0));
00223     return ES_OK;
00224   }
00225   template<class VX>
00226   forceinline ExecStatus
00227   post_false(Home home, ViewArray<VX>& x, const IntSet& y) {
00228     for (int i=0; i<x.size(); i++) {
00229       IntSetRanges ry(y);
00230       GECODE_ME_CHECK(x[i].minus_r(home,ry,false));
00231     }
00232     return ES_OK;
00233   }
00234 
00235   template<class VX>
00236   forceinline ExecStatus
00237   post_true(Home home, ViewArray<VX>& x, VX y) {
00238     ViewArray<VX> z(home,x.size()+1);
00239     z[x.size()] = y;
00240     for (int i=0; i<x.size(); i++)
00241       z[i] = x[i];
00242     return Rel::NaryEqDom<VX>::post(home,z);
00243   }
00244   template<class VX>
00245   forceinline ExecStatus
00246   post_true(Home home, VX x, VX y) {
00247     return Rel::EqDom<VX,VX>::post(home,x,y);
00248   }
00249   template<class VX>
00250   forceinline ExecStatus
00251   post_false(Home home, ViewArray<VX>& x, VX y) {
00252     for (int i=0; i<x.size(); i++)
00253       GECODE_ES_CHECK((Rel::Nq<VX,VX>::post(home,x[i],y)));
00254     return ES_OK;
00255   }
00256   template<class VX>
00257   forceinline ExecStatus
00258   post_false(Home home, VX x, VX y) {
00259     return Rel::Nq<VX,VX>::post(home,x,y);
00260   }
00261 
00262   template<class VX>
00263   forceinline ExecStatus
00264   prune(Space& home, ViewArray<VX>& x, ConstIntView) {
00265     (void) home;
00266     (void) x;
00267     return ES_OK;
00268   }
00269   template<class VX>
00270   forceinline ExecStatus
00271   prune(Space& home, ViewArray<VX>& x, ZeroIntView) {
00272     (void) home;
00273     (void) x;
00274     return ES_OK;
00275   }
00276   template<class VX>
00277   forceinline ExecStatus
00278   prune(Space& home, ViewArray<VX>& x, const IntSet& y) {
00279     (void) home;
00280     (void) x;
00281     (void) y;
00282     return ES_OK;
00283   }
00284   template<class VX>
00285   forceinline ExecStatus
00286   prune(Space& home, ViewArray<VX>& x, VX y) {
00287     if (x.size() == 0)
00288       return ES_OK;
00289     Region r;
00290     ViewRanges<VX>* rx = r.alloc<ViewRanges<VX> >(x.size());
00291     for (int i=0; i<x.size(); i++)
00292       rx[i] = ViewRanges<VX>(x[i]);
00293     Iter::Ranges::NaryUnion u(r, rx, x.size());
00294     GECODE_ME_CHECK(y.inter_r(home, u, false));
00295     return ES_OK;
00296   }
00297 
00298 }}}
00299 
00300 // STATISTICS: int-prop