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

card.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-01-29 13:37:51 +0100 (Tue, 29 Jan 2008) $ by $Author: tack $
00011  *     $Revision: 5993 $
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   forceinline
00041   CardProjection::CardProjection
00042   (Space* home, ViewArray<SetView>& x0, Gecode::Int::IntView i0, Projector& p0)
00043     : Propagator(home), x(x0), i(i0), pc(x.size()), proj(p0) {
00044     force(home);
00045     Support::DynamicArray<int> scope;
00046     for (int i=x0.size(); i--;)
00047       scope[i] = PC_SET_ANY + 1;
00048     p0.scope(scope);
00049     for (int i=x0.size(); i--;) {
00050       pc[i] = scope[i];
00051       if (pc[i] != PC_SET_ANY + 1)
00052         x[i].subscribe(home, this, pc[i]);
00053     }
00054   }
00055 
00056   forceinline
00057   CardProjection::CardProjection
00058   (Space* home, bool share, CardProjection& p)
00059     : Propagator(home,share,p), proj(p.proj) {
00060     x.update(home,share,p.x);
00061     i.update(home,share,p.i);
00062     pc.update(home,share, p.pc);
00063   }
00064 
00065   forceinline PropCost
00066   CardProjection::cost(ModEventDelta) const {
00067     switch (x.size()) {
00068     case 1: return PC_UNARY_HI;
00069     case 2: return PC_BINARY_HI;
00070     case 3: return PC_TERNARY_HI;
00071     default: return PC_LINEAR_HI;
00072     }
00073   }
00074 
00075   inline Support::Symbol
00076   CardProjection::ati(void) {
00077     return Support::Symbol("set.projectors.CardProjection");
00078   }
00079 
00080   forceinline Reflection::ActorSpec
00081   CardProjection::spec(const Space*, Reflection::VarMap&) const {
00082     throw Reflection::ReflectionException("Not implemented");
00083   }
00084 
00085   inline size_t
00086   CardProjection::dispose(Space* home) {
00087     unforce(home);
00088     if (!home->failed()) {
00089       for (int i=x.size(); i--;)
00090         if (pc[i] != PC_SET_ANY + 1)
00091           x[i].cancel(home, this, pc[i]);
00092     }
00093     proj.~Projector();
00094     pc.~SharedArray();
00095     (void) Propagator::dispose(home);
00096     return sizeof(*this);
00097   }
00098 
00099   inline ExecStatus
00100   CardProjection::post(Space* home,
00101                        ViewArray<SetView>& x, Gecode::Int::IntView i,
00102                        Projector& p) {
00103     (void) new (home) CardProjection(home,x,i,p);
00104     return ES_OK;
00105   }
00106 
00107   inline Actor*
00108   CardProjection::copy(Space* home, bool share) {
00109     return new (home) CardProjection(home,share,*this);
00110   }
00111 
00112   inline ExecStatus
00113   CardProjection::propagate(Space* home, ModEventDelta) {
00114     bool done = true;
00115     for (int j=x.size(); j--;)
00116       if (pc[j] != PC_SET_ANY + 1)
00117         done = done && x[j].assigned();
00118     
00119     {
00120       GECODE_ME_CHECK(i.gq(home, static_cast<int>(proj.glbSize(x))));
00121       GECODE_ME_CHECK(i.lq(home, static_cast<int>(proj.lubSize(x))));
00122     }
00123     return done ? ES_SUBSUMED(this,home) : ES_FIX;
00124   }
00125 
00126 }}}
00127 
00128 // STATISTICS: set-prop