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

narytwo.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  *
00006  *  Copyright:
00007  *     Patrick Pekczynski, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $
00011  *     $Revision: 6017 $
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 CpltSet {
00039 
00040   template <class View0, class View1>
00041   ExecStatus
00042   NaryTwoCpltSetPropagator<View0, View1>::divide_conquer(Space* home, bdd& p, 
00043                                       int l, int r, int ypos, int zpos) {
00044     if (l == r) {
00045       ModEvent me = ME_CPLTSET_NONE;
00046       if (l == ypos) {
00047         me  = y.intersect(home, p);
00048       } else {
00049         if (l == zpos) {
00050           me = z.intersect(home, p);
00051         } else {
00052           me = x[l].intersect(home, p);
00053         }
00054       }
00055       if (me_failed(me)) {
00056         return ES_FAILED;
00057       }
00058       return ES_OK;
00059     }
00060     int h = (r + l) / 2;
00061 
00062     // computing psi without recursion
00063     bdd left = p;
00064     for (int i = r; i >= h + 1; i--) {
00065       if (i == zpos) {
00066         quantify(left, z);
00067       } else {
00068         if (i == ypos) {
00069           quantify(left, y);
00070         } else {
00071           quantify(left, x[i]);
00072         }
00073       }
00074     }
00075    
00076     ExecStatus es = ES_OK;
00077     GECODE_ES_CHECK(es = divide_conquer(home, left, l, h, ypos, zpos));
00078 
00079     bdd right = p;
00080     for (int i = h; i >= l; i-- ) {
00081       if (i == zpos) {
00082         quantify(right, z);
00083       } else {
00084         if (i == ypos) {
00085           quantify(right, y);
00086         } else {
00087           quantify(right, x[i]);
00088         }
00089       }
00090     }
00091 
00092     GECODE_ES_CHECK(es = divide_conquer(home, right, h + 1, r , ypos, zpos));
00093     return es;
00094   }
00095   
00096   template <class View0, class View1>
00097   forceinline
00098   NaryTwoCpltSetPropagator<View0, View1>
00099   ::NaryTwoCpltSetPropagator(Space* home, ViewArray<View0>& x0,
00100                              View1& y0, View1& z0, bdd&)
00101   : Propagator(home), x(x0), y(y0), z(z0) {
00102     Propagator::force(home);
00103     x.subscribe(home, this, PC_CPLTSET_DOM);
00104     y.subscribe(home, this, PC_CPLTSET_DOM);
00105     z.subscribe(home, this, PC_CPLTSET_DOM);
00106   }
00107 
00108   template <class View0, class View1>
00109   forceinline
00110   NaryTwoCpltSetPropagator<View0, View1>
00111   ::NaryTwoCpltSetPropagator(Space* home, bool share, 
00112                              NaryTwoCpltSetPropagator& p)
00113     : Propagator(home, share, p), d(p.d) {
00114     x.update(home,share,p.x);
00115     y.update(home,share,p.y);
00116     z.update(home,share,p.z);
00117   }
00118 
00119   template <class View0, class View1>
00120   forceinline ExecStatus
00121   NaryTwoCpltSetPropagator<View0, View1>::post(Space* home, ViewArray<View0>& x, 
00122                             View1& y, View1& z, bdd& d0) {
00123     (void) new (home) NaryTwoCpltSetPropagator(home, x, y, z, d0);
00124     return ES_OK;
00125   }
00126 
00127   template <class View0, class View1>
00128   Support::Symbol
00129   NaryTwoCpltSetPropagator<View0, View1>::ati(void) {
00130     return 
00131       Reflection::mangle<View0,View1>("Gecode::CpltSet::NaryTwoCpltSetPropagator");
00132   }
00133 
00134   template <class View0, class View1>
00135   Reflection::ActorSpec
00136   NaryTwoCpltSetPropagator<View0,View1>::spec(const Space*,
00137                                               Reflection::VarMap&) const {
00138     throw Reflection::ReflectionException("Not implemented");
00139   } 
00140 
00141   template <class View0, class View1>
00142   forceinline Actor*
00143   NaryTwoCpltSetPropagator<View0, View1>::copy(Space* home, bool share) {
00144     return new (home) NaryTwoCpltSetPropagator(home, share, *this);
00145   }
00146   
00147   template <class View0, class View1>
00148   forceinline ExecStatus 
00149   NaryTwoCpltSetPropagator<View0, View1>::propagate(Space* home, ModEventDelta) {
00150     bool assigned = true;
00151     int n = x.size();
00152     ExecStatus es = ES_OK;
00153     int ypos = n;
00154     int zpos = n + 1;
00155 
00156     GECODE_ES_CHECK(es = divide_conquer(home, d, 0, n + 1, ypos, zpos));
00157 
00158     assigned = true;
00159     for (int i = x.size(); i--; ) {
00160       assigned &= x[i].assigned();
00161     }
00162     if (assigned) {
00163       return ES_SUBSUMED(this, home);
00164     }
00165 
00166     return ES_FIX;
00167   }
00168 
00169   template <class View0, class View1>
00170   PropCost
00171   NaryTwoCpltSetPropagator<View0,View1>::cost(ModEventDelta) const {
00172     return cost_lo(x.size()+2, PC_LINEAR_LO);
00173   }
00174 
00175   template <class View0, class View1>
00176   size_t
00177   NaryTwoCpltSetPropagator<View0, View1>::dispose(Space* home) {
00178     unforce(home);
00179     if (!home->failed()) {
00180       x.cancel(home, this, PC_CPLTSET_DOM);
00181       y.cancel(home, this, PC_CPLTSET_DOM);
00182       z.cancel(home, this, PC_CPLTSET_DOM);
00183     }
00184     manager.dispose(d);
00185     (void) Propagator::dispose(home);
00186     return sizeof(*this);
00187   }
00188 
00189 }}
00190 
00191 // STATISTICS: cpltset-prop