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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "gecode/set/sequence.hh"
00045
00046 namespace Gecode { namespace Set { namespace Sequence {
00047
00048
00049
00050
00051
00052
00053 Actor*
00054 SeqU::copy(Space* home, bool share) {
00055 return new (home) SeqU(home,share,*this);
00056 }
00057
00058 Support::Symbol
00059 SeqU::ati(void) {
00060 return Support::Symbol("Gecode::Set::Sequence::Union");
00061 }
00062
00063 Reflection::ActorSpec
00064 SeqU::spec(const Space* home, Reflection::VarMap& m) const {
00065 Reflection::ActorSpec s =
00066 NaryOnePropagator<SetView,PC_SET_ANY>::spec(home, m, ati());
00067 int count = 0;
00068 for (BndSetRanges uod(unionOfDets); uod(); ++uod)
00069 count++;
00070 Reflection::IntArrayArg* a = Reflection::Arg::newIntArray(count*2);
00071 count = 0;
00072 for (BndSetRanges uod(unionOfDets); uod(); ++uod) {
00073 (*a)[count++] = uod.min();
00074 (*a)[count++] = uod.max();
00075 }
00076 return s << a;
00077 }
00078
00079 void
00080 SeqU::post(Space* home, Reflection::VarMap& vars,
00081 const Reflection::ActorSpec& spec) {
00082 spec.checkArity(3);
00083 ViewArray<SetView> x0(home, vars, spec[0]);
00084 SetView x1(home, vars, spec[1]);
00085 Reflection::IntArrayArgRanges r(spec[2]->toIntArray());
00086 SeqU* sequprop = new (home) SeqU(home, x0, x1);
00087 sequprop->unionOfDets.includeI(home, r);
00088 }
00089
00090 ExecStatus
00091 SeqU::propagateSeqUnion(Space* home,
00092 bool& modified, ViewArray<SetView>& x,
00093 SetView& y) {
00094 GECODE_AUTOARRAY(GlbRanges<SetView>, XLBs,x.size());
00095 for (int i=x.size(); i--; ){
00096 GlbRanges<SetView> lb(x[i]);
00097 XLBs[i]=lb;
00098 }
00099 Iter::Ranges::NaryAppend<GlbRanges<SetView> > u(XLBs,x.size());
00100 GECODE_ME_CHECK_MODIFIED(modified, y.includeI(home,u));
00101
00102 GLBndSet before(home);
00103 for (int i=0; i<x.size(); i++) {
00104 LubRanges<SetView> xiub(x[i]);
00105 before.includeI(home, xiub);
00106 BndSetRanges beforeR(before);
00107 GlbRanges<SetView> ylb(y);
00108 Iter::Ranges::Diff<GlbRanges<SetView>, BndSetRanges> diff(ylb, beforeR);
00109 if (diff()) {
00110 GECODE_ME_CHECK_MODIFIED(modified, x[i].exclude(home, diff.min(),
00111 Limits::max));
00112 }
00113 }
00114 before.dispose(home);
00115
00116 GLBndSet after(home);
00117 for (int i=x.size(); i--; ) {
00118 LubRanges<SetView> xiub(x[i]);
00119 after.includeI(home, xiub);
00120 BndSetRanges afterR(after);
00121 GlbRanges<SetView> ylb(y);
00122 Iter::Ranges::Diff<GlbRanges<SetView>, BndSetRanges> diff(ylb, afterR);
00123 if (diff()) {
00124 int max = diff.max();
00125 for (; diff(); ++diff)
00126 max = diff.max();
00127 GECODE_ME_CHECK_MODIFIED(modified, x[i].exclude(home,
00128 Limits::min,
00129 max));
00130 }
00131 }
00132 after.dispose(home);
00133
00134 return ES_FIX;
00135 }
00136
00137
00138 ExecStatus
00139 SeqU::propagate(Space* home, ModEventDelta med) {
00140 ModEvent me0 = SetView::me(med);
00141 bool ubevent = Rel::testSetEventUB(me0);
00142 bool anybevent = Rel::testSetEventAnyB(me0);
00143 bool cardevent = Rel::testSetEventCard(me0);
00144
00145 bool modified = false;
00146 bool assigned=false;
00147 bool oldModified = false;
00148
00149 do {
00150 oldModified = modified;
00151 modified = false;
00152
00153 if (oldModified || modified || anybevent || cardevent)
00154 GECODE_ME_CHECK(propagateSeq(home,modified,assigned,x));
00155 if (oldModified || modified || anybevent)
00156 GECODE_ME_CHECK(propagateSeqUnion(home,modified,x,y));
00157 if (oldModified || modified || ubevent)
00158 GECODE_ME_CHECK(RelOp::unionNXiUB(home,modified,x,y,unionOfDets));
00159 if (oldModified || modified || ubevent)
00160 GECODE_ME_CHECK(RelOp::partitionNYUB(home,modified,x,y,unionOfDets));
00161 if (oldModified || modified || anybevent)
00162 GECODE_ME_CHECK(RelOp::partitionNXiLB(home,modified,x,y,unionOfDets));
00163 if (oldModified || modified || cardevent || ubevent)
00164 GECODE_ME_CHECK(RelOp::partitionNCard(home,modified,x,y,unionOfDets));
00165
00166 } while (modified);
00167
00168 for (int i=x.size(); i--;)
00169 if (!x[i].assigned())
00170 return ES_FIX;
00171 return ES_SUBSUMED(this,home);
00172 }
00173
00174 }}}
00175
00176