Generated on Tue May 22 09:40:01 2018 for Gecode by doxygen 1.6.3

idx-view.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  *  Contributing authors:
00007  *     Guido Tack <tack@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Christian Schulte, 2004
00011  *     Guido Tack, 2004
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 
00041   template<>
00042   class ViewToVarArg<IntView> {
00043   public:
00044     typedef IntVarArgs argtype;
00045   };
00047   template<>
00048   class ViewToVarArg<MinusView> {
00049   public:
00050     typedef IntVarArgs argtype;
00051   };
00053   template<>
00054   class ViewToVarArg<BoolView> {
00055   public:
00056     typedef BoolVarArgs argtype;
00057   };
00058 
00059   template<class View>
00060   forceinline IdxView<View>*
00061   IdxView<View>::allocate(Space& home, int n) {
00062     return home.alloc<IdxView<View> >(n);
00063   }
00064 
00065   template<class View>
00066   forceinline
00067   IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
00068 
00069   template<class View>
00070   forceinline
00071   IdxViewArray<View>::IdxViewArray(const IdxViewArray<View>& a) {
00072     n = a.n; xs = a.xs;
00073   }
00074 
00075   template<class View>
00076   forceinline
00077   IdxViewArray<View>::IdxViewArray(Space& home,
00078     const typename ViewToVarArg<View>::argtype& xa) : xs(NULL) {
00079     n = xa.size();
00080     if (n>0) {
00081       xs = IdxView<View>::allocate(home, n);
00082       for (int i = n; i--; ) {
00083         xs[i].idx = i; xs[i].view = xa[i];
00084       }
00085     }
00086   }
00087 
00088   template<class View>
00089   forceinline
00090   IdxViewArray<View>::IdxViewArray(Space& home, int n0) : xs(NULL) {
00091     n = n0;
00092     if (n>0) {
00093       xs = IdxView<View>::allocate(home, n);
00094     }
00095   }
00096 
00097   template<class View>
00098   forceinline int
00099   IdxViewArray<View>::size(void) const {
00100     return n;
00101   }
00102 
00103   template<class View>
00104   forceinline void
00105   IdxViewArray<View>::size(int n0) {
00106     n = n0;
00107   }
00108 
00109   template<class View>
00110   forceinline IdxView<View>&
00111   IdxViewArray<View>::operator [](int i) {
00112     assert((i >= 0) && (i < size()));
00113     return xs[i];
00114   }
00115 
00116   template<class View>
00117   forceinline const IdxView<View>&
00118   IdxViewArray<View>::operator [](int i) const {
00119     assert((i >= 0) && (i < size()));
00120     return xs[i];
00121   }
00122 
00123   template<class View>
00124   forceinline void
00125   IdxViewArray<View>::subscribe(Space& home, Propagator& p, PropCond pc,
00126                                 bool process) {
00127     for (int i = n; i--; )
00128       xs[i].view.subscribe(home,p,pc,process);
00129   }
00130 
00131   template<class View>
00132   forceinline void
00133   IdxViewArray<View>::cancel(Space& home, Propagator& p, PropCond pc) {
00134     for (int i = n; i--; )
00135       xs[i].view.cancel(home,p,pc);
00136   }
00137 
00138   template<class View>
00139   forceinline void
00140   IdxViewArray<View>::reschedule(Space& home, Propagator& p, PropCond pc) {
00141     for (int i = n; i--; )
00142       xs[i].view.reschedule(home,p,pc);
00143   }
00144 
00145   template<class View>
00146   forceinline void
00147   IdxViewArray<View>::update(Space& home, IdxViewArray<View>& a) {
00148     n = a.size();
00149     if (n>0) {
00150       xs = IdxView<View>::allocate(home,n);
00151       for (int i=n; i--; ) {
00152         xs[i].idx = a[i].idx;
00153         xs[i].view.update(home,a[i].view);
00154       }
00155     }
00156   }
00157 
00158 
00159   template<class Char, class Traits, class View>
00160   std::basic_ostream<Char,Traits>&
00161   operator <<(std::basic_ostream<Char,Traits>& os,
00162               const IdxViewArray<View>& x) {
00163     std::basic_ostringstream<Char,Traits> s;
00164     s.copyfmt(os); s.width(0);
00165     s << '{';
00166     if (x.size() > 0) {
00167       s << x[0].idx << ':' << x[0].view;
00168       for (int i=1; i<x.size(); i++)
00169         s << ", " << x[i].idx << ':' << x[i].view;
00170     }
00171     s << '}';
00172     return os << s.str();
00173   }
00174 
00175 }}
00176 
00177 // STATISTICS: int-prop
00178