Generated on Thu Mar 22 10:39:39 2012 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: 2011-07-13 18:55:08 +0200 (Wed, 13 Jul 2011) $ by $Author: schulte $
00011  *     $Revision: 12194 $
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 
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, bool share, FlexDim& d) {
00176     c0.update(home,share,d.c0);
00177     s.update(home,share,d.s);
00178     c1.update(home,share,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 
00194 }}}
00195 
00196 // STATISTICS: int-prop
00197