Generated on Thu Apr 11 13:58:56 2019 for Gecode by doxygen 1.6.3

bool.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 <gecode/int/bool.hh>
00035 #include <gecode/int/rel.hh>
00036 
00037 namespace Gecode {
00038 
00039   void
00040   rel(Home home, BoolVar x0, IntRelType irt, BoolVar x1, IntPropLevel) {
00041     using namespace Int;
00042     GECODE_POST;
00043     switch (irt) {
00044     case IRT_EQ:
00045       GECODE_ES_FAIL((Bool::Eq<BoolView,BoolView>
00046                            ::post(home,x0,x1)));
00047       break;
00048     case IRT_NQ:
00049       {
00050         NegBoolView n1(x1);
00051         GECODE_ES_FAIL((Bool::Eq<BoolView,NegBoolView>
00052                              ::post(home,x0,n1)));
00053       }
00054       break;
00055     case IRT_GQ:
00056       GECODE_ES_FAIL(Bool::Lq<BoolView>::post(home,x1,x0));
00057       break;
00058     case IRT_LQ:
00059       GECODE_ES_FAIL(Bool::Lq<BoolView>::post(home,x0,x1));
00060       break;
00061     case IRT_GR:
00062       GECODE_ES_FAIL(Bool::Le<BoolView>::post(home,x1,x0));
00063       break;
00064     case IRT_LE:
00065       GECODE_ES_FAIL(Bool::Le<BoolView>::post(home,x0,x1));
00066       break;
00067     default:
00068       throw UnknownRelation("Int::rel");
00069     }
00070   }
00071 
00072   void
00073   rel(Home home, BoolVar x0, IntRelType irt, int n, IntPropLevel) {
00074     using namespace Int;
00075     GECODE_POST;
00076     BoolView x(x0);
00077     if (n == 0) {
00078       switch (irt) {
00079       case IRT_LQ:
00080       case IRT_EQ:
00081         GECODE_ME_FAIL(x.zero(home)); break;
00082       case IRT_NQ:
00083       case IRT_GR:
00084         GECODE_ME_FAIL(x.one(home)); break;
00085       case IRT_LE:
00086         home.fail(); break;
00087       case IRT_GQ:
00088         break;
00089       default:
00090         throw UnknownRelation("Int::rel");
00091       }
00092     } else if (n == 1) {
00093       switch (irt) {
00094       case IRT_GQ:
00095       case IRT_EQ:
00096         GECODE_ME_FAIL(x.one(home)); break;
00097       case IRT_NQ:
00098       case IRT_LE:
00099         GECODE_ME_FAIL(x.zero(home)); break;
00100       case IRT_GR:
00101         home.fail(); break;
00102       case IRT_LQ:
00103         break;
00104       default:
00105         throw UnknownRelation("Int::rel");
00106       }
00107     } else {
00108       throw NotZeroOne("Int::rel");
00109     }
00110   }
00111 
00112   void
00113   rel(Home home, BoolVar x0, IntRelType irt, BoolVar x1, Reify r,
00114       IntPropLevel) {
00115     using namespace Int;
00116     GECODE_POST;
00117     switch (irt) {
00118     case IRT_EQ:
00119       switch (r.mode()) {
00120       case RM_EQV:
00121         GECODE_ES_FAIL((Bool::Eqv<BoolView,BoolView,BoolView>
00122                         ::post(home,x0,x1,r.var())));
00123         break;
00124       case RM_IMP:
00125         GECODE_ES_FAIL((Rel::ReEqBnd<BoolView,BoolView,RM_IMP>
00126                         ::post(home,x0,x1,r.var())));
00127         break;
00128       case RM_PMI:
00129         GECODE_ES_FAIL((Rel::ReEqBnd<BoolView,BoolView,RM_PMI>
00130                         ::post(home,x0,x1,r.var())));
00131         break;
00132       default: throw UnknownReifyMode("Int::rel");
00133       }
00134       break;
00135     case IRT_NQ:
00136       {
00137         NegBoolView nr(r.var());
00138         switch (r.mode()) {
00139         case RM_EQV:
00140           GECODE_ES_FAIL((Bool::Eqv<BoolView,BoolView,NegBoolView>
00141                           ::post(home,x0,x1,nr)));
00142           break;
00143         case RM_IMP:
00144           GECODE_ES_FAIL((Rel::ReEqBnd<BoolView,NegBoolView,RM_PMI>
00145                           ::post(home,x0,x1,nr)));
00146           break;
00147         case RM_PMI:
00148           GECODE_ES_FAIL((Rel::ReEqBnd<BoolView,NegBoolView,RM_IMP>
00149                           ::post(home,x0,x1,nr)));
00150           break;
00151         default: throw UnknownReifyMode("Int::rel");
00152         }
00153       }
00154       break;
00155     case IRT_GQ:
00156       std::swap(x0,x1); // Fall through
00157     case IRT_LQ:
00158       switch (r.mode()) {
00159       case RM_EQV:
00160         {
00161           NegBoolView n0(x0);
00162           GECODE_ES_FAIL((Bool::Or<NegBoolView,BoolView,BoolView>
00163                           ::post(home,n0,x1,r.var())));
00164         }
00165         break;
00166       case RM_IMP:
00167         GECODE_ES_FAIL((Rel::ReLq<BoolView,BoolView,RM_IMP>
00168                         ::post(home,x0,x1,r.var())));
00169         break;
00170       case RM_PMI:
00171         GECODE_ES_FAIL((Rel::ReLq<BoolView,BoolView,RM_PMI>
00172                         ::post(home,x0,x1,r.var())));
00173         break;
00174       default: throw UnknownReifyMode("Int::rel");
00175       }
00176       break;
00177     case IRT_LE:
00178       std::swap(x0,x1); // Fall through
00179     case IRT_GR:
00180       {
00181         NegBoolView nr(r.var());
00182         switch (r.mode()) {
00183         case RM_EQV:
00184           {
00185             NegBoolView n0(x0);
00186             GECODE_ES_FAIL((Bool::Or<NegBoolView,BoolView,NegBoolView>
00187                             ::post(home,n0,x1,nr)));
00188           }
00189           break;
00190         case RM_IMP:
00191           GECODE_ES_FAIL((Rel::ReLq<BoolView,NegBoolView,RM_PMI>
00192                           ::post(home,x0,x1,nr)));
00193           break;
00194         case RM_PMI:
00195           GECODE_ES_FAIL((Rel::ReLq<BoolView,NegBoolView,RM_IMP>
00196                           ::post(home,x0,x1,nr)));
00197           break;
00198         default: throw UnknownReifyMode("Int::rel");
00199         }
00200       }
00201       break;
00202     default:
00203       throw UnknownRelation("Int::rel");
00204     }
00205   }
00206 
00207   void
00208   rel(Home home, BoolVar x0, IntRelType irt, int n, Reify r,
00209       IntPropLevel) {
00210     using namespace Int;
00211     GECODE_POST;
00212     BoolView x(x0);
00213     BoolView y(r.var());
00214     if (n == 0) {
00215       switch (irt) {
00216       case IRT_LQ:
00217       case IRT_EQ:
00218         switch (r.mode()) {
00219         case RM_EQV:
00220           {
00221             NegBoolView ny(y);
00222             GECODE_ES_FAIL((Bool::Eq<BoolView,NegBoolView>
00223                             ::post(home,x,ny)));
00224           }
00225           break;
00226         case RM_IMP:
00227           {
00228             NegBoolView nx(x); NegBoolView ny(y);
00229             GECODE_ES_FAIL((Bool::BinOrTrue<NegBoolView,NegBoolView>
00230                             ::post(home,nx,ny)));
00231           }
00232           break;
00233         case RM_PMI:
00234           GECODE_ES_FAIL((Bool::BinOrTrue<BoolView,BoolView>
00235                           ::post(home,x,y)));
00236           break;
00237         default: throw UnknownReifyMode("Int::rel");
00238         }
00239         break;
00240       case IRT_NQ:
00241       case IRT_GR:
00242         switch (r.mode()) {
00243         case RM_EQV:
00244           GECODE_ES_FAIL((Bool::Eq<BoolView,BoolView>
00245                           ::post(home,x,y)));
00246           break;
00247         case RM_IMP:
00248           {
00249             NegBoolView ny(y);
00250             GECODE_ES_FAIL((Bool::BinOrTrue<BoolView,NegBoolView>
00251                             ::post(home,x,ny)));
00252           }
00253           break;
00254         case RM_PMI:
00255           {
00256             NegBoolView nx(x);
00257             GECODE_ES_FAIL((Bool::BinOrTrue<NegBoolView,BoolView>
00258                             ::post(home,nx,y)));
00259           }
00260           break;
00261         default: throw UnknownReifyMode("Int::rel");
00262         }
00263         break;
00264       case IRT_LE:
00265         switch (r.mode()) {
00266         case RM_EQV:
00267         case RM_IMP:
00268           GECODE_ME_FAIL(y.zero(home));
00269           break;
00270         case RM_PMI:
00271           break;
00272         default: throw UnknownReifyMode("Int::rel");
00273         }
00274         break;
00275       case IRT_GQ:
00276         switch (r.mode()) {
00277         case RM_EQV:
00278         case RM_PMI:
00279           GECODE_ME_FAIL(y.one(home));
00280           break;
00281         case RM_IMP:
00282           break;
00283         default: throw UnknownReifyMode("Int::rel");
00284         }
00285         break;
00286       default:
00287         throw UnknownRelation("Int::rel");
00288       }
00289     } else if (n == 1) {
00290       switch (irt) {
00291       case IRT_NQ:
00292       case IRT_LE:
00293         switch (r.mode()) {
00294         case RM_EQV:
00295           {
00296             NegBoolView ny(y);
00297             GECODE_ES_FAIL((Bool::Eq<BoolView,NegBoolView>
00298                             ::post(home,x,ny)));
00299           }
00300           break;
00301         case RM_IMP:
00302           {
00303             NegBoolView nx(x); NegBoolView ny(y);
00304             GECODE_ES_FAIL((Bool::BinOrTrue<NegBoolView,NegBoolView>
00305                             ::post(home,nx,ny)));
00306           }
00307           break;
00308         case RM_PMI:
00309           GECODE_ES_FAIL((Bool::BinOrTrue<BoolView,BoolView>
00310                           ::post(home,x,y)));
00311           break;
00312         default: throw UnknownReifyMode("Int::rel");
00313         }
00314         break;
00315       case IRT_EQ:
00316       case IRT_GQ:
00317         switch (r.mode()) {
00318         case RM_EQV:
00319           GECODE_ES_FAIL((Bool::Eq<BoolView,BoolView>
00320                           ::post(home,x,y)));
00321           break;
00322         case RM_IMP:
00323           {
00324             NegBoolView ny(y);
00325             GECODE_ES_FAIL((Bool::BinOrTrue<BoolView,NegBoolView>
00326                             ::post(home,x,ny)));
00327           }
00328           break;
00329         case RM_PMI:
00330           {
00331             NegBoolView nx(x);
00332             GECODE_ES_FAIL((Bool::BinOrTrue<NegBoolView,BoolView>
00333                             ::post(home,nx,y)));
00334           }
00335           break;
00336         default: throw UnknownReifyMode("Int::rel");
00337         }
00338         break;
00339       case IRT_GR:
00340         switch (r.mode()) {
00341         case RM_EQV:
00342         case RM_IMP:
00343           GECODE_ME_FAIL(y.zero(home));
00344           break;
00345         case RM_PMI:
00346           break;
00347         default: throw UnknownReifyMode("Int::rel");
00348         }
00349         break;
00350       case IRT_LQ:
00351         switch (r.mode()) {
00352         case RM_EQV:
00353         case RM_PMI:
00354           GECODE_ME_FAIL(y.one(home));
00355           break;
00356         case RM_IMP:
00357           break;
00358         default: throw UnknownReifyMode("Int::rel");
00359         }
00360         break;
00361       default:
00362         throw UnknownRelation("Int::rel");
00363       }
00364     } else {
00365       throw NotZeroOne("Int::rel");
00366     }
00367   }
00368 
00369   void
00370   rel(Home home, const BoolVarArgs& x, IntRelType irt, BoolVar y,
00371       IntPropLevel) {
00372     using namespace Int;
00373     GECODE_POST;
00374     switch (irt) {
00375     case IRT_EQ:
00376       for (int i=0; i<x.size(); i++) {
00377         GECODE_ES_FAIL((Bool::Eq<BoolView,BoolView>
00378                              ::post(home,x[i],y)));
00379       }
00380       break;
00381     case IRT_NQ:
00382       {
00383         NegBoolView n(y);
00384         for (int i=0; i<x.size(); i++) {
00385           GECODE_ES_FAIL((Bool::Eq<BoolView,NegBoolView>
00386                                ::post(home,x[i],n)));
00387         }
00388       }
00389       break;
00390     case IRT_GQ:
00391       for (int i=0; i<x.size(); i++) {
00392         GECODE_ES_FAIL(Bool::Lq<BoolView>::post(home,y,x[i]));
00393       }
00394       break;
00395     case IRT_LQ:
00396       for (int i=0; i<x.size(); i++) {
00397         GECODE_ES_FAIL(Bool::Lq<BoolView>::post(home,x[i],y));
00398       }
00399       break;
00400     case IRT_GR:
00401       for (int i=0; i<x.size(); i++) {
00402         GECODE_ES_FAIL(Bool::Le<BoolView>::post(home,y,x[i]));
00403       }
00404       break;
00405     case IRT_LE:
00406       for (int i=0; i<x.size(); i++) {
00407         GECODE_ES_FAIL(Bool::Le<BoolView>::post(home,x[i],y));
00408       }
00409       break;
00410     default:
00411       throw UnknownRelation("Int::rel");
00412     }
00413   }
00414 
00415   void
00416   rel(Home home, const BoolVarArgs& x, IntRelType irt, int n,
00417       IntPropLevel) {
00418     using namespace Int;
00419     GECODE_POST;
00420     if (n == 0) {
00421       switch (irt) {
00422       case IRT_LQ:
00423       case IRT_EQ:
00424         for (int i=0; i<x.size(); i++) {
00425           BoolView xi(x[i]); GECODE_ME_FAIL(xi.zero(home));
00426         }
00427         break;
00428       case IRT_NQ:
00429       case IRT_GR:
00430         for (int i=0; i<x.size(); i++) {
00431           BoolView xi(x[i]); GECODE_ME_FAIL(xi.one(home));
00432         }
00433         break;
00434       case IRT_LE:
00435         home.fail(); break;
00436       case IRT_GQ:
00437         break;
00438       default:
00439         throw UnknownRelation("Int::rel");
00440       }
00441     } else if (n == 1) {
00442       switch (irt) {
00443       case IRT_GQ:
00444       case IRT_EQ:
00445         for (int i=0; i<x.size(); i++) {
00446           BoolView xi(x[i]); GECODE_ME_FAIL(xi.one(home));
00447         }
00448         break;
00449       case IRT_NQ:
00450       case IRT_LE:
00451         for (int i=0; i<x.size(); i++) {
00452           BoolView xi(x[i]); GECODE_ME_FAIL(xi.zero(home));
00453         }
00454         break;
00455       case IRT_GR:
00456         home.fail(); break;
00457       case IRT_LQ:
00458         break;
00459       default:
00460         throw UnknownRelation("Int::rel");
00461       }
00462     } else {
00463       throw NotZeroOne("Int::rel");
00464     }
00465   }
00466 
00467   void
00468   rel(Home home, const BoolVarArgs& x, IntRelType irt, IntPropLevel) {
00469     using namespace Int;
00470     GECODE_POST;
00471     if ((irt != IRT_NQ) && (x.size() < 2))
00472       return;
00473 
00474     switch (irt) {
00475     case IRT_EQ:
00476       {
00477         ViewArray<BoolView> y(home,x);
00478         GECODE_ES_FAIL(Bool::NaryEq<BoolView>::post(home,y));
00479       }
00480       break;
00481     case IRT_NQ:
00482       {
00483         ViewArray<BoolView> y(home,x);
00484         GECODE_ES_FAIL((Rel::NaryNq<BoolView>::post(home,y)));
00485       }
00486       break;
00487     case IRT_LE:
00488       if (x.size() == 2) {
00489         GECODE_ES_FAIL(Bool::Le<BoolView>::post(home,x[0],x[1]));
00490       } else {
00491         home.fail();
00492       }
00493       break;
00494     case IRT_LQ:
00495       {
00496         ViewArray<BoolView> y(home,x);
00497         GECODE_ES_FAIL(Bool::NaryLq<BoolView>::post(home,y));
00498       }
00499       break;
00500     case IRT_GR:
00501       if (x.size() == 2) {
00502         GECODE_ES_FAIL(Bool::Le<BoolView>::post(home,x[1],x[0]));
00503       } else {
00504         home.fail();
00505       }
00506       break;
00507     case IRT_GQ:
00508       {
00509         ViewArray<BoolView> y(home,x.size());
00510         for (int i=0; i<x.size(); i++)
00511           y[i] = x[x.size()-1-i];
00512         GECODE_ES_FAIL(Bool::NaryLq<BoolView>::post(home,y));
00513       }
00514       break;
00515     default:
00516       throw UnknownRelation("Int::rel");
00517     }
00518   }
00519 
00520   void
00521   rel(Home home, const BoolVarArgs& x, IntRelType irt, const BoolVarArgs& y,
00522       IntPropLevel) {
00523     using namespace Int;
00524     GECODE_POST;
00525 
00526     switch (irt) {
00527     case IRT_GR:
00528       {
00529         ViewArray<BoolView> xv(home,x), yv(home,y);
00530         GECODE_ES_FAIL((Rel::LexLqLe<BoolView,BoolView>
00531                         ::post(home,yv,xv,true)));
00532       }
00533       break;
00534     case IRT_LE:
00535       {
00536         ViewArray<BoolView> xv(home,x), yv(home,y);
00537         GECODE_ES_FAIL((Rel::LexLqLe<BoolView,BoolView>
00538                         ::post(home,xv,yv,true)));
00539       }
00540       break;
00541     case IRT_GQ:
00542       {
00543         ViewArray<BoolView> xv(home,x), yv(home,y);
00544         GECODE_ES_FAIL((Rel::LexLqLe<BoolView,BoolView>
00545                         ::post(home,yv,xv,false)));
00546       }
00547       break;
00548     case IRT_LQ:
00549       {
00550         ViewArray<BoolView> xv(home,x), yv(home,y);
00551         GECODE_ES_FAIL((Rel::LexLqLe<BoolView,BoolView>
00552                         ::post(home,xv,yv,false)));
00553       }
00554       break;
00555     case IRT_EQ:
00556       for (int i=0; i<x.size(); i++) {
00557         GECODE_ES_FAIL((Bool::Eq<BoolView,BoolView>
00558                         ::post(home,x[i],y[i])));
00559       }
00560       break;
00561     case IRT_NQ:
00562       {
00563         ViewArray<BoolView> xv(home,x), yv(home,y);
00564         GECODE_ES_FAIL((Rel::LexNq<BoolView,BoolView>
00565                         ::post(home,xv,yv)));
00566       }
00567       break;
00568     default:
00569       throw UnknownRelation("Int::rel");
00570     }
00571   }
00572 
00573   namespace {
00574 
00576     ViewArray<Int::ConstIntView>
00577     viewarray(Space& home, const IntArgs& x) {
00578       ViewArray<Int::ConstIntView> xv(home, x.size());
00579       for (int i=0; i<x.size(); i++) {
00580         if ((x[i] != 0) && (x[i] != 1))
00581           throw Int::NotZeroOne("Int::rel");
00582         xv[i] = Int::ConstIntView(x[i]);
00583       }
00584       return xv;
00585     }
00586 
00587   }
00588 
00589   void
00590   rel(Home home, const BoolVarArgs& x, IntRelType irt, const IntArgs& y,
00591       IntPropLevel) {
00592     using namespace Int;
00593     GECODE_POST;
00594 
00595     switch (irt) {
00596     case IRT_GR:
00597       {
00598         ViewArray<BoolView> xv(home,x);
00599         ViewArray<ConstIntView> yv(viewarray(home,y));
00600         GECODE_ES_FAIL((Rel::LexLqLe<ConstIntView,BoolView>
00601                         ::post(home,yv,xv,true)));
00602       }
00603       break;
00604     case IRT_LE:
00605       {
00606         ViewArray<BoolView> xv(home,x);
00607         ViewArray<ConstIntView> yv(viewarray(home,y));
00608         GECODE_ES_FAIL((Rel::LexLqLe<BoolView,ConstIntView>
00609                         ::post(home,xv,yv,true)));
00610       }
00611       break;
00612     case IRT_GQ:
00613       {
00614         ViewArray<BoolView> xv(home,x);
00615         ViewArray<ConstIntView> yv(viewarray(home,y));
00616         GECODE_ES_FAIL((Rel::LexLqLe<ConstIntView,BoolView>
00617                         ::post(home,yv,xv,false)));
00618       }
00619       break;
00620     case IRT_LQ:
00621       {
00622         ViewArray<BoolView> xv(home,x);
00623         ViewArray<ConstIntView> yv(viewarray(home,y));
00624         GECODE_ES_FAIL((Rel::LexLqLe<BoolView,ConstIntView>
00625                         ::post(home,xv,yv,false)));
00626       }
00627       break;
00628     case IRT_EQ:
00629       if (x.size() != y.size()) {
00630         home.fail();
00631       } else {
00632         for (int i=0; i<x.size(); i++)
00633           GECODE_ME_FAIL(BoolView(x[i]).eq(home,y[i]));
00634       }
00635       break;
00636     case IRT_NQ:
00637       {
00638         ViewArray<BoolView> xv(home,x); 
00639         ViewArray<ConstIntView> yv(viewarray(home,y));
00640         GECODE_ES_FAIL((Rel::LexNq<BoolView,ConstIntView>
00641                         ::post(home,xv,yv)));
00642       }
00643       break;
00644     default:
00645       throw UnknownRelation("Int::rel");
00646     }
00647   }
00648 
00649   void
00650   rel(Home home, const IntArgs& x, IntRelType irt, const BoolVarArgs& y,
00651       IntPropLevel ipl) {
00652     rel(home,y,irt,x,ipl);
00653   }
00654 
00655   void
00656   rel(Home home, BoolVar x0, BoolOpType o, BoolVar x1, BoolVar x2,
00657       IntPropLevel) {
00658     using namespace Int;
00659     GECODE_POST;
00660     switch (o) {
00661     case BOT_AND:
00662       {
00663         NegBoolView n0(x0); NegBoolView n1(x1); NegBoolView n2(x2);
00664         GECODE_ES_FAIL((Bool::Or<NegBoolView,NegBoolView,NegBoolView>
00665                         ::post(home,n0,n1,n2)));
00666       }
00667       break;
00668     case BOT_OR:
00669       GECODE_ES_FAIL((Bool::Or<BoolView,BoolView,BoolView>
00670                       ::post(home,x0,x1,x2)));
00671       break;
00672     case BOT_IMP:
00673       {
00674         NegBoolView n0(x0);
00675         GECODE_ES_FAIL((Bool::Or<NegBoolView,BoolView,BoolView>
00676                         ::post(home,n0,x1,x2)));
00677       }
00678       break;
00679     case BOT_EQV:
00680       GECODE_ES_FAIL((Bool::Eqv<BoolView,BoolView,BoolView>
00681                       ::post(home,x0,x1,x2)));
00682       break;
00683     case BOT_XOR:
00684       {
00685         NegBoolView n2(x2);
00686         GECODE_ES_FAIL((Bool::Eqv<BoolView,BoolView,NegBoolView>
00687                         ::post(home,x0,x1,n2)));
00688       }
00689       break;
00690     default:
00691       throw UnknownOperation("Int::rel");
00692     }
00693   }
00694 
00695   void
00696   rel(Home home, BoolVar x0, BoolOpType o, BoolVar x1, int n,
00697       IntPropLevel) {
00698     using namespace Int;
00699     GECODE_POST;
00700     if (n == 0) {
00701       switch (o) {
00702       case BOT_AND:
00703         {
00704           NegBoolView n0(x0); NegBoolView n1(x1);
00705           GECODE_ES_FAIL((Bool::BinOrTrue<NegBoolView,NegBoolView>
00706                                ::post(home,n0,n1)));
00707         }
00708         break;
00709       case BOT_OR:
00710         {
00711           BoolView b0(x0); BoolView b1(x1);
00712           GECODE_ME_FAIL(b0.zero(home));
00713           GECODE_ME_FAIL(b1.zero(home));
00714         }
00715         break;
00716       case BOT_IMP:
00717         {
00718           BoolView b0(x0); BoolView b1(x1);
00719           GECODE_ME_FAIL(b0.one(home));
00720           GECODE_ME_FAIL(b1.zero(home));
00721         }
00722         break;
00723       case BOT_EQV:
00724         {
00725           NegBoolView n0(x0);
00726           GECODE_ES_FAIL((Bool::Eq<NegBoolView,BoolView>::post(home,n0,x1)));
00727         }
00728         break;
00729       case BOT_XOR:
00730         GECODE_ES_FAIL((Bool::Eq<BoolView,BoolView>::post(home,x0,x1)));
00731         break;
00732       default:
00733         throw UnknownOperation("Int::rel");
00734       }
00735     } else if (n == 1) {
00736       switch (o) {
00737       case BOT_AND:
00738         {
00739           BoolView b0(x0); BoolView b1(x1);
00740           GECODE_ME_FAIL(b0.one(home));
00741           GECODE_ME_FAIL(b1.one(home));
00742         }
00743         break;
00744       case BOT_OR:
00745         GECODE_ES_FAIL((Bool::BinOrTrue<BoolView,BoolView>::post(home,x0,x1)));
00746         break;
00747       case BOT_IMP:
00748         {
00749           NegBoolView n0(x0);
00750           GECODE_ES_FAIL((Bool::BinOrTrue<NegBoolView,BoolView>
00751                           ::post(home,n0,x1)));
00752         }
00753         break;
00754       case BOT_EQV:
00755         GECODE_ES_FAIL((Bool::Eq<BoolView,BoolView>::post(home,x0,x1)));
00756         break;
00757       case BOT_XOR:
00758         {
00759           NegBoolView n0(x0);
00760           GECODE_ES_FAIL((Bool::Eq<NegBoolView,BoolView>::post(home,n0,x1)));
00761         }
00762         break;
00763       default:
00764         throw UnknownOperation("Int::rel");
00765       }
00766     } else {
00767       throw NotZeroOne("Int::rel");
00768     }
00769   }
00770 
00771   void
00772   rel(Home home, BoolOpType o, const BoolVarArgs& x, BoolVar y,
00773       IntPropLevel) {
00774     using namespace Int;
00775     GECODE_POST;
00776     int m = x.size();
00777     Region r;
00778     switch (o) {
00779     case BOT_AND:
00780       {
00781         ViewArray<NegBoolView> b(home,m);
00782         for (int i=0; i<m; i++) {
00783           NegBoolView nb(x[i]); b[i]=nb;
00784         }
00785         NegBoolView ny(y);
00786         b.unique();
00787         GECODE_ES_FAIL((Bool::NaryOr<NegBoolView,NegBoolView>
00788                              ::post(home,b,ny)));
00789       }
00790       break;
00791     case BOT_OR:
00792       {
00793         ViewArray<BoolView> b(home,x);
00794         b.unique();
00795         GECODE_ES_FAIL((Bool::NaryOr<BoolView,BoolView>::post(home,b,y)));
00796       }
00797       break;
00798     case BOT_IMP:
00799       if (m < 2) {
00800         throw TooFewArguments("Int::rel");
00801       } else {
00802         ViewArray<NegBoolView> a(home,x.size()-1);
00803         for (int i=x.size()-1; i--; )
00804           a[i]=NegBoolView(x[i]);
00805         ViewArray<BoolView> b(home,1);
00806         b[0]=x[x.size()-1];
00807         GECODE_ES_FAIL((Bool::Clause<BoolView,NegBoolView>
00808                         ::post(home,b,a,y)));
00809       }
00810       break;
00811     case BOT_EQV:
00812       {
00813         ViewArray<BoolView> xy(home, x.size() + 1);
00814         for (int i=0; i<x.size(); i++)
00815           xy[i] = x[i];
00816         xy[x.size()] = y;
00817         GECODE_ES_FAIL(Bool::NaryEqv::post(home,xy,0));
00818       }
00819       break;
00820     case BOT_XOR:
00821       {
00822         ViewArray<BoolView> xy(home, x.size() + 1);
00823         for (int i=0; i<x.size(); i++)
00824           xy[i] = x[i];
00825         xy[x.size()] = y;
00826         GECODE_ES_FAIL(Bool::NaryEqv::post(home,xy,1));
00827       }
00828       break;
00829     default:
00830       throw UnknownOperation("Int::rel");
00831     }
00832   }
00833 
00834   void
00835   rel(Home home, BoolOpType o, const BoolVarArgs& x, int n,
00836       IntPropLevel) {
00837     using namespace Int;
00838     if ((n < 0) || (n > 1))
00839       throw NotZeroOne("Int::rel");
00840     GECODE_POST;
00841     int m = x.size();
00842     Region r;
00843     switch (o) {
00844     case BOT_AND:
00845       if (n == 0) {
00846         ViewArray<NegBoolView> b(home,m);
00847         for (int i=0; i<m; i++) {
00848           NegBoolView nb(x[i]); b[i]=nb;
00849         }
00850         b.unique();
00851         GECODE_ES_FAIL(Bool::NaryOrTrue<NegBoolView>::post(home,b));
00852       } else {
00853         for (int i=0; i<m; i++) {
00854           BoolView b(x[i]); GECODE_ME_FAIL(b.one(home));
00855         }
00856       }
00857       break;
00858     case BOT_OR:
00859       if (n == 0) {
00860         for (int i=0; i<m; i++) {
00861           BoolView b(x[i]); GECODE_ME_FAIL(b.zero(home));
00862         }
00863       } else {
00864         ViewArray<BoolView> b(home,x);
00865         b.unique();
00866         GECODE_ES_FAIL(Bool::NaryOrTrue<BoolView>::post(home,b));
00867       }
00868       break;
00869     case BOT_IMP:
00870       if (m < 2) {
00871         throw TooFewArguments("Int::rel");
00872       } else if (n == 0) {
00873         for (int i=m-1; i--; )
00874           GECODE_ME_FAIL(BoolView(x[i]).one(home));
00875         GECODE_ME_FAIL(BoolView(x[m-1]).zero(home));
00876       } else {
00877         ViewArray<NegBoolView> a(home,x.size()-1);
00878         for (int i=x.size()-1; i--; )
00879           a[i]=NegBoolView(x[i]);
00880         ViewArray<BoolView> b(home,1);
00881         b[0]=x[x.size()-1];
00882         GECODE_ES_FAIL((Bool::ClauseTrue<BoolView,NegBoolView>
00883                         ::post(home,b,a)));
00884       }
00885       break;
00886     case BOT_EQV:
00887       {
00888         ViewArray<BoolView> b(home,x);
00889         GECODE_ES_FAIL(Bool::NaryEqv::post(home,b,n));
00890       }
00891       break;
00892     case BOT_XOR:
00893       {
00894         ViewArray<BoolView> b(home,x);
00895         GECODE_ES_FAIL(Bool::NaryEqv::post(home,b,1^n));
00896       }
00897       break;
00898     default:
00899       throw UnknownOperation("Int::rel");
00900     }
00901   }
00902 
00903   void
00904   clause(Home home, BoolOpType o, const BoolVarArgs& x, const BoolVarArgs& y,
00905          int n, IntPropLevel) {
00906     using namespace Int;
00907     if ((n < 0) || (n > 1))
00908       throw NotZeroOne("Int::rel");
00909     GECODE_POST;
00910     switch (o) {
00911     case BOT_AND:
00912       if (n == 0) {
00913         ViewArray<NegBoolView> xv(home,x.size());
00914         for (int i=0; i<x.size(); i++) {
00915           NegBoolView nxi(x[i]); xv[i]=nxi;
00916         }
00917         ViewArray<BoolView> yv(home,y);
00918         xv.unique(); yv.unique();
00919         GECODE_ES_FAIL((Bool::ClauseTrue<NegBoolView,BoolView>
00920                         ::post(home,xv,yv)));
00921       } else {
00922         for (int i=0; i<x.size(); i++) {
00923           BoolView b(x[i]); GECODE_ME_FAIL(b.one(home));
00924         }
00925         for (int i=0; i<y.size(); i++) {
00926           BoolView b(y[i]); GECODE_ME_FAIL(b.zero(home));
00927         }
00928       }
00929       break;
00930     case BOT_OR:
00931       if (n == 0) {
00932         for (int i=0; i<x.size(); i++) {
00933           BoolView b(x[i]); GECODE_ME_FAIL(b.zero(home));
00934         }
00935         for (int i=0; i<y.size(); i++) {
00936           BoolView b(y[i]); GECODE_ME_FAIL(b.one(home));
00937         }
00938       } else {
00939         ViewArray<BoolView> xv(home,x);
00940         ViewArray<NegBoolView> yv(home,y.size());
00941         for (int i=0; i<y.size(); i++) {
00942           NegBoolView nyi(y[i]); yv[i]=nyi;
00943         }
00944         xv.unique(); yv.unique();
00945         GECODE_ES_FAIL((Bool::ClauseTrue<BoolView,NegBoolView>
00946                         ::post(home,xv,yv)));
00947       }
00948       break;
00949     default:
00950       throw IllegalOperation("Int::clause");
00951     }
00952   }
00953 
00954   void
00955   clause(Home home, BoolOpType o, const BoolVarArgs& x, const BoolVarArgs& y,
00956          BoolVar z, IntPropLevel) {
00957     using namespace Int;
00958     GECODE_POST;
00959     switch (o) {
00960     case BOT_AND:
00961       {
00962         ViewArray<NegBoolView> xv(home,x.size());
00963         for (int i=0; i<x.size(); i++) {
00964           NegBoolView n(x[i]); xv[i]=n;
00965         }
00966         ViewArray<BoolView> yv(home,y);
00967         xv.unique(); yv.unique();
00968         NegBoolView nz(z);
00969         GECODE_ES_FAIL((Bool::Clause<NegBoolView,BoolView>
00970                         ::post(home,xv,yv,nz)));
00971       }
00972       break;
00973     case BOT_OR:
00974       {
00975         ViewArray<BoolView> xv(home,x);
00976         ViewArray<NegBoolView> yv(home,y.size());
00977         for (int i=0; i<y.size(); i++) {
00978           NegBoolView n(y[i]); yv[i]=n;
00979         }
00980         xv.unique(); yv.unique();
00981         GECODE_ES_FAIL((Bool::Clause<BoolView,NegBoolView>
00982                         ::post(home,xv,yv,z)));
00983       }
00984       break;
00985     default:
00986       throw IllegalOperation("Int::clause");
00987     }
00988   }
00989 
00990   void
00991   ite(Home home, BoolVar b, IntVar x, IntVar y, IntVar z,
00992       IntPropLevel ipl) {
00993     using namespace Int;
00994     GECODE_POST;
00995     if (vbd(ipl) == IPL_BND) {
00996       GECODE_ES_FAIL((Bool::IteBnd<IntView,IntView,IntView>
00997                       ::post(home,b,x,y,z)));
00998     } else {
00999       GECODE_ES_FAIL((Bool::IteDom<IntView,IntView,IntView>
01000                       ::post(home,b,x,y,z)));
01001     }
01002   }
01003 
01004   void
01005   ite(Home home, BoolVar b, BoolVar x, BoolVar y, BoolVar z,
01006       IntPropLevel) {
01007     using namespace Int;
01008     GECODE_POST;
01009     GECODE_ES_FAIL((Bool::IteBnd<BoolView,BoolView,BoolView>
01010                     ::post(home,b,x,y,z)));
01011   }
01012 
01013 }
01014 
01015 // STATISTICS: int-post