channel.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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