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