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

rel-op-const-vcc.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Contributing authors:
00007  *     Gabor Szokoli <szokoli@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Guido Tack, 2004, 2005
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  Permission is hereby granted, free of charge, to any person obtaining
00017  *  a copy of this software and associated documentation files (the
00018  *  "Software"), to deal in the Software without restriction, including
00019  *  without limitation the rights to use, copy, modify, merge, publish,
00020  *  distribute, sublicense, and/or sell copies of the Software, and to
00021  *  permit persons to whom the Software is furnished to do so, subject to
00022  *  the following conditions:
00023  *
00024  *  The above copyright notice and this permission notice shall be
00025  *  included in all copies or substantial portions of the Software.
00026  *
00027  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00028  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00029  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00030  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00031  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00032  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00033  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00034  *
00035  */
00036 
00037 #include <gecode/set.hh>
00038 #include <gecode/set/rel.hh>
00039 #include <gecode/set/rel-op.hh>
00040 
00041 namespace Gecode {
00042   using namespace Gecode::Set;
00043   using namespace Gecode::Set::Rel;
00044   using namespace Gecode::Set::RelOp;
00045 
00046   void
00047   rel(Home home, SetVar x, SetOpType op, const IntSet& y, SetRelType r,
00048       const IntSet& z) {
00049     Set::Limits::check(y, "Set::rel");
00050     Set::Limits::check(z, "Set::rel");
00051     ConstSetView yv(home, y);
00052     ConstSetView zv(home, z);
00053 
00054     if (op==SOT_MINUS) {
00055       switch (r) {
00056       case SRT_EQ:
00057         {
00058           GlbRanges<ConstSetView> yr(yv);
00059           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00060           IntSet yc(yrc);
00061           ConstSetView cy(home, yc);
00062           GECODE_ES_FAIL(
00063                          (Intersection<ConstSetView,
00064                           SetView,ConstSetView>
00065                           ::post(home,cy,x,zv)));
00066         }
00067         break;
00068       case SRT_LQ: case SRT_LE: case SRT_GQ: case SRT_GR:
00069         {
00070           GlbRanges<ConstSetView> yr(yv);
00071           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00072           IntSet yc(yrc);
00073           ConstSetView cy(home, yc);
00074           SetVar tmp(home,IntSet::empty,Set::Limits::min,Set::Limits::max);
00075           GECODE_ES_FAIL(
00076                          (Intersection<ConstSetView,
00077                           SetView,SetView>
00078                           ::post(home,cy,x,tmp)));
00079           dom(home,tmp,r,z);
00080         }
00081         break;
00082       case SRT_NQ:
00083         {
00084           SetVar tmp(home);
00085           GECODE_ES_FAIL(
00086                          (Distinct<SetView,ConstSetView>
00087                           ::post(home,tmp,zv)));
00088           GlbRanges<ConstSetView> yr(yv);
00089           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00090           IntSet yc(yrc);
00091           ConstSetView cy(home, yc);
00092           GECODE_ES_FAIL(
00093                          (Intersection<ConstSetView,
00094                           SetView,SetView>
00095                           ::post(home,cy,x,tmp)));
00096         }
00097         break;
00098       case SRT_SUB:
00099         {
00100           GlbRanges<ConstSetView> yr(yv);
00101           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00102           IntSet yc(yrc);
00103           ConstSetView cy(home, yc);
00104           GECODE_ES_FAIL(
00105                          (SuperOfInter<ConstSetView,SetView,ConstSetView>
00106                           ::post(home,cy,x,zv)));
00107 
00108         }
00109         break;
00110       case SRT_SUP:
00111         {
00112           // z <= tmp
00113           SetVar tmp(home,z,Limits::min, Limits::max);
00114           SetView xv(x);
00115 
00116           GlbRanges<ConstSetView> yr(yv);
00117           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00118           IntSet yc(yrc);
00119           ConstSetView cy(home, yc);
00120 
00121           GECODE_ES_FAIL(
00122                          (Intersection<ConstSetView,
00123                           SetView,SetView>
00124                           ::post(home,cy,xv,tmp)));
00125         }
00126         break;
00127       case SRT_DISJ:
00128         {
00129           SetVar tmp(home);
00130           SetView tmpv(tmp);
00131           IntSetRanges zi(z);
00132           GECODE_ME_FAIL( tmpv.excludeI(home, zi));
00133 
00134           GlbRanges<ConstSetView> yr(yv);
00135           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00136           IntSet yc(yrc);
00137           ConstSetView cy(home, yc);
00138           GECODE_ES_FAIL(
00139                          (Intersection<ConstSetView,
00140                           SetView,SetView>
00141                           ::post(home,cy,x,tmp)));
00142         }
00143         break;
00144       case SRT_CMPL:
00145         {
00146           SetView xv(x);
00147           ComplementView<SetView> cx(xv);
00148           GECODE_ES_FAIL(
00149                          (Union<ConstSetView,
00150                           ComplementView<SetView>,
00151                           ConstSetView>::post(home, yv, cx, zv)));
00152         }
00153         break;
00154       default:
00155         throw UnknownRelation("Set::rel");
00156       }
00157     } else {
00158       rel(home, y, op, x, r, z);
00159     }
00160   }
00161 
00162 }
00163 
00164 // STATISTICS: set-post