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

channel.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Contributing authors:
00007  *     Gabor Szokoli <szokoli@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Guido Tack, 2004
00011  *     Christian Schulte, 2004
00012  *     Gabor Szokoli, 2004
00013  *
00014  *  Last modified:
00015  *     $Date: 2006-05-29 09:42:21 +0200 (Mon, 29 May 2006) $ by $Author: schulte $
00016  *     $Revision: 3246 $
00017  *
00018  *  This file is part of Gecode, the generic constraint
00019  *  development environment:
00020  *     http://www.gecode.org
00021  *
00022  *  See the file "LICENSE" for information on usage and
00023  *  redistribution of this file, and for a
00024  *     DISCLAIMER OF ALL WARRANTIES.
00025  *
00026  */
00027 
00028 
00029 
00030 #include "gecode/set/int.hh"
00031 
00032 #include "gecode/iter.hh"
00033 
00034 #include "gecode/set/rel.hh"
00035 
00036 namespace Gecode { namespace Set { namespace Int {
00037 
00038   PropCost
00039   Channel::cost(void) const {
00040     return PC_QUADRATIC_LO;
00041   }
00042 
00043   size_t
00044   Channel::dispose(Space* home) {
00045     assert(!home->failed());
00046     xs.cancel(home,this, Gecode::Int::PC_INT_DOM);
00047     ys.cancel(home,this, PC_SET_ANY);
00048     (void) Propagator::dispose(home);
00049     return sizeof(*this);
00050   }
00051 
00052   Actor*
00053   Channel::copy(Space* home, bool share) {
00054     return new (home) Channel(home,share,*this);
00055   }
00056 
00057   ExecStatus
00058   Channel::propagate(Space* home) {
00059     int assigned = 0;
00060     for (int v=xs.size(); v--;) {
00061       if (xs[v].assigned()) {
00062         assigned += 1;
00063         for (int i=ys.size(); i--;) {
00064           if (i==xs[v].val()) {
00065             GECODE_ME_CHECK(ys[i].include(home, v));
00066           }
00067           else {
00068             GECODE_ME_CHECK(ys[i].exclude(home, v));
00069           }
00070         }
00071       } else {
00072 
00073         for (int i=ys.size(); i--;) {
00074           if (ys[i].notContains(v)) {
00075             GECODE_ME_CHECK(xs[v].nq(home, i));
00076           }
00077           if (ys[i].contains(v)) {
00078             GECODE_ME_CHECK(xs[v].eq(home, i));
00079           }
00080         }
00081 
00082         Gecode::Int::ViewRanges<Gecode::Int::IntView> xsv(xs[v]);
00083         int min = 0;
00084         for (; xsv(); ++xsv) {
00085           for (int i=min; i<xsv.min(); i++) {
00086             GECODE_ME_CHECK(ys[i].exclude(home, v));
00087           }
00088           min = xsv.max() + 1;
00089         }
00090 
00091       }
00092     }
00093 
00094     return (assigned==xs.size()) ? ES_SUBSUMED : ES_NOFIX;
00095   }
00096 
00097 
00098 }}}
00099 
00100 // STATISTICS: set-prop