Generated on Wed Nov 1 15:04:36 2006 for Gecode by doxygen 1.4.5

nary.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Guido Tack, 2006
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-17 11:46:13 +0200 (Thu, 17 Aug 2006) $ by $Author: tack $
00010  *     $Revision: 3544 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 namespace Gecode { namespace Set { namespace Projection {
00023 
00024   template <bool negated>
00025   forceinline
00026   NaryProjection<negated>::NaryProjection
00027   (Space* home, ViewArray<SetView>& x0, ProjectorSet& ps0)
00028     : Propagator(home,true), x(x0), ps(ps0) {
00029     Support::DynamicArray<int> scope;
00030     ps.scope(scope);
00031     pc.ensure(x.size());
00032     for (int i=x0.size(); i--;) {
00033       pc[i] = scope[i];
00034       if (negated)
00035         pc[i] = ComplementView<SetView>::pc_negateset(pc[i]);
00036       x[i].subscribe(home, this, pc[i]);
00037     }
00038   }
00039 
00040   template <bool negated>
00041   forceinline
00042   NaryProjection<negated>::NaryProjection
00043   (Space* home, bool share, NaryProjection& p)
00044     : Propagator(home,share,p), ps(p.ps) {
00045     x.update(home,share,p.x);
00046     pc.update(share, p.pc);
00047   }
00048 
00049   template <bool negated>
00050   forceinline PropCost
00051   NaryProjection<negated>::cost(void) const {
00052     switch (x.size()) {
00053     case 1: return PC_UNARY_HI;
00054     case 2: return PC_BINARY_HI;
00055     case 3: return PC_TERNARY_HI;
00056     default: return PC_LINEAR_HI;
00057     }
00058   }
00059 
00060   template <bool negated>
00061   size_t
00062   NaryProjection<negated>::dispose(Space* home) {
00063     if (!home->failed()) {
00064       for (int i=x.size(); i--;)
00065         if (pc[i] != PC_SET_ANY + 1)
00066           x[i].cancel(home, this, pc[i]);
00067     }
00068     ps.~ProjectorSet();
00069     pc.~SharedArray();
00070     Propagator::dispose(home);
00071     return sizeof(*this);
00072   }
00073 
00074   template <bool negated>
00075   ExecStatus
00076   NaryProjection<negated>::post(Space* home,
00077                                 ViewArray<SetView>& x, ProjectorSet& ps) {
00078     if (ps.arity() != x.size()-1) {
00079       throw Set::InvalidProjector("");
00080     }
00081     (void) new (home) NaryProjection<negated>(home,x,ps);
00082     return ES_OK;
00083   }
00084 
00085   template <bool negated>
00086   Actor*
00087   NaryProjection<negated>::copy(Space* home, bool share) {
00088     return new (home) NaryProjection<negated>(home,share,*this);
00089   }
00090 
00091   template <bool negated>
00092   ExecStatus
00093   NaryProjection<negated>::propagate(Space* home) {
00094     bool done = true;
00095     for (int i=x.size(); i--;)
00096       if (!x[i].assigned()) {
00097         done = false; break;
00098       }
00099     ExecStatus es = ps.propagate<negated>(home, x);
00100     GECODE_ES_CHECK(es);
00101     return done ? ES_SUBSUMED : es;
00102   }
00103 
00104 }}}
00105 
00106 // STATISTICS: set-prop