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