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

idxarray.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *     Christian Schulte <schulte@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Guido Tack, 2004,2005
00009  *     Christian Schulte, 2004,2005
00010  *
00011  *  Last modified:
00012  *     $Date: 2008-05-27 19:24:07 +0200 (Tue, 27 May 2008) $ by $Author: tack $
00013  *     $Revision: 6982 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 namespace Gecode { namespace Set { namespace Element {
00041 
00042   template <class View>
00043   forceinline IdxView<View>*
00044   IdxView<View>::allocate(Space* home, int n) {
00045     return static_cast<IdxView<View>*>(home->alloc(sizeof(IdxView<View>)*n));
00046   }
00047 
00048   template <class View>
00049   IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
00050 
00051   template <class View>
00052   IdxViewArray<View>::IdxViewArray(const IdxViewArray<View>& a) {
00053     n = a.n; xs = a.xs;
00054   }
00055 
00056   template <class View>
00057   IdxViewArray<View>::IdxViewArray(Space* home, const SetVarArgs& xa)
00058     : xs(NULL) {
00059     n = xa.size();
00060     if (n>0) {
00061       xs = IdxView<View>::allocate(home, n);
00062       for (int i = n; i--; ) {
00063         SetView xav(xa[i]);
00064         View xavv(xav);
00065         xs[i].idx = i; xs[i].var = xavv;
00066       }
00067     }
00068   }
00069 
00070   template <class View>
00071   forceinline int
00072   IdxViewArray<View>::size(void) const {
00073     return n;
00074   }
00075 
00076   template <class View>
00077   forceinline void
00078   IdxViewArray<View>::size(int n0) {
00079     n = n0;
00080   }
00081 
00082   template <class View>
00083   forceinline IdxView<View>&
00084   IdxViewArray<View>::operator[](int i) {
00085     assert((i >= 0) && (i < size()));
00086     return xs[i];
00087   }
00088 
00089   template <class View>
00090   forceinline const IdxView<View>&
00091   IdxViewArray<View>::operator[](int i) const {
00092     assert((i >= 0) && (i < size()));
00093     return xs[i];
00094   }
00095 
00096   template <class View>
00097   void
00098   IdxViewArray<View>::subscribe(Space* home, Propagator* p, PropCond pc,
00099                                 bool process) {
00100     for (int i = n; i--; )
00101       xs[i].var.subscribe(home,p,pc,process);
00102   }
00103 
00104   template <class View>
00105   void
00106   IdxViewArray<View>::cancel(Space* home, Propagator* p, PropCond pc) {
00107     for (int i = n; i--; )
00108       xs[i].var.cancel(home,p,pc);
00109   }
00110 
00111   template <class View>
00112   void
00113   IdxViewArray<View>::update(Space* home, bool share, IdxViewArray<View>& a) {
00114     n = a.size();
00115     if (n>0) {
00116       xs = IdxView<View>::allocate(home,n);
00117       for (int i=n; i--; ) {
00118         xs[i].idx = a[i].idx;
00119         xs[i].var.update(home,share,a[i].var);
00120       }
00121     }
00122   }
00123   
00124   template <class View>
00125   Reflection::Arg*
00126   IdxViewArray<View>::spec(const Space* home, Reflection::VarMap& m) const {
00127     Reflection::IntArrayArg* is = Reflection::Arg::newIntArray(n);
00128     for (int i = 0; i<n; i++)
00129       (*is)[i] = xs[i].idx;
00130     Reflection::ArrayArg* s = Reflection::Arg::newArray(n);
00131     for (int i = 0; i<n; i++)
00132       (*s)[i] = xs[i].var.spec(home, m);
00133     return Reflection::Arg::newPair(is,s);
00134   }
00135 
00136   template <class View>
00137   IdxViewArray<View>::IdxViewArray(Space* home,
00138                                    const Reflection::VarMap& vars,
00139                                    Reflection::Arg* spec) : xs(NULL) {
00140     Reflection::IntArrayArg* is = spec->first()->toIntArray();
00141     Reflection::ArrayArg* s = spec->second()->toArray();
00142     n = is->size();
00143     if (n>0) {
00144       xs = IdxView<View>::allocate(home, n);
00145       for (int i = n; i--; ) {
00146         View xavv(home, vars, (*s)[i]);
00147         xs[i].idx = (*is)[i]; xs[i].var = xavv;
00148       }
00149     }                                     
00150   }
00151 
00152 }}}
00153 
00154 // STATISTICS: set-prop
00155