Generated on Thu Apr 11 13:59:17 2019 for Gecode by doxygen 1.6.3

set-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  *     Matthias Balzer <matthias.balzer@itwm.fraunhofer.de>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2005
00009  *     Fraunhofer ITWM, 2017
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/minimodel.hh>
00037 
00038 #ifdef GECODE_HAS_SET_VARS
00039 
00040 namespace Gecode {
00041 
00042   /*
00043    * Operators
00044    *
00045    */
00046   SetRel
00047   operator ==(const SetExpr& e0, const SetExpr& e1) {
00048     return SetRel(e0, SRT_EQ, e1);
00049   }
00050   SetRel
00051   operator !=(const SetExpr& e0, const SetExpr& e1) {
00052     return SetRel(e0, SRT_NQ, e1);
00053   }
00054   SetCmpRel
00055   operator <=(const SetExpr& e0, const SetExpr& e1) {
00056     return SetCmpRel(e0, SRT_SUB, e1);
00057   }
00058   BoolExpr
00059   operator <=(const SetCmpRel& r, const SetExpr& l) {
00060     return BoolExpr(r) && BoolExpr(r.r <= l);
00061   }
00062   SetCmpRel
00063   operator >=(const SetExpr& e0, const SetExpr& e1) {
00064     return SetCmpRel(e0, SRT_SUP, e1);
00065   }
00066   BoolExpr
00067   operator >=(const SetCmpRel& r, const SetExpr& l) {
00068     return BoolExpr(r) && BoolExpr(r.r >= l);
00069   }
00070   SetRel
00071   operator ||(const SetExpr& e0, const SetExpr& e1) {
00072     return SetRel(e0, SRT_DISJ, e1);
00073   }
00074 
00075   namespace {
00076 
00078     class SetIRTRel : public BoolExpr::Misc {
00080       SetExpr _s;
00082       LinIntExpr _x;
00084       IntRelType _irt;
00085     public:
00087       SetIRTRel(const SetExpr&, IntRelType, const LinIntExpr&);
00089       virtual void post(Home, BoolVar b, bool neg,
00090                         const IntPropLevels&) override;
00091     };
00092 
00093     SetIRTRel::SetIRTRel(const SetExpr& s, IntRelType irt, const LinIntExpr& x)
00094       : _s(s), _x(x), _irt(irt) {}
00095 
00096     void
00097     SetIRTRel::post(Home home, BoolVar b, bool neg,
00098                     const IntPropLevels& ipls) {
00099       if (b.zero()) {
00100         rel(home, _s.post(home), neg ? _irt : Gecode::neg(_irt),
00101             _x.post(home, ipls));
00102       } else if (b.one()) {
00103         rel(home, _s.post(home), neg ? Gecode::neg(_irt) : _irt, 
00104             _x.post(home, ipls));
00105       } else {
00106         rel(home, _s.post(home), neg ? Gecode::neg(_irt) : _irt,
00107             _x.post(home, ipls), b);
00108       }
00109     }
00110   }
00111 
00112 
00113   /*
00114    * IRT relations with SetExpr
00115    *
00116    */
00117   BoolExpr
00118   operator ==(const SetExpr& x, const LinIntExpr& y) {
00119     return BoolExpr(new SetIRTRel(x, IRT_EQ, y));
00120   }
00121   BoolExpr
00122   operator ==(const LinIntExpr& x, const SetExpr& y) {
00123     return operator ==(y, x);
00124   }
00125 
00126   BoolExpr
00127   operator !=(const SetExpr& x, const LinIntExpr& y) {
00128     return BoolExpr(new SetIRTRel(x, IRT_NQ, y));
00129   }
00130 
00131   BoolExpr
00132   operator !=(const LinIntExpr& x, const SetExpr& y) {
00133     return operator !=(y, x);
00134   }
00135 
00136   BoolExpr
00137   operator <=(const SetExpr& x, const LinIntExpr& y) {
00138     return BoolExpr(new SetIRTRel(x, IRT_LQ, y));
00139   }
00140 
00141   BoolExpr
00142   operator <=(const LinIntExpr& x, const SetExpr& y) {
00143     return operator >=(y, x);
00144   }
00145 
00146   BoolExpr
00147   operator <(const SetExpr& x, const LinIntExpr& y) {
00148     return BoolExpr(new SetIRTRel(x, IRT_LE, y));
00149   }
00150 
00151   BoolExpr
00152   operator <(const LinIntExpr& x, const SetExpr& y) {
00153     return operator >(y, x);
00154   }
00155 
00156   BoolExpr
00157   operator >=(const SetExpr& x, const LinIntExpr& y) {
00158     return BoolExpr(new SetIRTRel(x, IRT_GQ, y));
00159   }
00160 
00161   BoolExpr
00162   operator >=(const LinIntExpr& x, const SetExpr& y) {
00163     return operator <=(y, x);
00164   }
00165 
00166   BoolExpr
00167   operator >(const SetExpr& x, const LinIntExpr& y) {
00168     return BoolExpr(new SetIRTRel(x, IRT_GR, y));
00169   }
00170 
00171   BoolExpr
00172   operator >(const LinIntExpr& x, const SetExpr& y) {
00173     return operator <(y, x);
00174   }
00175 
00176 }
00177 
00178 #endif
00179 
00180 // STATISTICS: minimodel-any