Generated on Tue Apr 18 10:21:55 2017 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  *  Last modified:
00014  *     $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
00015  *     $Revision: 15137 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 namespace Gecode { namespace Int {
00043 
00045   template<>
00046   class ViewToVarArg<IntView> {
00047   public:
00048     typedef IntVarArgs argtype;
00049   };
00051   template<>
00052   class ViewToVarArg<MinusView> {
00053   public:
00054     typedef IntVarArgs argtype;
00055   };
00057   template<>
00058   class ViewToVarArg<BoolView> {
00059   public:
00060     typedef BoolVarArgs argtype;
00061   };
00062 
00063   template<class View>
00064   forceinline IdxView<View>*
00065   IdxView<View>::allocate(Space& home, int n) {
00066     return home.alloc<IdxView<View> >(n);
00067   }
00068 
00069   template<class View>
00070   forceinline
00071   IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
00072 
00073   template<class View>
00074   forceinline
00075   IdxViewArray<View>::IdxViewArray(const IdxViewArray<View>& a) {
00076     n = a.n; xs = a.xs;
00077   }
00078 
00079   template<class View>
00080   forceinline
00081   IdxViewArray<View>::IdxViewArray(Space& home,
00082     const typename ViewToVarArg<View>::argtype& xa) : xs(NULL) {
00083     n = xa.size();
00084     if (n>0) {
00085       xs = IdxView<View>::allocate(home, n);
00086       for (int i = n; i--; ) {
00087         xs[i].idx = i; xs[i].view = xa[i];
00088       }
00089     }
00090   }
00091 
00092   template<class View>
00093   forceinline
00094   IdxViewArray<View>::IdxViewArray(Space& home, int n0) : xs(NULL) {
00095     n = n0;
00096     if (n>0) {
00097       xs = IdxView<View>::allocate(home, n);
00098     }
00099   }
00100 
00101   template<class View>
00102   forceinline int
00103   IdxViewArray<View>::size(void) const {
00104     return n;
00105   }
00106 
00107   template<class View>
00108   forceinline void
00109   IdxViewArray<View>::size(int n0) {
00110     n = n0;
00111   }
00112 
00113   template<class View>
00114   forceinline IdxView<View>&
00115   IdxViewArray<View>::operator [](int i) {
00116     assert((i >= 0) && (i < size()));
00117     return xs[i];
00118   }
00119 
00120   template<class View>
00121   forceinline const IdxView<View>&
00122   IdxViewArray<View>::operator [](int i) const {
00123     assert((i >= 0) && (i < size()));
00124     return xs[i];
00125   }
00126 
00127   template<class View>
00128   forceinline void
00129   IdxViewArray<View>::subscribe(Space& home, Propagator& p, PropCond pc,
00130                                 bool process) {
00131     for (int i = n; i--; )
00132       xs[i].view.subscribe(home,p,pc,process);
00133   }
00134 
00135   template<class View>
00136   forceinline void
00137   IdxViewArray<View>::cancel(Space& home, Propagator& p, PropCond pc) {
00138     for (int i = n; i--; )
00139       xs[i].view.cancel(home,p,pc);
00140   }
00141 
00142   template<class View>
00143   forceinline void
00144   IdxViewArray<View>::reschedule(Space& home, Propagator& p, PropCond pc) {
00145     for (int i = n; i--; )
00146       xs[i].view.reschedule(home,p,pc);
00147   }
00148 
00149   template<class View>
00150   forceinline void
00151   IdxViewArray<View>::update(Space& home, bool share, IdxViewArray<View>& a) {
00152     n = a.size();
00153     if (n>0) {
00154       xs = IdxView<View>::allocate(home,n);
00155       for (int i=n; i--; ) {
00156         xs[i].idx = a[i].idx;
00157         xs[i].view.update(home,share,a[i].view);
00158       }
00159     }
00160   }
00161 
00162 
00163   template<class Char, class Traits, class View>
00164   std::basic_ostream<Char,Traits>&
00165   operator <<(std::basic_ostream<Char,Traits>& os,
00166               const IdxViewArray<View>& x) {
00167     std::basic_ostringstream<Char,Traits> s;
00168     s.copyfmt(os); s.width(0);
00169     s << '{';
00170     if (x.size() > 0) {
00171       s << x[0].idx << ':' << x[0].view;
00172       for (int i=1; i<x.size(); i++)
00173         s << ", " << x[i].idx << ':' << x[i].view;
00174     }
00175     s << '}';
00176     return os << s.str();
00177   }
00178 
00179 }}
00180 
00181 // STATISTICS: int-prop
00182