Generated on Fri Oct 19 11:25:07 2018 for Gecode by doxygen 1.6.3

int-post.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2002
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <algorithm>
00035 
00036 #include <gecode/int/rel.hh>
00037 #include <gecode/int/linear.hh>
00038 #include <gecode/int/div.hh>
00039 
00040 namespace Gecode { namespace Int { namespace Linear {
00041 
00043   forceinline void
00044   eliminate(Term<IntView>* t, int &n, long long int& d) {
00045     for (int i=n; i--; )
00046       if (t[i].x.assigned()) {
00047         long long int ax = t[i].a * static_cast<long long int>(t[i].x.val());
00048         if (Limits::overflow_sub(d,ax))
00049           throw OutOfLimits("Int::linear");
00050         d=d-ax; t[i]=t[--n];
00051       }
00052   }
00053 
00055   forceinline void
00056   rewrite(IntRelType &irt, long long int &d,
00057           Term<IntView>* &t_p, int &n_p,
00058           Term<IntView>* &t_n, int &n_n) {
00059     switch (irt) {
00060     case IRT_EQ: case IRT_NQ: case IRT_LQ:
00061       break;
00062     case IRT_LE:
00063       d--; irt = IRT_LQ;
00064       break;
00065     case IRT_GR:
00066       d++;
00067       /* fall through */
00068     case IRT_GQ:
00069       irt = IRT_LQ;
00070       std::swap(n_p,n_n); std::swap(t_p,t_n); d = -d;
00071       break;
00072     default:
00073       throw UnknownRelation("Int::linear");
00074     }
00075   }
00076 
00078   forceinline bool
00079   precision(Term<IntView>* t_p, int n_p,
00080             Term<IntView>* t_n, int n_n,
00081             long long int d) {
00082     long long int sl = 0;
00083     long long int su = 0;
00084 
00085     for (int i=0; i<n_p; i++) {
00086       long long int axmin =
00087         t_p[i].a * static_cast<long long int>(t_p[i].x.min());
00088       if (Limits::overflow_add(sl,axmin))
00089         throw OutOfLimits("Int::linear");
00090       sl = sl + axmin;
00091       long long int axmax =
00092         t_p[i].a * static_cast<long long int>(t_p[i].x.max());
00093       if (Limits::overflow_add(sl,axmax))
00094         throw OutOfLimits("Int::linear");
00095       su = su + axmax;
00096     }
00097     for (int i=0; i<n_n; i++) {
00098       long long int axmax =
00099         t_n[i].a * static_cast<long long int>(t_n[i].x.max());
00100       if (Limits::overflow_sub(sl,axmax))
00101         throw OutOfLimits("Int::linear");
00102       sl = sl - axmax;
00103       long long int axmin =
00104         t_n[i].a * static_cast<long long int>(t_n[i].x.min());
00105       if (Limits::overflow_sub(su,axmin))
00106         throw OutOfLimits("Int::linear");
00107       su = su - axmin;
00108     }
00109 
00110     bool is_ip = (sl >= Limits::min) && (su <= Limits::max);
00111 
00112     if (Limits::overflow_sub(sl,d))
00113       throw OutOfLimits("Int::linear");
00114     sl = sl - d;
00115     if (Limits::overflow_sub(su,d))
00116       throw OutOfLimits("Int::linear");
00117     su = su - d;
00118 
00119     is_ip = is_ip && (sl >= Limits::min) && (su <= Limits::max);
00120 
00121     for (int i=0; i<n_p; i++) {
00122       long long int axmin =
00123         t_p[i].a * static_cast<long long int>(t_p[i].x.min());
00124       if (Limits::overflow_sub(sl,axmin))
00125         throw OutOfLimits("Int::linear");
00126       if (sl - axmin < Limits::min)
00127         is_ip = false;
00128       long long int axmax =
00129         t_p[i].a * static_cast<long long int>(t_p[i].x.max());
00130       if (Limits::overflow_sub(su,axmax))
00131         throw OutOfLimits("Int::linear");
00132       if (su - axmax > Limits::max)
00133         is_ip = false;
00134     }
00135     for (int i=0; i<n_n; i++) {
00136       long long int axmin =
00137         t_n[i].a * static_cast<long long int>(t_n[i].x.min());
00138       if (Limits::overflow_add(sl,axmin))
00139         throw OutOfLimits("Int::linear");
00140       if (sl + axmin < Limits::min)
00141         is_ip = false;
00142       long long int axmax =
00143         t_n[i].a * static_cast<long long int>(t_n[i].x.max());
00144       if (Limits::overflow_add(su,axmax))
00145         throw OutOfLimits("Int::linear");
00146       if (su + axmax > Limits::max)
00147         is_ip = false;
00148     }
00149     return is_ip;
00150   }
00151 
00156   template<class Val, class View>
00157   forceinline void
00158   post_nary(Home home,
00159             ViewArray<View>& x, ViewArray<View>& y, IntRelType irt, Val c) {
00160     switch (irt) {
00161     case IRT_EQ:
00162       GECODE_ES_FAIL((Eq<Val,View,View >::post(home,x,y,c)));
00163       break;
00164     case IRT_NQ:
00165       GECODE_ES_FAIL((Nq<Val,View,View >::post(home,x,y,c)));
00166       break;
00167     case IRT_LQ:
00168       GECODE_ES_FAIL((Lq<Val,View,View >::post(home,x,y,c)));
00169       break;
00170     default: GECODE_NEVER;
00171     }
00172   }
00173 
00174 
00176 #define GECODE_INT_PL_BIN(CLASS)                                             \
00177   switch (n_p) {                                                             \
00178   case 2:                                                                    \
00179     GECODE_ES_FAIL((CLASS<int,IntView,IntView>::post                         \
00180                          (home,t_p[0].x,t_p[1].x,c)));                       \
00181     break;                                                                   \
00182   case 1:                                                                    \
00183     GECODE_ES_FAIL((CLASS<int,IntView,MinusView>::post                       \
00184                          (home,t_p[0].x,MinusView(t_n[0].x),c)));            \
00185     break;                                                                   \
00186   case 0:                                                                    \
00187     GECODE_ES_FAIL((CLASS<int,MinusView,MinusView>::post                     \
00188                          (home,MinusView(t_n[0].x),MinusView(t_n[1].x),c))); \
00189     break;                                                                   \
00190   default: GECODE_NEVER;                                                     \
00191   }
00192 
00194 #define GECODE_INT_PL_TER(CLASS)                                        \
00195   switch (n_p) {                                                        \
00196   case 3:                                                               \
00197     GECODE_ES_FAIL((CLASS<int,IntView,IntView,IntView>::post            \
00198                          (home,t_p[0].x,t_p[1].x,t_p[2].x,c)));         \
00199     break;                                                              \
00200   case 2:                                                               \
00201     GECODE_ES_FAIL((CLASS<int,IntView,IntView,MinusView>::post          \
00202                          (home,t_p[0].x,t_p[1].x,                       \
00203                           MinusView(t_n[0].x),c)));                     \
00204     break;                                                              \
00205   case 1:                                                               \
00206     GECODE_ES_FAIL((CLASS<int,IntView,MinusView,MinusView>::post        \
00207                          (home,t_p[0].x,                                \
00208                           MinusView(t_n[0].x),MinusView(t_n[1].x),c))); \
00209     break;                                                              \
00210   case 0:                                                               \
00211     GECODE_ES_FAIL((CLASS<int,MinusView,MinusView,MinusView>::post      \
00212                          (home,MinusView(t_n[0].x),                     \
00213                           MinusView(t_n[1].x),MinusView(t_n[2].x),c))); \
00214     break;                                                              \
00215   default: GECODE_NEVER;                                                \
00216   }
00217 
00218   void
00219   post(Home home, Term<IntView>* t, int n, IntRelType irt, int c,
00220        IntPropLevel ipl) {
00221 
00222     Limits::check(c,"Int::linear");
00223 
00224     long long int d = c;
00225 
00226     eliminate(t,n,d);
00227 
00228     Term<IntView> *t_p, *t_n;
00229     int n_p, n_n, gcd=1;
00230     bool is_unit = normalize<IntView>(t,n,t_p,n_p,t_n,n_n,gcd);
00231 
00232     rewrite(irt,d,t_p,n_p,t_n,n_n);
00233 
00234     // Divide by gcd
00235     if (gcd > 1) {
00236       switch (irt) {
00237       case IRT_EQ:
00238         if ((d % gcd) != 0) {
00239           home.fail();
00240           return;
00241         }
00242         d /= gcd;
00243         break;
00244       case IRT_NQ:
00245         if ((d % gcd) != 0)
00246           return;
00247         d /= gcd;
00248         break;
00249       case IRT_LQ:
00250         d = floor_div_xp(d,static_cast<long long int>(gcd));
00251         break;
00252       default: GECODE_NEVER;
00253       }
00254     }
00255 
00256     if (n == 0) {
00257       switch (irt) {
00258       case IRT_EQ: if (d != 0) home.fail(); break;
00259       case IRT_NQ: if (d == 0) home.fail(); break;
00260       case IRT_LQ: if (d < 0)  home.fail(); break;
00261       default: GECODE_NEVER;
00262       }
00263       return;
00264     }
00265 
00266     if (n == 1) {
00267       if (n_p == 1) {
00268         LLongScaleView y(t_p[0].a,t_p[0].x);
00269         switch (irt) {
00270         case IRT_EQ: GECODE_ME_FAIL(y.eq(home,d)); break;
00271         case IRT_NQ: GECODE_ME_FAIL(y.nq(home,d)); break;
00272         case IRT_LQ: GECODE_ME_FAIL(y.lq(home,d)); break;
00273         default: GECODE_NEVER;
00274         }
00275       } else {
00276         LLongScaleView y(t_n[0].a,t_n[0].x);
00277         switch (irt) {
00278         case IRT_EQ: GECODE_ME_FAIL(y.eq(home,-d)); break;
00279         case IRT_NQ: GECODE_ME_FAIL(y.nq(home,-d)); break;
00280         case IRT_LQ: GECODE_ME_FAIL(y.gq(home,-d)); break;
00281         default: GECODE_NEVER;
00282         }
00283       }
00284       return;
00285     }
00286 
00287     // Check this special case here, as there can be no overflow
00288     if ((n == 2) && is_unit &&
00289         ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) &&
00290         (irt == IRT_EQ) && (d == 0)) {
00291       switch (n_p) {
00292       case 2: {
00293         IntView x(t_p[0].x);
00294         MinusView y(t_p[1].x);
00295         GECODE_ES_FAIL((Rel::EqDom<IntView,MinusView>::post(home,x,y)));
00296         break;
00297       }
00298       case 1: {
00299         IntView x(t_p[0].x);
00300         IntView y(t_n[0].x);
00301         GECODE_ES_FAIL((Rel::EqDom<IntView,IntView>::post(home,x,y)));
00302         break;
00303       }
00304       case 0: {
00305         IntView x(t_n[0].x);
00306         MinusView y(t_n[1].x);
00307         GECODE_ES_FAIL((Rel::EqDom<IntView,MinusView>::post(home,x,y)));
00308         break;
00309       }
00310       default:
00311         GECODE_NEVER;
00312       }
00313       return;
00314     }
00315 
00316     bool is_ip = precision(t_p,n_p,t_n,n_n,d);
00317 
00318     if (is_unit && is_ip &&
00319         (vbd(ipl) != IPL_DOM) && (vbd(ipl) != IPL_DEF)) {
00320       // Unit coefficients with integer precision
00321       c = static_cast<int>(d);
00322       if (n == 2) {
00323         switch (irt) {
00324         case IRT_EQ: GECODE_INT_PL_BIN(EqBin); break;
00325         case IRT_NQ: GECODE_INT_PL_BIN(NqBin); break;
00326         case IRT_LQ: GECODE_INT_PL_BIN(LqBin); break;
00327         default: GECODE_NEVER;
00328         }
00329       } else if (n == 3) {
00330         switch (irt) {
00331         case IRT_EQ: GECODE_INT_PL_TER(EqTer); break;
00332         case IRT_NQ: GECODE_INT_PL_TER(NqTer); break;
00333         case IRT_LQ: GECODE_INT_PL_TER(LqTer); break;
00334         default: GECODE_NEVER;
00335         }
00336       } else {
00337         ViewArray<IntView> x(home,n_p);
00338         for (int i=0; i<n_p; i++)
00339           x[i] = t_p[i].x;
00340         ViewArray<IntView> y(home,n_n);
00341         for (int i=0; i<n_n; i++)
00342           y[i] = t_n[i].x;
00343         post_nary<int,IntView>(home,x,y,irt,c);
00344       }
00345     } else if (is_ip) {
00346       if ((n==2) && is_unit &&
00347           ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) &&
00348           (irt == IRT_EQ)) {
00349         // Binary domain-consistent equality
00350         c = static_cast<int>(d);
00351         assert(c != 0);
00352         switch (n_p) {
00353         case 2: {
00354           MinusView x(t_p[0].x);
00355           OffsetView y(t_p[1].x, -c);
00356           GECODE_ES_FAIL((Rel::EqDom<MinusView,OffsetView>::post(home,x,y)));
00357           break;
00358         }
00359         case 1: {
00360           IntView x(t_p[0].x);
00361           OffsetView y(t_n[0].x, c);
00362           GECODE_ES_FAIL((Rel::EqDom<IntView,OffsetView>::post(home,x,y)));
00363           break;
00364         }
00365         case 0: {
00366           MinusView x(t_n[0].x);
00367           OffsetView y(t_n[1].x, c);
00368           GECODE_ES_FAIL((Rel::EqDom<MinusView,OffsetView>::post(home,x,y)));
00369           break;
00370         }
00371         default:
00372           GECODE_NEVER;
00373         }
00374       } else {
00375         // Arbitrary coefficients with integer precision
00376         c = static_cast<int>(d);
00377         ViewArray<IntScaleView> x(home,n_p);
00378         for (int i=0; i<n_p; i++)
00379           x[i] = IntScaleView(t_p[i].a,t_p[i].x);
00380         ViewArray<IntScaleView> y(home,n_n);
00381         for (int i=0; i<n_n; i++)
00382           y[i] = IntScaleView(t_n[i].a,t_n[i].x);
00383         if ((vbd(ipl) == IPL_DOM) && (irt == IRT_EQ)) {
00384           GECODE_ES_FAIL((DomEq<int,IntScaleView>::post(home,x,y,c)));
00385         } else {
00386           post_nary<int,IntScaleView>(home,x,y,irt,c);
00387         }
00388       }
00389     } else {
00390       // Arbitrary coefficients with long long precision
00391       ViewArray<LLongScaleView> x(home,n_p);
00392       for (int i=0; i<n_p; i++)
00393         x[i] = LLongScaleView(t_p[i].a,t_p[i].x);
00394       ViewArray<LLongScaleView> y(home,n_n);
00395       for (int i=0; i<n_n; i++)
00396         y[i] = LLongScaleView(t_n[i].a,t_n[i].x);
00397       if ((vbd(ipl) == IPL_DOM) && (irt == IRT_EQ)) {
00398         GECODE_ES_FAIL((DomEq<long long int,LLongScaleView>
00399                         ::post(home,x,y,d)));
00400       } else {
00401         post_nary<long long int,LLongScaleView>(home,x,y,irt,d);
00402       }
00403     }
00404   }
00405 
00406 #undef GECODE_INT_PL_BIN
00407 #undef GECODE_INT_PL_TER
00408 
00409 
00414   template<class Val, class View>
00415   forceinline void
00416   post_nary(Home home,
00417             ViewArray<View>& x, ViewArray<View>& y,
00418             IntRelType irt, Val c, Reify r) {
00419     switch (irt) {
00420     case IRT_EQ:
00421       switch (r.mode()) {
00422       case RM_EQV:
00423         GECODE_ES_FAIL((ReEq<Val,View,View,BoolView,RM_EQV>::
00424                         post(home,x,y,c,r.var())));
00425         break;
00426       case RM_IMP:
00427         GECODE_ES_FAIL((ReEq<Val,View,View,BoolView,RM_IMP>::
00428                         post(home,x,y,c,r.var())));
00429         break;
00430       case RM_PMI:
00431         GECODE_ES_FAIL((ReEq<Val,View,View,BoolView,RM_PMI>::
00432                         post(home,x,y,c,r.var())));
00433         break;
00434       default: GECODE_NEVER;
00435       }
00436       break;
00437     case IRT_NQ:
00438       {
00439         NegBoolView n(r.var());
00440         switch (r.mode()) {
00441         case RM_EQV:
00442           GECODE_ES_FAIL((ReEq<Val,View,View,NegBoolView,RM_EQV>::
00443                           post(home,x,y,c,n)));
00444           break;
00445         case RM_IMP:
00446           GECODE_ES_FAIL((ReEq<Val,View,View,NegBoolView,RM_PMI>::
00447                           post(home,x,y,c,n)));
00448           break;
00449         case RM_PMI:
00450           GECODE_ES_FAIL((ReEq<Val,View,View,NegBoolView,RM_IMP>::
00451                           post(home,x,y,c,n)));
00452           break;
00453         default: GECODE_NEVER;
00454         }
00455       }
00456       break;
00457     case IRT_LQ:
00458         switch (r.mode()) {
00459         case RM_EQV:
00460           GECODE_ES_FAIL((ReLq<Val,View,View,RM_EQV>::
00461                           post(home,x,y,c,r.var())));
00462           break;
00463         case RM_IMP:
00464           GECODE_ES_FAIL((ReLq<Val,View,View,RM_IMP>::
00465                           post(home,x,y,c,r.var())));
00466           break;
00467         case RM_PMI:
00468           GECODE_ES_FAIL((ReLq<Val,View,View,RM_PMI>::
00469                           post(home,x,y,c,r.var())));
00470           break;
00471         default: GECODE_NEVER;
00472         }
00473       break;
00474     default: GECODE_NEVER;
00475     }
00476   }
00477 
00478   template<class CtrlView>
00479   forceinline void
00480   posteqint(Home home, IntView& x, int c, CtrlView b, ReifyMode rm,
00481             IntPropLevel ipl) {
00482     if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
00483       switch (rm) {
00484       case RM_EQV:
00485         GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,CtrlView,RM_EQV>::
00486                         post(home,x,c,b)));
00487         break;
00488       case RM_IMP:
00489         GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,CtrlView,RM_IMP>::
00490                         post(home,x,c,b)));
00491         break;
00492       case RM_PMI:
00493         GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,CtrlView,RM_PMI>::
00494                         post(home,x,c,b)));
00495         break;
00496       default: GECODE_NEVER;
00497       }
00498     } else {
00499       switch (rm) {
00500       case RM_EQV:
00501         GECODE_ES_FAIL((Rel::ReEqBndInt<IntView,CtrlView,RM_EQV>::
00502                         post(home,x,c,b)));
00503         break;
00504       case RM_IMP:
00505         GECODE_ES_FAIL((Rel::ReEqBndInt<IntView,CtrlView,RM_IMP>::
00506                         post(home,x,c,b)));
00507         break;
00508       case RM_PMI:
00509         GECODE_ES_FAIL((Rel::ReEqBndInt<IntView,CtrlView,RM_PMI>::
00510                         post(home,x,c,b)));
00511         break;
00512       default: GECODE_NEVER;
00513       }
00514     }
00515   }
00516 
00517   void
00518   post(Home home,
00519        Term<IntView>* t, int n, IntRelType irt, int c, Reify r,
00520        IntPropLevel ipl) {
00521     Limits::check(c,"Int::linear");
00522     long long int d = c;
00523 
00524     eliminate(t,n,d);
00525 
00526     Term<IntView> *t_p, *t_n;
00527     int n_p, n_n, gcd=1;
00528     bool is_unit = normalize<IntView>(t,n,t_p,n_p,t_n,n_n,gcd);
00529 
00530     rewrite(irt,d,t_p,n_p,t_n,n_n);
00531 
00532     // Divide by gcd
00533     if (gcd > 1) {
00534       switch (irt) {
00535       case IRT_EQ:
00536         if ((d % gcd) != 0) {
00537           if (r.mode() != RM_PMI)
00538             GECODE_ME_FAIL(BoolView(r.var()).zero(home));
00539           return;
00540         }
00541         d /= gcd;
00542         break;
00543       case IRT_NQ:
00544         if ((d % gcd) != 0) {
00545           if (r.mode() != RM_IMP)
00546             GECODE_ME_FAIL(BoolView(r.var()).one(home));
00547           return;
00548         }
00549         d /= gcd;
00550         break;
00551       case IRT_LQ:
00552         d = floor_div_xp(d,static_cast<long long int>(gcd));
00553         break;
00554       default: GECODE_NEVER;
00555       }
00556     }
00557 
00558     if (n == 0) {
00559       bool fail = false;
00560       switch (irt) {
00561       case IRT_EQ: fail = (d != 0); break;
00562       case IRT_NQ: fail = (d == 0); break;
00563       case IRT_LQ: fail = (0 > d); break;
00564       default: GECODE_NEVER;
00565       }
00566       if (fail) {
00567         if (r.mode() != RM_PMI)
00568           GECODE_ME_FAIL(BoolView(r.var()).zero(home));
00569       } else {
00570         if (r.mode() != RM_IMP)
00571           GECODE_ME_FAIL(BoolView(r.var()).one(home));
00572       }
00573       return;
00574     }
00575 
00576     bool is_ip = precision(t_p,n_p,t_n,n_n,d);
00577 
00578     if (is_unit && is_ip) {
00579       c = static_cast<int>(d);
00580       if (n == 1) {
00581         switch (irt) {
00582         case IRT_EQ:
00583           if (n_p == 1) {
00584             posteqint<BoolView>(home,t_p[0].x,c,r.var(),r.mode(),ipl);
00585           } else {
00586             posteqint<BoolView>(home,t_p[0].x,-c,r.var(),r.mode(),ipl);
00587           }
00588           break;
00589         case IRT_NQ:
00590           {
00591             NegBoolView nb(r.var());
00592             ReifyMode rm = r.mode();
00593             switch (rm) {
00594             case RM_IMP: rm = RM_PMI; break;
00595             case RM_PMI: rm = RM_IMP; break;
00596             default: ;
00597             }
00598             if (n_p == 1) {
00599               posteqint<NegBoolView>(home,t_p[0].x,c,nb,rm,ipl);
00600             } else {
00601               posteqint<NegBoolView>(home,t_p[0].x,-c,nb,rm,ipl);
00602             }
00603           }
00604           break;
00605         case IRT_LQ:
00606           if (n_p == 1) {
00607             switch (r.mode()) {
00608             case RM_EQV:
00609               GECODE_ES_FAIL((Rel::ReLqInt<IntView,BoolView,RM_EQV>::
00610                               post(home,t_p[0].x,c,r.var())));
00611               break;
00612             case RM_IMP:
00613               GECODE_ES_FAIL((Rel::ReLqInt<IntView,BoolView,RM_IMP>::
00614                               post(home,t_p[0].x,c,r.var())));
00615               break;
00616             case RM_PMI:
00617               GECODE_ES_FAIL((Rel::ReLqInt<IntView,BoolView,RM_PMI>::
00618                               post(home,t_p[0].x,c,r.var())));
00619               break;
00620             default: GECODE_NEVER;
00621             }
00622           } else {
00623             NegBoolView nb(r.var());
00624             switch (r.mode()) {
00625             case RM_EQV:
00626               GECODE_ES_FAIL((Rel::ReLqInt<IntView,NegBoolView,RM_EQV>::
00627                               post(home,t_n[0].x,-c-1,nb)));
00628               break;
00629             case RM_IMP:
00630               GECODE_ES_FAIL((Rel::ReLqInt<IntView,NegBoolView,RM_PMI>::
00631                               post(home,t_n[0].x,-c-1,nb)));
00632               break;
00633             case RM_PMI:
00634               GECODE_ES_FAIL((Rel::ReLqInt<IntView,NegBoolView,RM_IMP>::
00635                               post(home,t_n[0].x,-c-1,nb)));
00636               break;
00637             default: GECODE_NEVER;
00638             }
00639           }
00640           break;
00641         default: GECODE_NEVER;
00642         }
00643       } else if (n == 2) {
00644         switch (irt) {
00645         case IRT_EQ:
00646           switch (n_p) {
00647           case 2:
00648             switch (r.mode()) {
00649             case RM_EQV:
00650               GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,BoolView,RM_EQV>::
00651                               post(home,t_p[0].x,t_p[1].x,c,r.var())));
00652               break;
00653             case RM_IMP:
00654               GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,BoolView,RM_IMP>::
00655                               post(home,t_p[0].x,t_p[1].x,c,r.var())));
00656               break;
00657             case RM_PMI:
00658               GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,BoolView,RM_PMI>::
00659                               post(home,t_p[0].x,t_p[1].x,c,r.var())));
00660               break;
00661             default: GECODE_NEVER;
00662             }
00663             break;
00664           case 1:
00665             switch (r.mode()) {
00666             case RM_EQV:
00667               GECODE_ES_FAIL((ReEqBin<int,IntView,MinusView,BoolView,RM_EQV>::
00668                               post(home,t_p[0].x,MinusView(t_n[0].x),c,
00669                                    r.var())));
00670               break;
00671             case RM_IMP:
00672               GECODE_ES_FAIL((ReEqBin<int,IntView,MinusView,BoolView,RM_IMP>::
00673                               post(home,t_p[0].x,MinusView(t_n[0].x),c,
00674                                    r.var())));
00675               break;
00676             case RM_PMI:
00677               GECODE_ES_FAIL((ReEqBin<int,IntView,MinusView,BoolView,RM_PMI>::
00678                               post(home,t_p[0].x,MinusView(t_n[0].x),c,
00679                                    r.var())));
00680               break;
00681             default: GECODE_NEVER;
00682             }
00683             break;
00684           case 0:
00685             switch (r.mode()) {
00686             case RM_EQV:
00687               GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,BoolView,RM_EQV>::
00688                               post(home,t_n[0].x,t_n[1].x,-c,r.var())));
00689               break;
00690             case RM_IMP:
00691               GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,BoolView,RM_IMP>::
00692                               post(home,t_n[0].x,t_n[1].x,-c,r.var())));
00693               break;
00694             case RM_PMI:
00695               GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,BoolView,RM_PMI>::
00696                               post(home,t_n[0].x,t_n[1].x,-c,r.var())));
00697               break;
00698             default: GECODE_NEVER;
00699             }
00700             break;
00701           default: GECODE_NEVER;
00702           }
00703           break;
00704         case IRT_NQ:
00705           {
00706             NegBoolView nb(r.var());
00707             switch (n_p) {
00708             case 2:
00709               switch (r.mode()) {
00710               case RM_EQV:
00711                 GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,NegBoolView,RM_EQV>::
00712                                 post(home,t_p[0].x,t_p[1].x,c,nb)));
00713                 break;
00714               case RM_IMP:
00715                 GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,NegBoolView,RM_PMI>::
00716                                 post(home,t_p[0].x,t_p[1].x,c,nb)));
00717                 break;
00718               case RM_PMI:
00719                 GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,NegBoolView,RM_IMP>::
00720                                 post(home,t_p[0].x,t_p[1].x,c,nb)));
00721                 break;
00722               default: GECODE_NEVER;
00723               }
00724               break;
00725             case 1:
00726               switch (r.mode()) {
00727               case RM_EQV:
00728                 GECODE_ES_FAIL((ReEqBin<int,IntView,MinusView,NegBoolView,RM_EQV>::
00729                                 post(home,t_p[0].x,MinusView(t_n[0].x),c,nb)));
00730                 break;
00731               case RM_IMP:
00732                 GECODE_ES_FAIL((ReEqBin<int,IntView,MinusView,NegBoolView,RM_PMI>::
00733                                 post(home,t_p[0].x,MinusView(t_n[0].x),c,nb)));
00734                 break;
00735               case RM_PMI:
00736                 GECODE_ES_FAIL((ReEqBin<int,IntView,MinusView,NegBoolView,RM_IMP>::
00737                                 post(home,t_p[0].x,MinusView(t_n[0].x),c,nb)));
00738                 break;
00739               default: GECODE_NEVER;
00740               }
00741               break;
00742             case 0:
00743               switch (r.mode()) {
00744               case RM_EQV:
00745                 GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,NegBoolView,RM_EQV>::
00746                                 post(home,t_p[0].x,t_p[1].x,-c,nb)));
00747                 break;
00748               case RM_IMP:
00749                 GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,NegBoolView,RM_PMI>::
00750                                 post(home,t_p[0].x,t_p[1].x,-c,nb)));
00751                 break;
00752               case RM_PMI:
00753                 GECODE_ES_FAIL((ReEqBin<int,IntView,IntView,NegBoolView,RM_IMP>::
00754                                 post(home,t_p[0].x,t_p[1].x,-c,nb)));
00755                 break;
00756               default: GECODE_NEVER;
00757               }
00758               break;
00759             default: GECODE_NEVER;
00760             }
00761           }
00762           break;
00763         case IRT_LQ:
00764           switch (n_p) {
00765           case 2:
00766             switch (r.mode()) {
00767             case RM_EQV:
00768               GECODE_ES_FAIL((ReLqBin<int,IntView,IntView,RM_EQV>::
00769                               post(home,t_p[0].x,t_p[1].x,c,r.var())));
00770               break;
00771             case RM_IMP:
00772               GECODE_ES_FAIL((ReLqBin<int,IntView,IntView,RM_IMP>::
00773                               post(home,t_p[0].x,t_p[1].x,c,r.var())));
00774               break;
00775             case RM_PMI:
00776               GECODE_ES_FAIL((ReLqBin<int,IntView,IntView,RM_PMI>::
00777                               post(home,t_p[0].x,t_p[1].x,c,r.var())));
00778               break;
00779             default: GECODE_NEVER;
00780             }
00781             break;
00782           case 1:
00783             switch (r.mode()) {
00784             case RM_EQV:
00785               GECODE_ES_FAIL((ReLqBin<int,IntView,MinusView,RM_EQV>::
00786                               post(home,t_p[0].x,MinusView(t_n[0].x),c,
00787                                    r.var())));
00788               break;
00789             case RM_IMP:
00790               GECODE_ES_FAIL((ReLqBin<int,IntView,MinusView,RM_IMP>::
00791                               post(home,t_p[0].x,MinusView(t_n[0].x),c,
00792                                    r.var())));
00793               break;
00794             case RM_PMI:
00795               GECODE_ES_FAIL((ReLqBin<int,IntView,MinusView,RM_PMI>::
00796                               post(home,t_p[0].x,MinusView(t_n[0].x),c,
00797                                    r.var())));
00798               break;
00799             default: GECODE_NEVER;
00800             }
00801             break;
00802           case 0:
00803             switch (r.mode()) {
00804             case RM_EQV:
00805               GECODE_ES_FAIL((ReLqBin<int,MinusView,MinusView,RM_EQV>::
00806                               post(home,MinusView(t_n[0].x),
00807                                    MinusView(t_n[1].x),c,r.var())));
00808               break;
00809             case RM_IMP:
00810               GECODE_ES_FAIL((ReLqBin<int,MinusView,MinusView,RM_IMP>::
00811                               post(home,MinusView(t_n[0].x),
00812                                    MinusView(t_n[1].x),c,r.var())));
00813               break;
00814             case RM_PMI:
00815               GECODE_ES_FAIL((ReLqBin<int,MinusView,MinusView,RM_PMI>::
00816                               post(home,MinusView(t_n[0].x),
00817                                    MinusView(t_n[1].x),c,r.var())));
00818               break;
00819             default: GECODE_NEVER;
00820             }
00821             break;
00822           default: GECODE_NEVER;
00823           }
00824           break;
00825         default: GECODE_NEVER;
00826         }
00827       } else {
00828         ViewArray<IntView> x(home,n_p);
00829         for (int i=0; i<n_p; i++)
00830           x[i] = t_p[i].x;
00831         ViewArray<IntView> y(home,n_n);
00832         for (int i=0; i<n_n; i++)
00833           y[i] = t_n[i].x;
00834         post_nary<int,IntView>(home,x,y,irt,c,r);
00835       }
00836     } else if (is_ip) {
00837       // Arbitrary coefficients with integer precision
00838       c = static_cast<int>(d);
00839       ViewArray<IntScaleView> x(home,n_p);
00840       for (int i=0; i<n_p; i++)
00841         x[i] = IntScaleView(t_p[i].a,t_p[i].x);
00842       ViewArray<IntScaleView> y(home,n_n);
00843       for (int i=0; i<n_n; i++)
00844         y[i] = IntScaleView(t_n[i].a,t_n[i].x);
00845       post_nary<int,IntScaleView>(home,x,y,irt,c,r);
00846     } else {
00847       // Arbitrary coefficients with long long precision
00848       ViewArray<LLongScaleView> x(home,n_p);
00849       for (int i=0; i<n_p; i++)
00850         x[i] = LLongScaleView(t_p[i].a,t_p[i].x);
00851       ViewArray<LLongScaleView> y(home,n_n);
00852       for (int i=0; i<n_n; i++)
00853         y[i] = LLongScaleView(t_n[i].a,t_n[i].x);
00854       post_nary<long long int,LLongScaleView>(home,x,y,irt,d,r);
00855     }
00856   }
00857 
00858 }}}
00859 
00860 // STATISTICS: int-post