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 #include <gecode/int/nvalues.hh>
00039 #include <gecode/int/rel.hh>
00040
00041 namespace Gecode {
00042
00043 void
00044 nvalues(Home home, const IntVarArgs& x, IntRelType r, int y,
00045 IntConLevel) {
00046 using namespace Int;
00047 Limits::check(y,"Int::nvalues");
00048
00049 Limits::check(static_cast<double>(x.size())*static_cast<double>(x.size()),
00050 "Int::nvalues");
00051
00052 if (home.failed()) return;
00053
00054 ViewArray<IntView> xv(home,x);
00055
00056 switch (r) {
00057 case IRT_EQ:
00058 {
00059 ConstIntView yv(y);
00060 GECODE_ES_FAIL(NValues::EqInt<ConstIntView>::post(home,xv,yv));
00061 }
00062 break;
00063 case IRT_NQ:
00064 {
00065 IntVar z(home,0,x.size());
00066 GECODE_ME_FAIL(IntView(z).nq(home,y));
00067 GECODE_ES_FAIL(NValues::EqInt<IntView>::post(home,xv,z));
00068 }
00069 break;
00070 case IRT_LE:
00071 y--;
00072
00073 case IRT_LQ:
00074 {
00075 ConstIntView yv(y);
00076 GECODE_ES_FAIL(NValues::LqInt<ConstIntView>::post(home,xv,yv));
00077 }
00078 break;
00079 case IRT_GR:
00080 y++;
00081
00082 case IRT_GQ:
00083 {
00084 ConstIntView yv(y);
00085 GECODE_ES_FAIL(NValues::GqInt<ConstIntView>::post(home,xv,yv));
00086 }
00087 break;
00088 default:
00089 throw UnknownRelation("Int::nvalues");
00090 }
00091 }
00092
00093 void
00094 nvalues(Home home, const IntVarArgs& x, IntRelType r, IntVar y,
00095 IntConLevel) {
00096 using namespace Int;
00097
00098 Limits::check(static_cast<double>(x.size())*static_cast<double>(x.size()),
00099 "Int::nvalues");
00100
00101 if (home.failed()) return;
00102
00103 if (y.assigned()) {
00104 nvalues(home, x, r, y.val());
00105 return;
00106 }
00107
00108 ViewArray<IntView> xv(home,x);
00109
00110 switch (r) {
00111 case IRT_EQ:
00112 GECODE_ES_FAIL(NValues::EqInt<IntView>::post(home,xv,y));
00113 break;
00114 case IRT_NQ:
00115 {
00116 IntVar z(home,0,x.size());
00117 GECODE_ES_FAIL(Rel::Nq<IntView>::post(home,y,z));
00118 GECODE_ES_FAIL(NValues::EqInt<IntView>::post(home,xv,z));
00119 }
00120 break;
00121 case IRT_LE:
00122 {
00123 OffsetView z(y,-1);
00124 GECODE_ES_FAIL(NValues::LqInt<OffsetView>::post(home,xv,z));
00125 }
00126 break;
00127 case IRT_LQ:
00128 GECODE_ES_FAIL(NValues::LqInt<IntView>::post(home,xv,y));
00129 break;
00130 case IRT_GR:
00131 {
00132 OffsetView z(y,1);
00133 GECODE_ES_FAIL(NValues::GqInt<OffsetView>::post(home,xv,z));
00134 }
00135 break;
00136 case IRT_GQ:
00137 GECODE_ES_FAIL(NValues::GqInt<IntView>::post(home,xv,y));
00138 break;
00139 default:
00140 throw UnknownRelation("Int::nvalues");
00141 }
00142 }
00143
00144 void
00145 nvalues(Home home, const BoolVarArgs& x, IntRelType r, int y,
00146 IntConLevel) {
00147 using namespace Int;
00148 Limits::check(y,"Int::nvalues");
00149
00150 if (home.failed()) return;
00151
00152 Region region(home);
00153 ViewArray<BoolView> xv(region,x);
00154
00155 switch (r) {
00156 case IRT_EQ:
00157 {
00158 ConstIntView yv(y);
00159 GECODE_ES_FAIL(NValues::EqBool<ConstIntView>::post(home,xv,yv));
00160 }
00161 break;
00162 case IRT_NQ:
00163 {
00164 IntVar z(home,0,2);
00165 GECODE_ME_FAIL(IntView(z).nq(home,y));
00166 GECODE_ES_FAIL(NValues::EqBool<IntView>::post(home,xv,z));
00167 }
00168 break;
00169 case IRT_LE:
00170 y--;
00171
00172 case IRT_LQ:
00173 {
00174 ConstIntView yv(y);
00175 GECODE_ES_FAIL(NValues::LqBool<ConstIntView>::post(home,xv,yv));
00176 }
00177 break;
00178 case IRT_GR:
00179 y++;
00180
00181 case IRT_GQ:
00182 {
00183 ConstIntView yv(y);
00184 GECODE_ES_FAIL(NValues::GqBool<ConstIntView>::post(home,xv,yv));
00185 }
00186 break;
00187 default:
00188 throw UnknownRelation("Int::nvalues");
00189 }
00190 }
00191
00192 void
00193 nvalues(Home home, const BoolVarArgs& x, IntRelType r, IntVar y,
00194 IntConLevel) {
00195 using namespace Int;
00196
00197 if (home.failed()) return;
00198
00199 if (y.assigned()) {
00200 nvalues(home, x, r, y.val());
00201 return;
00202 }
00203
00204 Region region(home);
00205 ViewArray<BoolView> xv(region,x);
00206
00207 switch (r) {
00208 case IRT_EQ:
00209 GECODE_ES_FAIL(NValues::EqBool<IntView>::post(home,xv,y));
00210 break;
00211 case IRT_NQ:
00212 {
00213 IntVar z(home,0,2);
00214 GECODE_ES_FAIL(Rel::Nq<IntView>::post(home,y,z));
00215 GECODE_ES_FAIL(NValues::EqBool<IntView>::post(home,xv,z));
00216 }
00217 break;
00218 case IRT_LE:
00219 {
00220 OffsetView z(y,-1);
00221 GECODE_ES_FAIL(NValues::LqBool<OffsetView>::post(home,xv,z));
00222 }
00223 break;
00224 case IRT_LQ:
00225 GECODE_ES_FAIL(NValues::LqBool<IntView>::post(home,xv,y));
00226 break;
00227 case IRT_GR:
00228 {
00229 OffsetView z(y,1);
00230 GECODE_ES_FAIL(NValues::GqBool<OffsetView>::post(home,xv,z));
00231 }
00232 break;
00233 case IRT_GQ:
00234 GECODE_ES_FAIL(NValues::GqBool<IntView>::post(home,xv,y));
00235 break;
00236 default:
00237 throw UnknownRelation("Int::nvalues");
00238 }
00239 }
00240
00241 }
00242
00243
00244