Generated on Sun Feb 17 15:24:21 2019 for Gecode by doxygen 1.6.3

dim.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, 2011
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 namespace Gecode { namespace Int { namespace NoOverlap {
00035 
00036   /*
00037    * Dimension with integer size
00038    *
00039    */
00040   forceinline
00041   FixDim::FixDim(void)
00042     : s(0) {}
00043   forceinline
00044   FixDim::FixDim(IntView c0, int s0)
00045     : c(c0), s(s0) {}
00046 
00047   forceinline int
00048   FixDim::ssc(void) const {
00049     return c.min();
00050   }
00051   forceinline int
00052   FixDim::lsc(void) const {
00053     return c.max();
00054   }
00055   forceinline int
00056   FixDim::sec(void) const {
00057     return c.min() + s;
00058   }
00059   forceinline int
00060   FixDim::lec(void) const {
00061     return c.max() + s;
00062   }
00063 
00064   forceinline ExecStatus
00065   FixDim::ssc(Space& home, int n) {
00066     GECODE_ME_CHECK(c.gq(home, n));
00067     return ES_OK;
00068   }
00069   forceinline ExecStatus
00070   FixDim::lec(Space& home, int n) {
00071     GECODE_ME_CHECK(c.lq(home, n - s));
00072     return ES_OK;
00073   }
00074   forceinline ExecStatus
00075   FixDim::nooverlap(Space& home, int n, int m) {
00076     if (n <= m) {
00077       Iter::Ranges::Singleton r(n-s+1,m);
00078       GECODE_ME_CHECK(c.minus_r(home,r,false));
00079     }
00080     return ES_OK;
00081   }
00082   forceinline ExecStatus
00083   FixDim::nooverlap(Space& home, FixDim& d) {
00084     if (d.sec() > lsc()) {
00085       // Propagate that d must be after this
00086       GECODE_ES_CHECK(lec(home,d.lsc()));
00087       GECODE_ES_CHECK(d.ssc(home,sec()));
00088     } else {
00089       nooverlap(home, d.lsc(), d.sec()-1);
00090     }
00091     return ES_OK;
00092   }
00093 
00094   forceinline void
00095   FixDim::update(Space& home, FixDim& d) {
00096     c.update(home,d.c);
00097     s = d.s;
00098   }
00099 
00100   forceinline void
00101   FixDim::subscribe(Space& home, Propagator& p) {
00102     c.subscribe(home,p,PC_INT_DOM);
00103   }
00104   forceinline void
00105   FixDim::cancel(Space& home, Propagator& p) {
00106     c.cancel(home,p,PC_INT_DOM);
00107   }
00108   forceinline void
00109   FixDim::reschedule(Space& home, Propagator& p) {
00110     c.reschedule(home,p,PC_INT_DOM);
00111   }
00112 
00113 
00114   /*
00115    * Dimension with integer view size
00116    *
00117    */
00118   forceinline
00119   FlexDim::FlexDim(void) {}
00120   forceinline
00121   FlexDim::FlexDim(IntView c00, IntView s0, IntView c10)
00122     : c0(c00), s(s0), c1(c10) {}
00123 
00124   forceinline int
00125   FlexDim::ssc(void) const {
00126     return c0.min();
00127   }
00128   forceinline int
00129   FlexDim::lsc(void) const {
00130     return c0.max();
00131   }
00132   forceinline int
00133   FlexDim::sec(void) const {
00134     return c1.min();
00135   }
00136   forceinline int
00137   FlexDim::lec(void) const {
00138     return c1.max();
00139   }
00140 
00141   forceinline ExecStatus
00142   FlexDim::ssc(Space& home, int n) {
00143     GECODE_ME_CHECK(c0.gq(home, n));
00144     return ES_OK;
00145   }
00146   forceinline ExecStatus
00147   FlexDim::lec(Space& home, int n) {
00148     GECODE_ME_CHECK(c1.lq(home, n));
00149     return ES_OK;
00150   }
00151   forceinline ExecStatus
00152   FlexDim::nooverlap(Space& home, int n, int m) {
00153     if (n <= m) {
00154       Iter::Ranges::Singleton r0(n-s.min()+1,m);
00155       GECODE_ME_CHECK(c0.minus_r(home,r0,false));
00156       Iter::Ranges::Singleton r1(n+1,s.min()+m);
00157       GECODE_ME_CHECK(c1.minus_r(home,r1,false));
00158     }
00159     return ES_OK;
00160   }
00161   forceinline ExecStatus
00162   FlexDim::nooverlap(Space& home, FlexDim& d) {
00163     if (d.sec() > lsc()) {
00164       // Propagate that d must be after this
00165       GECODE_ES_CHECK(lec(home,d.lsc()));
00166       GECODE_ES_CHECK(d.ssc(home,sec()));
00167     } else {
00168       nooverlap(home, d.lsc(), d.sec()-1);
00169     }
00170     return ES_OK;
00171   }
00172 
00173 
00174   forceinline void
00175   FlexDim::update(Space& home, FlexDim& d) {
00176     c0.update(home,d.c0);
00177     s.update(home,d.s);
00178     c1.update(home,d.c1);
00179   }
00180 
00181   forceinline void
00182   FlexDim::subscribe(Space& home, Propagator& p) {
00183     c0.subscribe(home,p,PC_INT_DOM);
00184     s.subscribe(home,p,PC_INT_BND);
00185     c1.subscribe(home,p,PC_INT_DOM);
00186   }
00187   forceinline void
00188   FlexDim::cancel(Space& home, Propagator& p) {
00189     c0.cancel(home,p,PC_INT_DOM);
00190     s.cancel(home,p,PC_INT_BND);
00191     c1.cancel(home,p,PC_INT_DOM);
00192   }
00193   forceinline void
00194   FlexDim::reschedule(Space& home, Propagator& p) {
00195     c0.reschedule(home,p,PC_INT_DOM);
00196     s.reschedule(home,p,PC_INT_BND);
00197     c1.reschedule(home,p,PC_INT_DOM);
00198   }
00199 
00200 }}}
00201 
00202 // STATISTICS: int-prop
00203