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 #include "gecode/set.hh"
00042 #include "gecode/set/rel.hh"
00043
00044 namespace Gecode {
00045
00046 void
00047 dom(Space* home, SetVar s, SetRelType r, int i) {
00048 Set::Limits::check(i, "Set::dom");
00049 IntSet d(i,i);
00050 dom(home, s, r, d);
00051 }
00052
00053 void
00054 dom(Space* home, SetVar s, SetRelType r, int i, int j) {
00055 Set::Limits::check(i, "Set::dom");
00056 Set::Limits::check(j, "Set::dom");
00057 IntSet d(i,j);
00058 dom(home, s, r, d);
00059 }
00060
00061 void
00062 dom(Space* home, SetVar s, SetRelType r, const IntSet& is) {
00063 Set::Limits::check(is, "Set::dom");
00064 if (home->failed()) return;
00065
00066 Set::SetView _s(s);
00067
00068 switch(r) {
00069 case SRT_EQ:
00070 {
00071 if (is.size() == 1) {
00072 GECODE_ME_FAIL(home,_s.include(home, is.min(), is.max()));
00073 GECODE_ME_FAIL(home,_s.intersect(home, is.min(), is.max()));
00074 } else {
00075 IntSetRanges rd1(is);
00076 GECODE_ME_FAIL(home,_s.includeI(home, rd1));
00077 IntSetRanges rd2(is);
00078 GECODE_ME_FAIL(home,_s.intersectI(home, rd2));
00079 }
00080 }
00081 break;
00082 case SRT_DISJ:
00083 {
00084 if (is.size() == 1) {
00085 GECODE_ME_FAIL(home,_s.exclude(home, is.min(), is.max()));
00086 } else {
00087 IntSetRanges rd(is);
00088 GECODE_ME_FAIL(home,_s.excludeI(home, rd));
00089 }
00090 }
00091 break;
00092 case SRT_NQ:
00093 {
00094 Set::ConstantView cv(home, is);
00095 GECODE_ES_FAIL(home,
00096 (Set::Rel::DistinctDoit<Set::SetView>::post(home, s,
00097 cv)));
00098 }
00099 break;
00100 case SRT_SUB:
00101 {
00102 if (is.size() == 1) {
00103 GECODE_ME_FAIL(home,_s.intersect(home, is.min(), is.max()));
00104 } else {
00105 IntSetRanges rd(is);
00106 GECODE_ME_FAIL(home,_s.intersectI(home, rd));
00107 }
00108 }
00109 break;
00110 case SRT_SUP:
00111 {
00112 if (is.size() == 1) {
00113 GECODE_ME_FAIL(home,_s.include(home, is.min(), is.max()));
00114 } else {
00115 IntSetRanges rd(is);
00116 GECODE_ME_FAIL(home,_s.includeI(home, rd));
00117 }
00118 }
00119 break;
00120 case SRT_CMPL:
00121 {
00122 if (is.size() == 1) {
00123 GECODE_ME_FAIL(home,_s.exclude(home, is.min(), is.max()));
00124 GECODE_ME_FAIL(home,
00125 _s.include(home,
00126 Set::Limits::min,
00127 is.min()-1) );
00128 GECODE_ME_FAIL(home,
00129 _s.include(home, is.max()+1,
00130 Set::Limits::max) );
00131 } else {
00132 IntSetRanges rd1(is);
00133 Set::RangesCompl<IntSetRanges > rdC1(rd1);
00134 GECODE_ME_FAIL(home,_s.includeI(home, rdC1));
00135 IntSetRanges rd2(is);
00136 Set::RangesCompl<IntSetRanges > rdC2(rd2);
00137 GECODE_ME_FAIL(home,_s.intersectI(home, rdC2));
00138 }
00139 }
00140 break;
00141 }
00142 }
00143
00144 void
00145 dom(Space* home, SetVar s, SetRelType r, int i, BoolVar b) {
00146 Set::Limits::check(i, "Set::dom");
00147 IntSet d(i,i);
00148 dom(home, s, r, d, b);
00149 }
00150
00151 void
00152 dom(Space* home, SetVar s, SetRelType r, int i, int j, BoolVar b) {
00153 Set::Limits::check(i, "Set::dom");
00154 Set::Limits::check(j, "Set::dom");
00155 IntSet d(i,j);
00156 dom(home, s, r, d, b);
00157 }
00158
00159 void
00160 dom(Space* home, SetVar s, SetRelType r, const IntSet& is, BoolVar b) {
00161 Set::Limits::check(is, "Set::dom");
00162 if (home->failed()) return;
00163 switch(r) {
00164 case SRT_EQ:
00165 {
00166 Set::ConstantView cv(home, is);
00167 GECODE_ES_FAIL(home,
00168 (Set::Rel::ReEq<Set::SetView,
00169 Set::ConstantView>::post(home, s, cv, b)));
00170 }
00171 break;
00172 case SRT_NQ:
00173 {
00174 BoolVar notb(home,0,1);
00175 rel(home, b, IRT_NQ, notb);
00176 Set::ConstantView cv(home, is);
00177 GECODE_ES_FAIL(home,
00178 (Set::Rel::ReEq<Set::SetView,
00179 Set::ConstantView>::post(home, s, cv, notb)));
00180 }
00181 break;
00182 case SRT_SUB:
00183 {
00184 Set::ConstantView cv(home, is);
00185 GECODE_ES_FAIL(home,
00186 (Set::Rel::ReSubset<Set::SetView,Set::ConstantView>
00187 ::post(home, s, cv, b)));
00188 }
00189 break;
00190 case SRT_SUP:
00191 {
00192 Set::ConstantView cv(home, is);
00193 GECODE_ES_FAIL(home,
00194 (Set::Rel::ReSubset<Set::ConstantView,Set::SetView>
00195 ::post(home, cv, s, b)));
00196 }
00197 break;
00198 case SRT_DISJ:
00199 {
00200
00201
00202
00203
00204 IntSetRanges dr1(is);
00205 Set::RangesCompl<IntSetRanges > dc1(dr1);
00206 IntSet dcompl(dc1);
00207 Set::ConstantView cvcompl(home, dcompl);
00208 GECODE_ES_FAIL(home,
00209 (Set::Rel::ReSubset<Set::SetView,Set::ConstantView>
00210 ::post(home, s, cvcompl, b)));
00211 }
00212 break;
00213 case SRT_CMPL:
00214 {
00215 Set::SetView sv(s);
00216
00217 IntSetRanges dr1(is);
00218 Set::RangesCompl<IntSetRanges> dc1(dr1);
00219 IntSet dcompl(dc1);
00220 Set::ConstantView cvcompl(home, dcompl);
00221
00222 GECODE_ES_FAIL(home,
00223 (Set::Rel::ReEq<Set::SetView,Set::ConstantView>
00224 ::post(home, sv, cvcompl, b)));
00225 }
00226 break;
00227 }
00228 }
00229
00230 }
00231
00232