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

dom.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, 2013
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 
00035 #include <gecode/float/rel.hh>
00036 
00037 namespace Gecode {
00038 
00039   void
00040   dom(Home home, FloatVar x, FloatVal n) {
00041     using namespace Float;
00042     Limits::check(n,"Float::dom");
00043     GECODE_POST;
00044     FloatView xv(x);
00045     GECODE_ME_FAIL(xv.eq(home,n));
00046   }
00047 
00048   void
00049   dom(Home home, const FloatVarArgs& x, FloatVal n) {
00050     using namespace Float;
00051     Limits::check(n,"Float::dom");
00052     GECODE_POST;
00053     for (int i=x.size(); i--; ) {
00054       FloatView xv(x[i]);
00055       GECODE_ME_FAIL(xv.eq(home,n));
00056     }
00057   }
00058 
00059   void
00060   dom(Home home, FloatVar x, FloatNum min, FloatNum max) {
00061     using namespace Float;
00062     Limits::check(min,"Float::dom");
00063     Limits::check(max,"Float::dom");
00064     GECODE_POST;
00065     FloatView xv(x);
00066     GECODE_ME_FAIL(xv.gq(home,min));
00067     GECODE_ME_FAIL(xv.lq(home,max));
00068   }
00069 
00070   void
00071   dom(Home home, const FloatVarArgs& x, FloatNum min, FloatNum max) {
00072     using namespace Float;
00073     Limits::check(min,"Float::dom");
00074     Limits::check(max,"Float::dom");
00075     GECODE_POST;
00076     for (int i=x.size(); i--; ) {
00077       FloatView xv(x[i]);
00078       GECODE_ME_FAIL(xv.gq(home,min));
00079       GECODE_ME_FAIL(xv.lq(home,max));
00080     }
00081   }
00082 
00083   void
00084   dom(Home home, FloatVar x, FloatVal n, Reify r) {
00085     using namespace Float;
00086     Limits::check(n,"Float::dom");
00087     GECODE_POST;
00088     switch (r.mode()) {
00089     case RM_EQV:
00090       GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_EQV>
00091                       ::post(home,x,n,r.var())));
00092       break;
00093     case RM_IMP:
00094       GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_IMP>
00095                       ::post(home,x,n,r.var())));
00096       break;
00097     case RM_PMI:
00098       GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_PMI>
00099                       ::post(home,x,n,r.var())));
00100       break;
00101     default: throw Int::UnknownReifyMode("Float::dom");
00102     }
00103   }
00104 
00105   void
00106   dom(Home home, FloatVar x, FloatNum min, FloatNum max, Reify r) {
00107     using namespace Float;
00108     if (min > max) {
00109       Int::BoolView b(r.var());
00110       switch (r.mode()) {
00111       case RM_EQV:
00112       case RM_IMP:
00113         GECODE_ME_FAIL(b.zero(home));
00114         break;
00115       case RM_PMI:
00116         break;
00117       default: throw Int::UnknownReifyMode("Float::dom");
00118       }
00119     } else {
00120       FloatVal n(min,max);
00121       dom(home,x,n,r);
00122     }
00123   }
00124 
00125   void
00126   dom(Home home, FloatVar x, FloatVar d) {
00127     using namespace Float;
00128     GECODE_POST;
00129     FloatView xv(x), dv(d);
00130     if (xv != dv) {
00131       GECODE_ME_FAIL(xv.lq(home,dv.max()));
00132       GECODE_ME_FAIL(xv.gq(home,dv.min()));
00133     }
00134   }
00135 
00136   void
00137   dom(Home home, const FloatVarArgs& x, const FloatVarArgs& d) {
00138     using namespace Float;
00139     if (x.size() != d.size())
00140       throw ArgumentSizeMismatch("Float::dom");
00141     for (int i=x.size(); i--; ) {
00142       GECODE_POST;
00143       FloatView xv(x[i]), dv(d[i]);
00144       if (xv != dv) {
00145         GECODE_ME_FAIL(xv.lq(home,dv.max()));
00146         GECODE_ME_FAIL(xv.gq(home,dv.min()));
00147       }
00148     }
00149   }
00150 
00151 }
00152 
00153 // STATISTICS: float-post
00154