Generated on Tue May 22 09:40:11 2018 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, IntPropLevel) override;
00090     };
00091 
00092     SetIRTRel::SetIRTRel(const SetExpr& s, IntRelType irt, const LinIntExpr& x)
00093       : _s(s), _x(x), _irt(irt) {}
00094 
00095     void
00096     SetIRTRel::post(Home home, BoolVar b, bool neg, IntPropLevel ipl) {
00097       if (b.zero()) {
00098         rel(home, _s.post(home), neg ? _irt : Gecode::neg(_irt),
00099             _x.post(home, ipl));
00100       } else if (b.one()) {
00101         rel(home, _s.post(home), neg ? Gecode::neg(_irt) : _irt, 
00102             _x.post(home, ipl));
00103       } else {
00104         rel(home, _s.post(home), neg ? Gecode::neg(_irt) : _irt,
00105             _x.post(home, ipl), b);
00106       }
00107     }
00108   }
00109 
00110 
00111   /*
00112    * IRT relations with SetExpr
00113    *
00114    */
00115   BoolExpr
00116   operator ==(const SetExpr& x, const LinIntExpr& y) {
00117     return BoolExpr(new SetIRTRel(x, IRT_EQ, y));
00118   }
00119   BoolExpr
00120   operator ==(const LinIntExpr& x, const SetExpr& y) {
00121     return operator ==(y, x);
00122   }
00123 
00124   BoolExpr
00125   operator !=(const SetExpr& x, const LinIntExpr& y) {
00126     return BoolExpr(new SetIRTRel(x, IRT_NQ, y));
00127   }
00128 
00129   BoolExpr
00130   operator !=(const LinIntExpr& x, const SetExpr& y) {
00131     return operator !=(y, x);
00132   }
00133 
00134   BoolExpr
00135   operator <=(const SetExpr& x, const LinIntExpr& y) {
00136     return BoolExpr(new SetIRTRel(x, IRT_LQ, y));
00137   }
00138 
00139   BoolExpr
00140   operator <=(const LinIntExpr& x, const SetExpr& y) {
00141     return operator >=(y, x);
00142   }
00143 
00144   BoolExpr
00145   operator <(const SetExpr& x, const LinIntExpr& y) {
00146     return BoolExpr(new SetIRTRel(x, IRT_LE, y));
00147   }
00148 
00149   BoolExpr
00150   operator <(const LinIntExpr& x, const SetExpr& y) {
00151     return operator >(y, x);
00152   }
00153 
00154   BoolExpr
00155   operator >=(const SetExpr& x, const LinIntExpr& y) {
00156     return BoolExpr(new SetIRTRel(x, IRT_GQ, y));
00157   }
00158 
00159   BoolExpr
00160   operator >=(const LinIntExpr& x, const SetExpr& y) {
00161     return operator <=(y, x);
00162   }
00163 
00164   BoolExpr
00165   operator >(const SetExpr& x, const LinIntExpr& y) {
00166     return BoolExpr(new SetIRTRel(x, IRT_GR, y));
00167   }
00168 
00169   BoolExpr
00170   operator >(const LinIntExpr& x, const SetExpr& y) {
00171     return operator <(y, x);
00172   }
00173 
00174 }
00175 
00176 #endif
00177 
00178 // STATISTICS: minimodel-any