Generated on Mon Aug 25 11:35:39 2008 for Gecode by doxygen 1.5.6

offset.icc

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: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $
00011  *     $Revision: 6017 $
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     forceinline
00060     OffsetView::OffsetView(Space* home, const Reflection::VarMap& vars,
00061                            Reflection::Arg* arg)
00062     : DerivedViewBase<IntView>(IntView(home, vars, arg->second())),
00063       c(arg->first()->toInt()) {}
00064 
00065     /*
00066      * Value access
00067      *
00068      */
00069     forceinline int
00070     OffsetView::min(void) const {
00071       return view.min()+c;
00072     }
00073     forceinline int
00074     OffsetView::max(void) const {
00075       return view.max()+c;
00076     }
00077     forceinline int
00078     OffsetView::med(void) const {
00079       return view.med()+c;
00080     }
00081     forceinline int
00082     OffsetView::val(void) const {
00083       return view.val()+c;
00084     }
00085 
00086     forceinline unsigned int
00087     OffsetView::width(void) const {
00088       return view.width();
00089     }
00090     forceinline unsigned int
00091     OffsetView::size(void) const {
00092       return view.size();
00093     }
00094     forceinline unsigned int
00095     OffsetView::regret_min(void) const {
00096       return view.regret_min();
00097     }
00098     forceinline unsigned int
00099     OffsetView::regret_max(void) const {
00100       return view.regret_max();
00101     }
00102 
00103     /*
00104      * Domain tests
00105      *
00106      */
00107     forceinline bool
00108     OffsetView::range(void) const {
00109       return view.range();
00110     }
00111     forceinline bool
00112     OffsetView::assigned(void) const {
00113       return view.assigned();
00114     }
00115 
00116     forceinline bool
00117     OffsetView::in(int n) const {
00118       return view.in(n-c);
00119     }
00120     forceinline bool
00121     OffsetView::in(double n) const {
00122       return view.in(n-c);
00123     }
00124 
00125 
00126     /*
00127      * Domain update by value
00128      *
00129      */
00130     forceinline ModEvent
00131     OffsetView::lq(Space* home, int n) {
00132       return view.lq(home,n-c);
00133     }
00134     forceinline ModEvent
00135     OffsetView::lq(Space* home, double n) {
00136       return view.lq(home,n-c);
00137     }
00138     forceinline ModEvent
00139     OffsetView::le(Space* home, int n) {
00140       return view.le(home,n-c);
00141     }
00142     forceinline ModEvent
00143     OffsetView::le(Space* home, double n) {
00144       return view.le(home,n-c);
00145     }
00146     forceinline ModEvent
00147     OffsetView::gq(Space* home, int n) {
00148       return view.gq(home,n-c);
00149     }
00150     forceinline ModEvent
00151     OffsetView::gq(Space* home, double n) {
00152       return view.gq(home,n-c);
00153     }
00154     forceinline ModEvent
00155     OffsetView::gr(Space* home, int n) {
00156       return view.gr(home,n-c);
00157     }
00158     forceinline ModEvent
00159     OffsetView::gr(Space* home, double n) {
00160       return view.gr(home,n-c);
00161     }
00162     forceinline ModEvent
00163     OffsetView::nq(Space* home, int n) {
00164       return view.nq(home,n-c);
00165     }
00166     forceinline ModEvent
00167     OffsetView::nq(Space* home, double n) {
00168       return view.nq(home,n-c);
00169     }
00170     forceinline ModEvent
00171     OffsetView::eq(Space* home, int n) {
00172       return view.eq(home,n-c);
00173     }
00174     forceinline ModEvent
00175     OffsetView::eq(Space* home, double n) {
00176       return view.eq(home,n-c);
00177     }
00178 
00179 
00180     /*
00181      * Iterator-based domain update
00182      *
00183      */
00184     template <class I>
00185     forceinline ModEvent
00186     OffsetView::narrow_r(Space* home, I& i, bool depend) {
00187       Iter::Ranges::Offset<I> oi(i,-c); 
00188       return view.narrow_r(home,oi,depend);
00189     }
00190     template <class I>
00191     forceinline ModEvent
00192     OffsetView::inter_r(Space* home, I& i, bool depend) {
00193       Iter::Ranges::Offset<I> oi(i,-c); 
00194       return view.inter_r(home,oi,depend);
00195     }
00196     template <class I>
00197     forceinline ModEvent
00198     OffsetView::minus_r(Space* home, I& i, bool depend) {
00199       Iter::Ranges::Offset<I> oi(i,-c); 
00200       return view.minus_r(home,oi,depend);
00201     }
00202     template <class I>
00203     forceinline ModEvent
00204     OffsetView::narrow_v(Space* home, I& i, bool depend) {
00205       Iter::Values::Offset<I> oi(i,-c); 
00206       return view.narrow_v(home,oi,depend);
00207     }
00208     template <class I>
00209     forceinline ModEvent
00210     OffsetView::inter_v(Space* home, I& i, bool depend) {
00211       Iter::Values::Offset<I> oi(i,-c); 
00212       return view.inter_v(home,oi,depend);
00213     }
00214     template <class I>
00215     forceinline ModEvent
00216     OffsetView::minus_v(Space* home, I& i, bool depend) {
00217       Iter::Values::Offset<I> oi(i,-c); 
00218       return view.minus_v(home,oi,depend);
00219     }
00220 
00221 
00222 
00223     /*
00224      * Propagator modification events
00225      *
00226      */
00227     forceinline void
00228     OffsetView::schedule(Space* home, Propagator* p, ModEvent me) {
00229       return IntView::schedule(home,p,me);
00230     }
00231     forceinline ModEvent
00232     OffsetView::me(ModEventDelta med) {
00233       return IntView::me(med);
00234     }
00235     forceinline ModEventDelta
00236     OffsetView::med(ModEvent me) {
00237       return IntView::med(me);
00238     }
00239 
00240 
00241     /*
00242      * Dependencies
00243      *
00244      */
00245     forceinline void
00246     OffsetView::subscribe(Space* home, Propagator* p, PropCond pc, 
00247                           bool process) {
00248       view.subscribe(home,p,pc,process);
00249     }
00250     forceinline void
00251     OffsetView::cancel(Space* home, Propagator* p, PropCond pc) {
00252       view.cancel(home,p,pc);
00253     }
00254     forceinline void
00255     OffsetView::subscribe(Space* home, Advisor* a) {
00256       view.subscribe(home,a);
00257     }
00258     forceinline void
00259     OffsetView::cancel(Space* home, Advisor* a) {
00260       view.cancel(home,a);
00261     }
00262 
00263 
00264     /*
00265      * Delta information for advisors
00266      *
00267      */
00268     forceinline ModEvent
00269     OffsetView::modevent(const Delta* d) {
00270       return IntView::modevent(d);
00271     }
00272     forceinline int
00273     OffsetView::min(const Delta* d) const {
00274       return view.min(d)+c;
00275     }
00276     forceinline int
00277     OffsetView::max(const Delta* d) const {
00278       return view.max(d)+c;
00279     }
00280     forceinline bool
00281     OffsetView::any(const Delta* d) const {
00282       return view.any(d);
00283     }
00284 
00285 
00286 
00287     /*
00288      * Cloning
00289      *
00290      */
00291     forceinline void
00292     OffsetView::update(Space* home, bool share, OffsetView& x) {
00293       c=x.c; view.update(home,share,x.view);
00294     }
00295 
00296     /*
00297      * Serialization
00298      *
00299      */
00300     forceinline Reflection::Arg*
00301     OffsetView::spec(const Space* home, Reflection::VarMap& m) const {
00302       return Reflection::Arg::newPair(Reflection::Arg::newInt(c), 
00303                                       view.spec(home, m));
00304     }
00305     inline Support::Symbol
00306     OffsetView::type(void) {
00307       return Support::Symbol("Gecode::Int::OffsetView");
00308     }
00309 
00314     template <>
00315     class ViewRanges<OffsetView>
00316       : public Iter::Ranges::Offset<ViewRanges<IntView> > {
00317     public:
00319 
00320 
00321       ViewRanges(void);
00323       ViewRanges(const OffsetView& x);
00325       void init(const OffsetView& x);
00327     };
00328 
00329     forceinline
00330     ViewRanges<OffsetView>::ViewRanges(void) {}
00331 
00332     forceinline
00333     ViewRanges<OffsetView>::ViewRanges(const OffsetView& x) {
00334       ViewRanges<IntView> xi(x.base());
00335       Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset());
00336     }
00337 
00338     forceinline void
00339     ViewRanges<OffsetView>::init(const OffsetView& x) {
00340       ViewRanges<IntView> xi(x.base());
00341       Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset());
00342     }
00343   }
00344 
00345   /*
00346    * View comparison
00347    *
00348    */
00349   forceinline bool
00350   same(const Int::OffsetView& x, const Int::OffsetView& y) {
00351     return same(x.base(),y.base()) && (x.offset() == y.offset());
00352   }
00353   forceinline bool
00354   before(const Int::OffsetView& x, const Int::OffsetView& y) {
00355     return before(x.base(),y.base())
00356       || (same(x.base(),y.base()) && (x.offset() < y.offset()));
00357   }
00358 
00359 }
00360 
00361 // STATISTICS: int-var
00362