Generated on Tue Jul 27 2010 21:59:16 for Gecode by doxygen 1.7.1

offset.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, 2002
00008  *
00009  *  Last modified:
00010  *     $Date: 2010-06-29 10:39:13 +0200 (Tue, 29 Jun 2010) $ by $Author: schulte $
00011  *     $Revision: 11118 $
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 {
00039 
00040   /*
00041    * Constructors and initialization
00042    *
00043    */
00044   forceinline
00045   OffsetView::OffsetView(void) {}
00046   forceinline
00047   OffsetView::OffsetView(const IntView& y, int d)
00048     : DerivedView<IntView>(y), c(d) {}
00049 
00050 
00051   /*
00052    * Value access
00053    *
00054    */
00055   forceinline int
00056   OffsetView::offset(void) const {
00057     return c;
00058   }
00059   forceinline int
00060   OffsetView::min(void) const {
00061     return x.min()+c;
00062   }
00063   forceinline int
00064   OffsetView::max(void) const {
00065     return x.max()+c;
00066   }
00067   forceinline int
00068   OffsetView::med(void) const {
00069     return x.med()+c;
00070   }
00071   forceinline int
00072   OffsetView::val(void) const {
00073     return x.val()+c;
00074   }
00075 
00076   forceinline unsigned int
00077   OffsetView::width(void) const {
00078     return x.width();
00079   }
00080   forceinline unsigned int
00081   OffsetView::size(void) const {
00082     return x.size();
00083   }
00084   forceinline unsigned int
00085   OffsetView::regret_min(void) const {
00086     return x.regret_min();
00087   }
00088   forceinline unsigned int
00089   OffsetView::regret_max(void) const {
00090     return x.regret_max();
00091   }
00092 
00093   /*
00094    * Domain tests
00095    *
00096    */
00097   forceinline bool
00098   OffsetView::range(void) const {
00099     return x.range();
00100   }
00101   forceinline bool
00102   OffsetView::in(int n) const {
00103     return x.in(n-c);
00104   }
00105   forceinline bool
00106   OffsetView::in(double n) const {
00107     return x.in(n-c);
00108   }
00109 
00110 
00111   /*
00112    * Domain update by value
00113    *
00114    */
00115   forceinline ModEvent
00116   OffsetView::lq(Space& home, int n) {
00117     return x.lq(home,n-c);
00118   }
00119   forceinline ModEvent
00120   OffsetView::lq(Space& home, double n) {
00121     return x.lq(home,n-c);
00122   }
00123   forceinline ModEvent
00124   OffsetView::le(Space& home, int n) {
00125     return x.le(home,n-c);
00126   }
00127   forceinline ModEvent
00128   OffsetView::le(Space& home, double n) {
00129     return x.le(home,n-c);
00130   }
00131   forceinline ModEvent
00132   OffsetView::gq(Space& home, int n) {
00133     return x.gq(home,n-c);
00134   }
00135   forceinline ModEvent
00136   OffsetView::gq(Space& home, double n) {
00137     return x.gq(home,n-c);
00138   }
00139   forceinline ModEvent
00140   OffsetView::gr(Space& home, int n) {
00141     return x.gr(home,n-c);
00142   }
00143   forceinline ModEvent
00144   OffsetView::gr(Space& home, double n) {
00145     return x.gr(home,n-c);
00146   }
00147   forceinline ModEvent
00148   OffsetView::nq(Space& home, int n) {
00149     return x.nq(home,n-c);
00150   }
00151   forceinline ModEvent
00152   OffsetView::nq(Space& home, double n) {
00153     return x.nq(home,n-c);
00154   }
00155   forceinline ModEvent
00156   OffsetView::eq(Space& home, int n) {
00157     return x.eq(home,n-c);
00158   }
00159   forceinline ModEvent
00160   OffsetView::eq(Space& home, double n) {
00161     return x.eq(home,n-c);
00162   }
00163 
00164 
00165   /*
00166    * Iterator-based domain update
00167    *
00168    */
00169   template<class I>
00170   forceinline ModEvent
00171   OffsetView::narrow_r(Space& home, I& i, bool depend) {
00172     Iter::Ranges::Offset<I> oi(i,-c);
00173     return x.narrow_r(home,oi,depend);
00174   }
00175   template<class I>
00176   forceinline ModEvent
00177   OffsetView::inter_r(Space& home, I& i, bool depend) {
00178     Iter::Ranges::Offset<I> oi(i,-c);
00179     return x.inter_r(home,oi,depend);
00180   }
00181   template<class I>
00182   forceinline ModEvent
00183   OffsetView::minus_r(Space& home, I& i, bool depend) {
00184     Iter::Ranges::Offset<I> oi(i,-c);
00185     return x.minus_r(home,oi,depend);
00186   }
00187   template<class I>
00188   forceinline ModEvent
00189   OffsetView::narrow_v(Space& home, I& i, bool depend) {
00190     Iter::Values::Offset<I> oi(i,-c);
00191     return x.narrow_v(home,oi,depend);
00192   }
00193   template<class I>
00194   forceinline ModEvent
00195   OffsetView::inter_v(Space& home, I& i, bool depend) {
00196     Iter::Values::Offset<I> oi(i,-c);
00197     return x.inter_v(home,oi,depend);
00198   }
00199   template<class I>
00200   forceinline ModEvent
00201   OffsetView::minus_v(Space& home, I& i, bool depend) {
00202     Iter::Values::Offset<I> oi(i,-c);
00203     return x.minus_v(home,oi,depend);
00204   }
00205 
00206 
00207 
00208   /*
00209    * Propagator modification events
00210    *
00211    */
00212   forceinline ModEventDelta
00213   OffsetView::med(ModEvent me) {
00214     return IntView::med(me);
00215   }
00216 
00217 
00218   /*
00219    * Delta information for advisors
00220    *
00221    */
00222   forceinline int
00223   OffsetView::min(const Delta& d) const {
00224     return x.min(d)+c;
00225   }
00226   forceinline int
00227   OffsetView::max(const Delta& d) const {
00228     return x.max(d)+c;
00229   }
00230   forceinline bool
00231   OffsetView::any(const Delta& d) const {
00232     return x.any(d);
00233   }
00234 
00235 
00236 
00237   /*
00238    * Cloning
00239    *
00240    */
00241   forceinline void
00242   OffsetView::update(Space& home, bool share, OffsetView& y) {
00243     DerivedView<IntView>::update(home,share,y);
00244     c=y.c;
00245   }
00246 
00247 
00252   template<>
00253   class ViewRanges<OffsetView>
00254     : public Iter::Ranges::Offset<ViewRanges<IntView> > {
00255   public:
00257 
00258 
00259     ViewRanges(void);
00261     ViewRanges(const OffsetView& x);
00263     void init(const OffsetView& x);
00265   };
00266 
00267   forceinline
00268   ViewRanges<OffsetView>::ViewRanges(void) {}
00269 
00270   forceinline
00271   ViewRanges<OffsetView>::ViewRanges(const OffsetView& x) {
00272     ViewRanges<IntView> xi(x.base());
00273     Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset());
00274   }
00275 
00276   forceinline void
00277   ViewRanges<OffsetView>::init(const OffsetView& x) {
00278     ViewRanges<IntView> xi(x.base());
00279     Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset());
00280   }
00281 
00282   /*
00283    * View comparison
00284    *
00285    */
00286   forceinline bool
00287   same(const OffsetView& x, const OffsetView& y) {
00288     return same(x.base(),y.base()) && (x.offset() == y.offset());
00289   }
00290   forceinline bool
00291   before(const OffsetView& x, const OffsetView& y) {
00292     return before(x.base(),y.base())
00293       || (same(x.base(),y.base()) && (x.offset() < y.offset()));
00294   }
00295 
00296 }}
00297 
00298 // STATISTICS: int-var
00299