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

card.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   forceinline
00025   CardProjection::CardProjection
00026   (Space* home, ViewArray<SetView>& x0, Gecode::Int::IntView i0, Projector& p0)
00027     : Propagator(home,true), x(x0), i(i0), proj(p0) {
00028     Support::DynamicArray<int> scope;
00029     p0.scope(scope);
00030     pc.ensure(x.size());
00031     for (int i=x0.size(); i--;) {
00032       pc[i] = scope[i];
00033       x[i].subscribe(home, this, pc[i]);
00034     }
00035   }
00036 
00037   forceinline
00038   CardProjection::CardProjection
00039   (Space* home, bool share, CardProjection& p)
00040     : Propagator(home,share,p), proj(p.proj) {
00041     x.update(home,share,p.x);
00042     i.update(home,share,p.i);
00043     pc.update(share, p.pc);
00044   }
00045 
00046   forceinline PropCost
00047   CardProjection::cost(void) const {
00048     switch (x.size()) {
00049     case 1: return PC_UNARY_HI;
00050     case 2: return PC_BINARY_HI;
00051     case 3: return PC_TERNARY_HI;
00052     default: return PC_LINEAR_HI;
00053     }
00054   }
00055 
00056   inline size_t
00057   CardProjection::dispose(Space* home) {
00058     if (!home->failed()) {
00059       for (int i=x.size(); i--;)
00060         if (pc[i] != PC_SET_ANY + 1)
00061           x[i].cancel(home, this, pc[i]);
00062     }
00063     proj.~Projector();
00064     pc.~SharedArray();
00065     Propagator::dispose(home);
00066     return sizeof(*this);
00067   }
00068 
00069   inline ExecStatus
00070   CardProjection::post(Space* home,
00071                        ViewArray<SetView>& x, Gecode::Int::IntView i,
00072                        Projector& p) {
00073     (void) new (home) CardProjection(home,x,i,p);
00074     return ES_OK;
00075   }
00076 
00077   inline Actor*
00078   CardProjection::copy(Space* home, bool share) {
00079     return new (home) CardProjection(home,share,*this);
00080   }
00081 
00082   inline ExecStatus
00083   CardProjection::propagate(Space* home) {
00084     bool done = true;
00085     for (int j=x.size(); j--;)
00086       if (pc[j] != PC_SET_ANY + 1)
00087         done = done && x[j].assigned();
00088     
00089     {
00090       GECODE_ME_CHECK(i.gq(home, static_cast<int>(proj.glbSize(x))));
00091       GECODE_ME_CHECK(i.lq(home, static_cast<int>(proj.lubSize(x))));
00092     }
00093     return done ? ES_SUBSUMED : ES_FIX;
00094   }
00095 
00096 }}}