Generated on Fri Oct 19 11:24:56 2018 for Gecode by doxygen 1.6.3

rel.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  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2002
00009  *     Vincent Barichard, 2012
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 #include <gecode/float/rel.hh>
00037 
00038 #include <algorithm>
00039 
00040 namespace Gecode {
00041 
00042   void
00043   rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n) {
00044     using namespace Float;
00045     Limits::check(n,"Float::rel");
00046     GECODE_POST;
00047     FloatView x(x0);
00048     switch (frt) {
00049     case FRT_EQ: GECODE_ME_FAIL(x.eq(home,n)); break;
00050     case FRT_NQ:
00051       GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,x,n)));
00052       break;
00053     case FRT_LQ: GECODE_ME_FAIL(x.lq(home,n)); break;
00054     case FRT_LE:
00055       GECODE_ME_FAIL(x.lq(home,n));
00056       GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,x,n)));
00057       break;
00058     case FRT_GQ: GECODE_ME_FAIL(x.gq(home,n)); break;
00059     case FRT_GR:
00060       GECODE_ME_FAIL(x.gq(home,n));
00061       GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,x,n)));
00062       break;
00063     default: throw UnknownRelation("Float::rel");
00064     }
00065   }
00066 
00067   void
00068   rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1) {
00069     using namespace Float;
00070     GECODE_POST;
00071     switch (frt) {
00072     case FRT_EQ:
00073       GECODE_ES_FAIL((Rel::Eq<FloatView,FloatView>::post(home,x0,x1)));
00074       break;
00075     case FRT_NQ:
00076       GECODE_ES_FAIL((Rel::Nq<FloatView,FloatView>::post(home,x0,x1)));
00077       break;
00078     case FRT_GQ:
00079       std::swap(x0,x1); // Fall through
00080     case FRT_LQ:
00081       GECODE_ES_FAIL((Rel::Lq<FloatView>::post(home,x0,x1))); break;
00082     case FRT_GR:
00083       std::swap(x0,x1); // Fall through
00084     case FRT_LE:
00085       GECODE_ES_FAIL((Rel::Le<FloatView>::post(home,x0,x1))); break;
00086     default:
00087       throw UnknownRelation("Float::rel");
00088     }
00089   }
00090 
00091   void
00092   rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1, Reify r) {
00093     using namespace Float;
00094     GECODE_POST;
00095     switch (frt) {
00096     case FRT_EQ:
00097       switch (r.mode()) {
00098       case RM_EQV:
00099         GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::BoolView,RM_EQV>::
00100                              post(home,x0,x1,r.var())));
00101         break;
00102       case RM_IMP:
00103         GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::BoolView,RM_IMP>::
00104                              post(home,x0,x1,r.var())));
00105         break;
00106       case RM_PMI:
00107         GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::BoolView,RM_PMI>::
00108                              post(home,x0,x1,r.var())));
00109         break;
00110       default: throw Int::UnknownReifyMode("Float::rel");
00111       }
00112       break;
00113     case FRT_NQ:
00114     {
00115       Int::NegBoolView n(r.var());
00116       switch (r.mode()) {
00117       case RM_EQV:
00118         GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::NegBoolView,RM_EQV>::
00119                              post(home,x0,x1,n)));
00120         break;
00121       case RM_IMP:
00122         GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::NegBoolView,RM_PMI>::
00123                              post(home,x0,x1,n)));
00124         break;
00125       case RM_PMI:
00126         GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::NegBoolView,RM_IMP>::
00127                              post(home,x0,x1,n)));
00128         break;
00129       default: throw Int::UnknownReifyMode("Float::rel");
00130       }
00131       break;
00132     }
00133     case FRT_GQ:
00134       std::swap(x0,x1); // Fall through
00135     case FRT_LQ:
00136       switch (r.mode()) {
00137       case RM_EQV:
00138         GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::BoolView,RM_EQV>::
00139                              post(home,x0,x1,r.var())));
00140         break;
00141       case RM_IMP:
00142         GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::BoolView,RM_IMP>::
00143                              post(home,x0,x1,r.var())));
00144         break;
00145       case RM_PMI:
00146         GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::BoolView,RM_PMI>::
00147                              post(home,x0,x1,r.var())));
00148         break;
00149       default: throw Int::UnknownReifyMode("Float::rel");
00150       }
00151       break;
00152     case FRT_LE:
00153       std::swap(x0,x1); // Fall through
00154     case FRT_GR:
00155     {
00156       Int::NegBoolView n(r.var());
00157       switch (r.mode()) {
00158       case RM_EQV:
00159         GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::NegBoolView,RM_EQV>::
00160                              post(home,x0,x1,n)));
00161         break;
00162       case RM_IMP:
00163         GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::NegBoolView,RM_PMI>::
00164                              post(home,x0,x1,n)));
00165         break;
00166       case RM_PMI:
00167         GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::NegBoolView,RM_IMP>::
00168                              post(home,x0,x1,n)));
00169         break;
00170       default: throw Int::UnknownReifyMode("Float::rel");
00171       }
00172       break;
00173     }
00174     default:
00175       throw Int::UnknownRelation("Float::rel");
00176     }
00177   }
00178 
00179   void
00180   rel(Home home, FloatVar x, FloatRelType frt, FloatVal n, Reify r) {
00181     using namespace Float;
00182     Limits::check(n,"Float::rel");
00183     GECODE_POST;
00184     switch (frt) {
00185     case FRT_EQ:
00186       switch (r.mode()) {
00187       case RM_EQV:
00188         GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_EQV>::
00189                              post(home,x,n,r.var())));
00190         break;
00191       case RM_IMP:
00192         GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_IMP>::
00193                              post(home,x,n,r.var())));
00194         break;
00195       case RM_PMI:
00196         GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_PMI>::
00197                              post(home,x,n,r.var())));
00198         break;
00199       default: throw Int::UnknownReifyMode("Float::rel");
00200       }
00201       break;
00202     case FRT_NQ:
00203     {
00204       Int::NegBoolView nb(r.var());
00205       switch (r.mode()) {
00206       case RM_EQV:
00207         GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::NegBoolView,RM_EQV>::
00208                              post(home,x,n,nb)));
00209         break;
00210       case RM_IMP:
00211         GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::NegBoolView,RM_PMI>::
00212                              post(home,x,n,nb)));
00213         break;
00214       case RM_PMI:
00215         GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::NegBoolView,RM_IMP>::
00216                              post(home,x,n,nb)));
00217         break;
00218       default: throw Int::UnknownReifyMode("Float::rel");
00219       }
00220       break;
00221     }
00222     case FRT_LQ:
00223       switch (r.mode()) {
00224       case RM_EQV:
00225         GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::BoolView,RM_EQV>::
00226                              post(home,x,n,r.var())));
00227         break;
00228       case RM_IMP:
00229         GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::BoolView,RM_IMP>::
00230                              post(home,x,n,r.var())));
00231         break;
00232       case RM_PMI:
00233         GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::BoolView,RM_PMI>::
00234                              post(home,x,n,r.var())));
00235         break;
00236       default: throw Int::UnknownReifyMode("Float::rel");
00237       }
00238       break;
00239     case FRT_LE:
00240       switch (r.mode()) {
00241       case RM_EQV:
00242         GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::BoolView,RM_EQV>::
00243                              post(home,x,n,r.var())));
00244         break;
00245       case RM_IMP:
00246         GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::BoolView,RM_IMP>::
00247                              post(home,x,n,r.var())));
00248         break;
00249       case RM_PMI:
00250         GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::BoolView,RM_PMI>::
00251                              post(home,x,n,r.var())));
00252         break;
00253       default: throw Int::UnknownReifyMode("Float::rel");
00254       }
00255       break;
00256     case FRT_GQ:
00257     {
00258       Int::NegBoolView nb(r.var());
00259       switch (r.mode()) {
00260       case RM_EQV:
00261         GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::NegBoolView,RM_EQV>::
00262                              post(home,x,n,nb)));
00263         break;
00264       case RM_IMP:
00265         GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::NegBoolView,RM_PMI>::
00266                              post(home,x,n,nb)));
00267         break;
00268       case RM_PMI:
00269         GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::NegBoolView,RM_IMP>::
00270                              post(home,x,n,nb)));
00271         break;
00272       default: throw Int::UnknownReifyMode("Float::rel");
00273       }
00274       break;
00275     }
00276     case FRT_GR:
00277     {
00278       Int::NegBoolView nb(r.var());
00279       switch (r.mode()) {
00280       case RM_EQV:
00281         GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::NegBoolView,RM_EQV>::
00282                              post(home,x,n,nb)));
00283         break;
00284       case RM_IMP:
00285         GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::NegBoolView,RM_PMI>::
00286                              post(home,x,n,nb)));
00287         break;
00288       case RM_PMI:
00289         GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::NegBoolView,RM_IMP>::
00290                              post(home,x,n,nb)));
00291         break;
00292       default: throw Int::UnknownReifyMode("Float::rel");
00293       }
00294       break;
00295     }
00296     default:
00297       throw Int::UnknownRelation("Float::rel");
00298     }
00299   }
00300 
00301   void
00302   rel(Home home, const FloatVarArgs& x, FloatRelType frt, FloatVal c) {
00303     using namespace Float;
00304     Limits::check(c,"Float::rel");
00305     GECODE_POST;
00306     switch (frt) {
00307     case FRT_EQ:
00308       for (int i=x.size(); i--; ) {
00309         FloatView xi(x[i]); GECODE_ME_FAIL(xi.eq(home,c));
00310       }
00311       break;
00312     case FRT_NQ:
00313       for (int i=x.size(); i--; ) {
00314         FloatView xi(x[i]); GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,xi,c)));
00315       }
00316       break;
00317     case FRT_LQ:
00318       for (int i=x.size(); i--; ) {
00319         FloatView xi(x[i]); GECODE_ME_FAIL(xi.lq(home,c));
00320       }
00321       break;
00322     case FRT_LE:
00323       for (int i=x.size(); i--; ) {
00324         FloatView xi(x[i]); GECODE_ME_FAIL(xi.lq(home,c));
00325         GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,xi,c)));
00326       }
00327       break;
00328     case FRT_GQ:
00329       for (int i=x.size(); i--; ) {
00330         FloatView xi(x[i]); GECODE_ME_FAIL(xi.gq(home,c));
00331       }
00332       break;
00333     case FRT_GR:
00334       for (int i=x.size(); i--; ) {
00335         FloatView xi(x[i]); GECODE_ME_FAIL(xi.gq(home,c));
00336         GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,xi,c)));
00337       }
00338       break;
00339     default:
00340       throw UnknownRelation("Float::rel");
00341     }
00342   }
00343 
00344   void
00345   rel(Home home, const FloatVarArgs& x, FloatRelType frt, FloatVar y) {
00346     using namespace Float;
00347     GECODE_POST;
00348     switch (frt) {
00349     case FRT_EQ:
00350       for (int i=x.size(); i--; ) {
00351         GECODE_ES_FAIL((Rel::Eq<FloatView,FloatView>::post(home,y,x[i])));
00352       }
00353       break;
00354     case FRT_NQ:
00355       for (int i=x.size(); i--; ) {
00356         GECODE_ES_FAIL((Rel::Nq<FloatView,FloatView>::post(home,y,x[i])));
00357       }
00358       break;
00359     case FRT_GQ:
00360       for (int i=x.size(); i--; ) {
00361         GECODE_ES_FAIL((Rel::Lq<FloatView>::post(home,y,x[i])));
00362       }
00363       break;
00364     case FRT_GR:
00365       for (int i=x.size(); i--; ) {
00366         GECODE_ES_FAIL((Rel::Le<FloatView>::post(home,y,x[i])));
00367       }
00368       break;
00369     case FRT_LQ:
00370       for (int i=x.size(); i--; ) {
00371         GECODE_ES_FAIL((Rel::Lq<FloatView>::post(home,x[i],y)));
00372       }
00373       break;
00374     case FRT_LE:
00375       for (int i=x.size(); i--; ) {
00376         GECODE_ES_FAIL((Rel::Le<FloatView>::post(home,x[i],y)));
00377       }
00378       break;
00379     default:
00380       throw UnknownRelation("Float::rel");
00381     }
00382   }
00383 }
00384 
00385 // STATISTICS: float-post