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

nary.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  *
00006  *  Copyright:
00007  *     Guido Tack, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-07 09:15:13 +0100 (Thu, 07 Feb 2008) $ by $Author: tack $
00011  *     $Revision: 6105 $
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 Set { namespace Projection {
00039 
00040   template <bool negated>
00041   forceinline
00042   NaryProjection<negated>::NaryProjection
00043   (Space* home, ViewArray<SetView>& x0, ProjectorSet& ps0)
00044     : Propagator(home), x(x0), pc(x.size()), ps(ps0) {
00045     force(home);
00046     Support::DynamicArray<int> scope;
00047     ps.scope(scope, x.size());
00048     for (int i=x.size(); i--;) {
00049       pc[i] = scope[i];
00050       if (pc[i] != PC_SET_ANY + 1) {
00051         if (negated)
00052           pc[i] = ComplementView<SetView>::pc_negateset(pc[i]);
00053         x[i].subscribe(home, this, pc[i]);
00054       }
00055     }
00056   }
00057 
00058   template <bool negated>
00059   forceinline
00060   NaryProjection<negated>::NaryProjection
00061   (Space* home, bool share, NaryProjection& p)
00062     : Propagator(home,share,p) {
00063     x.update(home,share,p.x);
00064     pc.update(home, share, p.pc);
00065     ps.update(home, share, p.ps);
00066   }
00067 
00068   template <bool negated>
00069   PropCost
00070   NaryProjection<negated>::cost(ModEventDelta) const {
00071     switch (x.size()) {
00072     case 1: return PC_UNARY_HI;
00073     case 2: return PC_BINARY_HI;
00074     case 3: return PC_TERNARY_HI;
00075     default: return PC_LINEAR_HI;
00076     }
00077   }
00078 
00079   template <bool negated>
00080   Support::Symbol
00081   NaryProjection<negated>::ati(void) {
00082     if (negated)
00083       return Support::Symbol("set.projectors.NaryProjection<true>");
00084     else
00085       return Support::Symbol("set.projectors.NaryProjection<false>");
00086   }
00087 
00088   template <bool negated>
00089   Reflection::ActorSpec
00090   NaryProjection<negated>::spec(const Space*, Reflection::VarMap&) const {
00091     throw Reflection::ReflectionException("Not implemented");
00092   }
00093 
00094   template <bool negated>
00095   size_t
00096   NaryProjection<negated>::dispose(Space* home) {
00097     unforce(home);
00098     if (!home->failed()) {
00099       for (int i=x.size(); i--;)
00100         if (pc[i] != PC_SET_ANY + 1)
00101           x[i].cancel(home, this, pc[i]);
00102     }
00103     ps.~ProjectorSet();
00104     pc.~SharedArray();
00105     (void) Propagator::dispose(home);
00106     return sizeof(*this);
00107   }
00108 
00109   template <bool negated>
00110   ExecStatus
00111   NaryProjection<negated>::post(Space* home,
00112                                 ViewArray<SetView>& x, ProjectorSet& ps) {
00113     if (ps.arity() != x.size()-1) {
00114       throw Set::InvalidProjector("");
00115     }
00116     (void) new (home) NaryProjection<negated>(home,x,ps);
00117     return ES_OK;
00118   }
00119 
00120   template <bool negated>
00121   Actor*
00122   NaryProjection<negated>::copy(Space* home, bool share) {
00123     return new (home) NaryProjection<negated>(home,share,*this);
00124   }
00125 
00126   template <bool negated>
00127   ExecStatus
00128   NaryProjection<negated>::propagate(Space* home, ModEventDelta) {
00129     bool done = true;
00130     for (int i=x.size(); i--;)
00131       if (!x[i].assigned()) {
00132         done = false; break;
00133       }
00134     ExecStatus es = ps.propagate<negated>(home, x);
00135     if (es == ES_FAILED)
00136       return ES_FAILED;
00137     if (es == __ES_SUBSUMED)
00138       return ES_SUBSUMED(this,home);
00139     return done ? ES_SUBSUMED(this,home) : es;
00140   }
00141 
00142 }}}
00143 
00144 // STATISTICS: set-prop