Generated on Mon Nov 30 23:53:30 2009 for Gecode by doxygen 1.6.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: 2009-09-08 21:10:29 +0200 (Tue, 08 Sep 2009) $ by $Author: schulte $
00011  *     $Revision: 9692 $
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 {
00039 
00040   namespace Int {
00041 
00042     /*
00043      * Constructors and initialization
00044      *
00045      */
00046     forceinline
00047     OffsetView::OffsetView(void) {}
00048     forceinline
00049     OffsetView::OffsetView(const IntView& x, int d)
00050       : DerivedViewBase<IntView>(x), c(d) {}
00051     forceinline void
00052     OffsetView::init(const IntView& x, int d) {
00053       view=x; c=d;
00054     }
00055     forceinline int
00056     OffsetView::offset(void) const {
00057       return c;
00058     }
00059 
00060 
00061     /*
00062      * Value access
00063      *
00064      */
00065     forceinline int
00066     OffsetView::min(void) const {
00067       return view.min()+c;
00068     }
00069     forceinline int
00070     OffsetView::max(void) const {
00071       return view.max()+c;
00072     }
00073     forceinline int
00074     OffsetView::med(void) const {
00075       return view.med()+c;
00076     }
00077     forceinline int
00078     OffsetView::val(void) const {
00079       return view.val()+c;
00080     }
00081 
00082     forceinline unsigned int
00083     OffsetView::width(void) const {
00084       return view.width();
00085     }
00086     forceinline unsigned int
00087     OffsetView::size(void) const {
00088       return view.size();
00089     }
00090     forceinline unsigned int
00091     OffsetView::regret_min(void) const {
00092       return view.regret_min();
00093     }
00094     forceinline unsigned int
00095     OffsetView::regret_max(void) const {
00096       return view.regret_max();
00097     }
00098 
00099     /*
00100      * Domain tests
00101      *
00102      */
00103     forceinline bool
00104     OffsetView::range(void) const {
00105       return view.range();
00106     }
00107     forceinline bool
00108     OffsetView::assigned(void) const {
00109       return view.assigned();
00110     }
00111 
00112     forceinline bool
00113     OffsetView::in(int n) const {
00114       return view.in(n-c);
00115     }
00116     forceinline bool
00117     OffsetView::in(double n) const {
00118       return view.in(n-c);
00119     }
00120 
00121 
00122     /*
00123      * Domain update by value
00124      *
00125      */
00126     forceinline ModEvent
00127     OffsetView::lq(Space& home, int n) {
00128       return view.lq(home,n-c);
00129     }
00130     forceinline ModEvent
00131     OffsetView::lq(Space& home, double n) {
00132       return view.lq(home,n-c);
00133     }
00134     forceinline ModEvent
00135     OffsetView::le(Space& home, int n) {
00136       return view.le(home,n-c);
00137     }
00138     forceinline ModEvent
00139     OffsetView::le(Space& home, double n) {
00140       return view.le(home,n-c);
00141     }
00142     forceinline ModEvent
00143     OffsetView::gq(Space& home, int n) {
00144       return view.gq(home,n-c);
00145     }
00146     forceinline ModEvent
00147     OffsetView::gq(Space& home, double n) {
00148       return view.gq(home,n-c);
00149     }
00150     forceinline ModEvent
00151     OffsetView::gr(Space& home, int n) {
00152       return view.gr(home,n-c);
00153     }
00154     forceinline ModEvent
00155     OffsetView::gr(Space& home, double n) {
00156       return view.gr(home,n-c);
00157     }
00158     forceinline ModEvent
00159     OffsetView::nq(Space& home, int n) {
00160       return view.nq(home,n-c);
00161     }
00162     forceinline ModEvent
00163     OffsetView::nq(Space& home, double n) {
00164       return view.nq(home,n-c);
00165     }
00166     forceinline ModEvent
00167     OffsetView::eq(Space& home, int n) {
00168       return view.eq(home,n-c);
00169     }
00170     forceinline ModEvent
00171     OffsetView::eq(Space& home, double n) {
00172       return view.eq(home,n-c);
00173     }
00174 
00175 
00176     /*
00177      * Iterator-based domain update
00178      *
00179      */
00180     template<class I>
00181     forceinline ModEvent
00182     OffsetView::narrow_r(Space& home, I& i, bool depend) {
00183       Iter::Ranges::Offset<I> oi(i,-c);
00184       return view.narrow_r(home,oi,depend);
00185     }
00186     template<class I>
00187     forceinline ModEvent
00188     OffsetView::inter_r(Space& home, I& i, bool depend) {
00189       Iter::Ranges::Offset<I> oi(i,-c);
00190       return view.inter_r(home,oi,depend);
00191     }
00192     template<class I>
00193     forceinline ModEvent
00194     OffsetView::minus_r(Space& home, I& i, bool depend) {
00195       Iter::Ranges::Offset<I> oi(i,-c);
00196       return view.minus_r(home,oi,depend);
00197     }
00198     template<class I>
00199     forceinline ModEvent
00200     OffsetView::narrow_v(Space& home, I& i, bool depend) {
00201       Iter::Values::Offset<I> oi(i,-c);
00202       return view.narrow_v(home,oi,depend);
00203     }
00204     template<class I>
00205     forceinline ModEvent
00206     OffsetView::inter_v(Space& home, I& i, bool depend) {
00207       Iter::Values::Offset<I> oi(i,-c);
00208       return view.inter_v(home,oi,depend);
00209     }
00210     template<class I>
00211     forceinline ModEvent
00212     OffsetView::minus_v(Space& home, I& i, bool depend) {
00213       Iter::Values::Offset<I> oi(i,-c);
00214       return view.minus_v(home,oi,depend);
00215     }
00216 
00217 
00218 
00219     /*
00220      * Propagator modification events
00221      *
00222      */
00223     forceinline void
00224     OffsetView::schedule(Space& home, Propagator& p, ModEvent me) {
00225       return IntView::schedule(home,p,me);
00226     }
00227     forceinline ModEvent
00228     OffsetView::me(const ModEventDelta& med) {
00229       return IntView::me(med);
00230     }
00231     forceinline ModEventDelta
00232     OffsetView::med(ModEvent me) {
00233       return IntView::med(me);
00234     }
00235 
00236 
00237     /*
00238      * Dependencies
00239      *
00240      */
00241     forceinline void
00242     OffsetView::subscribe(Space& home, Propagator& p, PropCond pc,
00243                           bool process) {
00244       view.subscribe(home,p,pc,process);
00245     }
00246     forceinline void
00247     OffsetView::cancel(Space& home, Propagator& p, PropCond pc) {
00248       view.cancel(home,p,pc);
00249     }
00250     forceinline void
00251     OffsetView::subscribe(Space& home, Advisor& a) {
00252       view.subscribe(home,a);
00253     }
00254     forceinline void
00255     OffsetView::cancel(Space& home, Advisor& a) {
00256       view.cancel(home,a);
00257     }
00258 
00259 
00260     /*
00261      * Delta information for advisors
00262      *
00263      */
00264     forceinline ModEvent
00265     OffsetView::modevent(const Delta& d) {
00266       return IntView::modevent(d);
00267     }
00268     forceinline int
00269     OffsetView::min(const Delta& d) const {
00270       return view.min(d)+c;
00271     }
00272     forceinline int
00273     OffsetView::max(const Delta& d) const {
00274       return view.max(d)+c;
00275     }
00276     forceinline bool
00277     OffsetView::any(const Delta& d) const {
00278       return view.any(d);
00279     }
00280 
00281 
00282 
00283     /*
00284      * Cloning
00285      *
00286      */
00287     forceinline void
00288     OffsetView::update(Space& home, bool share, OffsetView& x) {
00289       c=x.c; view.update(home,share,x.view);
00290     }
00291 
00292 
00297     template<>
00298     class ViewRanges<OffsetView>
00299       : public Iter::Ranges::Offset<ViewRanges<IntView> > {
00300     public:
00302 
00303 
00304       ViewRanges(void);
00306       ViewRanges(const OffsetView& x);
00308       void init(const OffsetView& x);
00310     };
00311 
00312     forceinline
00313     ViewRanges<OffsetView>::ViewRanges(void) {}
00314 
00315     forceinline
00316     ViewRanges<OffsetView>::ViewRanges(const OffsetView& x) {
00317       ViewRanges<IntView> xi(x.base());
00318       Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset());
00319     }
00320 
00321     forceinline void
00322     ViewRanges<OffsetView>::init(const OffsetView& x) {
00323       ViewRanges<IntView> xi(x.base());
00324       Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset());
00325     }
00326   }
00327 
00328   /*
00329    * View comparison
00330    *
00331    */
00332   forceinline bool
00333   same(const Int::OffsetView& x, const Int::OffsetView& y) {
00334     return same(x.base(),y.base()) && (x.offset() == y.offset());
00335   }
00336   forceinline bool
00337   before(const Int::OffsetView& x, const Int::OffsetView& y) {
00338     return before(x.base(),y.base())
00339       || (same(x.base(),y.base()) && (x.offset() < y.offset()));
00340   }
00341 
00342 }
00343 
00344 // STATISTICS: int-var
00345