Generated on Thu Apr 11 13:59:09 2019 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   };
00059   template<>
00060   class ViewToVarArg<NegBoolView> {
00061   public:
00062     typedef BoolVarArgs argtype;
00063   };
00064 
00065   template<class View>
00066   forceinline IdxView<View>*
00067   IdxView<View>::allocate(Space& home, int n) {
00068     return home.alloc<IdxView<View> >(n);
00069   }
00070 
00071   template<class View>
00072   forceinline
00073   IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
00074 
00075   template<class View>
00076   forceinline
00077   IdxViewArray<View>::IdxViewArray(const IdxViewArray<View>& a) {
00078     n = a.n; xs = a.xs;
00079   }
00080 
00081   template<class View>
00082   forceinline
00083   IdxViewArray<View>::IdxViewArray(Space& home,
00084     const typename ViewToVarArg<View>::argtype& xa) : xs(NULL) {
00085     n = xa.size();
00086     if (n>0) {
00087       xs = IdxView<View>::allocate(home, n);
00088       for (int i=0; i<n; i++) {
00089         xs[i].idx = i; xs[i].view = xa[i];
00090       }
00091     }
00092   }
00093 
00094   template<class View>
00095   forceinline
00096   IdxViewArray<View>::IdxViewArray(Space& home, int n0) : xs(NULL) {
00097     n = n0;
00098     if (n>0) {
00099       xs = IdxView<View>::allocate(home, n);
00100     }
00101   }
00102 
00103   template<class View>
00104   forceinline int
00105   IdxViewArray<View>::size(void) const {
00106     return n;
00107   }
00108 
00109   template<class View>
00110   forceinline void
00111   IdxViewArray<View>::size(int n0) {
00112     n = n0;
00113   }
00114 
00115   template<class View>
00116   forceinline IdxView<View>&
00117   IdxViewArray<View>::operator [](int i) {
00118     assert((i >= 0) && (i < size()));
00119     return xs[i];
00120   }
00121 
00122   template<class View>
00123   forceinline const IdxView<View>&
00124   IdxViewArray<View>::operator [](int i) const {
00125     assert((i >= 0) && (i < size()));
00126     return xs[i];
00127   }
00128 
00129   template<class View>
00130   forceinline void
00131   IdxViewArray<View>::subscribe(Space& home, Propagator& p, PropCond pc,
00132                                 bool process) {
00133     for (int i=0; i<n; i++)
00134       xs[i].view.subscribe(home,p,pc,process);
00135   }
00136 
00137   template<class View>
00138   forceinline void
00139   IdxViewArray<View>::cancel(Space& home, Propagator& p, PropCond pc) {
00140     for (int i=0; i<n; i++)
00141       xs[i].view.cancel(home,p,pc);
00142   }
00143 
00144   template<class View>
00145   forceinline void
00146   IdxViewArray<View>::reschedule(Space& home, Propagator& p, PropCond pc) {
00147     for (int i=0; i<n; i++)
00148       xs[i].view.reschedule(home,p,pc);
00149   }
00150 
00151   template<class View>
00152   forceinline void
00153   IdxViewArray<View>::update(Space& home, IdxViewArray<View>& a) {
00154     n = a.size();
00155     if (n>0) {
00156       xs = IdxView<View>::allocate(home,n);
00157       for (int i=0; i<n; i++) {
00158         xs[i].idx = a[i].idx;
00159         xs[i].view.update(home,a[i].view);
00160       }
00161     }
00162   }
00163 
00164 
00165   template<class Char, class Traits, class View>
00166   std::basic_ostream<Char,Traits>&
00167   operator <<(std::basic_ostream<Char,Traits>& os,
00168               const IdxViewArray<View>& x) {
00169     std::basic_ostringstream<Char,Traits> s;
00170     s.copyfmt(os); s.width(0);
00171     s << '{';
00172     if (x.size() > 0) {
00173       s << x[0].idx << ':' << x[0].view;
00174       for (int i=1; i<x.size(); i++)
00175         s << ", " << x[i].idx << ':' << x[i].view;
00176     }
00177     s << '}';
00178     return os << s.str();
00179   }
00180 
00181 }}
00182 
00183 // STATISTICS: int-prop
00184