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.hh"
00045 #include "gecode/int.hh"
00046
00047 namespace Gecode { namespace Set { namespace Int {
00048
00049 template <class View>
00050 forceinline
00051 MinElement<View>::MinElement(Space* home, View y0, Gecode::Int::IntView y1)
00052 : IntSetPropagator<View,PC_SET_ANY,
00053 Gecode::Int::PC_INT_BND> (home, y0, y1) {}
00054
00055 template <class View>
00056 forceinline ExecStatus
00057 MinElement<View>::post(Space* home, View x0, Gecode::Int::IntView x1) {
00058 GECODE_ME_CHECK(x0.cardMin(home,1));
00059 (void) new (home) MinElement(home,x0,x1);
00060 return ES_OK;
00061 }
00062
00063 template <class View>
00064 forceinline
00065 MinElement<View>::MinElement(Space* home, bool share, MinElement& p)
00066 : IntSetPropagator<View,PC_SET_ANY,
00067 Gecode::Int::PC_INT_BND> (home, share, p) {}
00068
00069 template <class View>
00070 Actor*
00071 MinElement<View>::copy(Space* home, bool share) {
00072 return new (home) MinElement(home,share,*this);
00073 }
00074
00075 template <class View>
00076 Support::Symbol
00077 MinElement<View>::ati(void) {
00078 return Reflection::mangle<View>("Gecode::Set::Int::MinElement");
00079 }
00080
00081 template <class View>
00082 Reflection::ActorSpec
00083 MinElement<View>::spec(const Space* home, Reflection::VarMap& m) const {
00084 return IntSetPropagator<View,PC_SET_ANY,Gecode::Int::PC_INT_BND>
00085 ::spec(home, m, ati());
00086 }
00087
00088 template <class View>
00089 void
00090 MinElement<View>::post(Space* home, Reflection::VarMap& vars,
00091 const Reflection::ActorSpec& spec) {
00092 spec.checkArity(2);
00093 View x0(home, vars, spec[0]);
00094 Gecode::Int::IntView x1(home, vars, spec[1]);
00095 (void) post(home,x0,x1);
00096 }
00097
00098 template <class View>
00099 ExecStatus
00100 MinElement<View>::propagate(Space* home, ModEventDelta) {
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 {
00113 LubRanges<View> ub(x0);
00114 GECODE_ME_CHECK(x1.inter_r(home,ub,false));
00115 }
00116 GECODE_ME_CHECK(x1.lq(home,x0.glbMin()));
00117
00118 assert(x0.cardMin()>=1);
00119
00120 {
00122 int size = 0;
00123 int maxN = BndSet::MAX_OF_EMPTY;
00124 for (LubRanges<View> ubr(x0); ubr(); ++ubr, ++size) {}
00125 GECODE_AUTOARRAY(int, ub, size*2);
00126 int i=0;
00127 for (LubRanges<View> ubr(x0); ubr(); ++ubr, ++i) {
00128 ub[2*i] = ubr.min();
00129 ub[2*i+1] = ubr.max();
00130 }
00131 int x0cm = x0.cardMin()-1;
00132 for (int i=size; i--;) {
00133 int width = ub[2*i+1]-ub[2*i]+1;
00134 if (width > x0cm) {
00135 maxN = ub[2*i+1]-x0cm;
00136 break;
00137 }
00138 x0cm -= width;
00139 }
00140 GECODE_ME_CHECK(x1.lq(home,maxN));
00141 }
00142
00143 GECODE_ME_CHECK( x0.exclude(home,
00144 Limits::min, x1.min()-1) );
00145
00146 if (x1.assigned()) {
00147 GECODE_ME_CHECK(x0.include(home,x1.val()));
00148 GECODE_ME_CHECK(x0.exclude(home,
00149 Limits::min, x1.val()-1));
00150 return ES_SUBSUMED(this,home);
00151 }
00152
00153 return ES_FIX;
00154 }
00155
00156 template <class View>
00157 forceinline
00158 MaxElement<View>::MaxElement(Space* home, View y0, Gecode::Int::IntView y1)
00159 : IntSetPropagator<View,PC_SET_ANY,
00160 Gecode::Int::PC_INT_BND> (home, y0, y1) {}
00161
00162 template <class View>
00163 forceinline
00164 MaxElement<View>::MaxElement(Space* home, bool share, MaxElement& p)
00165 : IntSetPropagator<View,PC_SET_ANY,
00166 Gecode::Int::PC_INT_BND> (home, share, p) {}
00167
00168 template <class View>
00169 ExecStatus
00170 MaxElement<View>::post(Space* home, View x0,
00171 Gecode::Int::IntView x1) {
00172 GECODE_ME_CHECK(x0.cardMin(home,1));
00173 (void) new (home) MaxElement(home,x0,x1);
00174 return ES_OK;
00175 }
00176
00177 template <class View>
00178 Actor*
00179 MaxElement<View>::copy(Space* home, bool share) {
00180 return new (home) MaxElement(home,share,*this);
00181 }
00182
00183 template <class View>
00184 Support::Symbol
00185 MaxElement<View>::ati(void) {
00186 return Reflection::mangle<View>("Gecode::Set::Int::MaxElement");
00187 }
00188
00189 template <class View>
00190 Reflection::ActorSpec
00191 MaxElement<View>::spec(const Space* home, Reflection::VarMap& m) const {
00192 return IntSetPropagator<View,PC_SET_ANY,Gecode::Int::PC_INT_BND>
00193 ::spec(home, m, ati());
00194 }
00195
00196 template <class View>
00197 void
00198 MaxElement<View>::post(Space* home, Reflection::VarMap& vars,
00199 const Reflection::ActorSpec& spec) {
00200 spec.checkArity(2);
00201 View x0(home, vars, spec[0]);
00202 Gecode::Int::IntView x1(home, vars, spec[1]);
00203 (void) new (home) MaxElement<View>(home,x0,x1);
00204 }
00205
00206 template <class View>
00207 ExecStatus
00208 MaxElement<View>::propagate(Space* home, ModEventDelta) {
00209 LubRanges<View> ub(x0);
00210 GECODE_ME_CHECK(x1.inter_r(home,ub,false));
00211 GECODE_ME_CHECK(x1.gq(home,x0.glbMax()));
00212 assert(x0.cardMin()>=1);
00213 GECODE_ME_CHECK(x1.gq(home,x0.lubMinN(x0.cardMin()-1)));
00214 GECODE_ME_CHECK(x0.exclude(home,
00215 x1.max()+1,Limits::max) );
00216
00217 if (x1.assigned()) {
00218 GECODE_ME_CHECK(x0.include(home,x1.val()));
00219 GECODE_ME_CHECK( x0.exclude(home,
00220 x1.val()+1,Limits::max) );
00221 return ES_SUBSUMED(this,home);
00222 }
00223
00224 return ES_FIX;
00225 }
00226 }}}
00227
00228