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

naryone.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Patrick Pekczynski <pekczynski@ps.uni-sb.de>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Patrick Pekczynski, 2006
00009  *     Guido Tack, 2007
00010  *
00011  *  Last modified:
00012  *     $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $
00013  *     $Revision: 6017 $
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 CpltSet {
00041 
00042   template <class View0, class View1>
00043   forceinline
00044   NaryOneCpltSetPropagator<View0, View1>
00045   ::NaryOneCpltSetPropagator(Space* home, ViewArray<View0>& x, 
00046                              View1& y, bdd& d0) : Super(home, x, y), d(d0) {
00047     Super::force(home);
00048   }
00049 
00050   template <class View0, class View1>
00051   forceinline
00052   NaryOneCpltSetPropagator<View0, View1>
00053   ::NaryOneCpltSetPropagator(Space* home, bool share, 
00054                              NaryOneCpltSetPropagator& p)
00055     : Super(home, share, p), d(p.d) {}
00056 
00057   template <class View0, class View1>
00058   forceinline ExecStatus
00059   NaryOneCpltSetPropagator<View0, View1>::post(Space* home,
00060                                                ViewArray<View0>& x, View1& y, 
00061                                                bdd& d0) {
00062     (void) new (home) NaryOneCpltSetPropagator(home, x, y, d0);
00063     return ES_OK;
00064   }
00065 
00066   template <class View0, class View1>
00067   Support::Symbol
00068   NaryOneCpltSetPropagator<View0, View1>::ati(void) {
00069     return 
00070       Reflection::mangle<View0,View1>("Gecode::CpltSet::NaryOneCpltSetPropagator");
00071   }
00072 
00073   template <class View0, class View1>
00074   Reflection::ActorSpec
00075   NaryOneCpltSetPropagator<View0,View1>::spec(const Space* home,
00076                                               Reflection::VarMap& m) const {
00077     throw Reflection::ReflectionException("Not implemented");
00078   } 
00079 
00080   template <class View0, class View1>
00081   forceinline Actor*
00082   NaryOneCpltSetPropagator<View0, View1>::copy(Space* home, bool share) {
00083     return new (home) NaryOneCpltSetPropagator(home, share, *this);
00084   }
00085 
00086   template <class View0, class View1>
00087   ExecStatus
00088   NaryOneCpltSetPropagator<View0, View1>::divide_conquer(Space* home, bdd& p,
00089                                                          int l, int r,
00090                                                          int ypos) {
00091     if (l == r) {
00092       ModEvent me = ME_CPLTSET_NONE;
00093       if (l == ypos) {
00094         GECODE_ME_CHECK(me = y.intersect(home, p));
00095       } else {
00096         GECODE_ME_CHECK(me = x[l].intersect(home, p));
00097       }
00098       return ES_OK;
00099     }
00100 
00101     int h = (r + l) / 2;
00102 
00103     // computing psi without recursion
00104     bdd left = p;
00105     for (int i = r; i >= h + 1; i--) {
00106       if (i == ypos) {
00107         quantify(left, y);
00108       } else {
00109         quantify(left, x[i]);
00110       }
00111     }
00112  
00113     ExecStatus es = ES_OK;
00114     GECODE_ES_CHECK(es = divide_conquer(home, left, l, h, ypos));
00115 
00116     bdd right = p;
00117     for (int i = h; i >= l; i-- ) {
00118       if (i == ypos) {
00119         quantify(right, y);
00120       } else {
00121         quantify(right, x[i]);
00122       }
00123     }
00124 
00125     GECODE_ES_CHECK(es = divide_conquer(home, right, h + 1, r, ypos));
00126     return es;
00127   }
00128   
00129   template <class View0, class View1>
00130   forceinline ExecStatus 
00131   NaryOneCpltSetPropagator<View0, View1>::propagate(Space* home, ModEventDelta) {
00132     bool assigned = true;
00133     int n = x.size();
00134     ExecStatus es = ES_OK;
00135     int ypos = n;
00136 
00137     GECODE_ES_CHECK(es = divide_conquer(home, d, 0, n, ypos));
00138 
00139     assigned = true;
00140     for (int i = x.size(); i--; ) {
00141       assigned &= x[i].assigned();
00142     }
00143     if (assigned) {
00144       return ES_SUBSUMED(this, home);
00145     }
00146 
00147     return ES_FIX;
00148   }
00149 
00150   template <class View0, class View1>
00151   size_t
00152   NaryOneCpltSetPropagator<View0, View1>::dispose(Space* home) {
00153     Super::unforce(home);
00154     if (!home->failed()) {
00155       x.cancel(home, this, PC_CPLTSET_DOM);
00156       y.cancel(home, this, PC_CPLTSET_DOM);
00157     }
00158     manager.dispose(d);
00159     Super::dispose(home);
00160     return sizeof(*this);
00161   }
00162 
00163 }}
00164 
00165 // STATISTICS: cpltset-prop