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

rel-op-const-vcv.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       SetVar z) {
00049     Set::Limits::check(y, "Set::rel");
00050     ConstSetView yv(home, y);
00051 
00052     if (op==SOT_MINUS) {
00053       switch (r) {
00054       case SRT_EQ:
00055         {
00056           GlbRanges<ConstSetView> yr(yv);
00057           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00058           IntSet yc(yrc);
00059           ConstSetView cy(home, yc);
00060           GECODE_ES_FAIL(
00061                          (Intersection<ConstSetView,
00062                           SetView,SetView>
00063                           ::post(home,cy,x,z)));
00064         }
00065         break;
00066       case SRT_LQ: case SRT_LE: case SRT_GQ: case SRT_GR:
00067         {
00068           GlbRanges<ConstSetView> yr(yv);
00069           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00070           IntSet yc(yrc);
00071           ConstSetView cy(home, yc);
00072           SetVar tmp(home,IntSet::empty,Set::Limits::min,Set::Limits::max);
00073           GECODE_ES_FAIL(
00074                          (Intersection<ConstSetView,
00075                           SetView,SetView>
00076                           ::post(home,cy,x,tmp)));
00077           rel(home,tmp,r,z);
00078         }
00079         break;
00080       case SRT_NQ:
00081         {
00082           SetVar tmp(home);
00083           GECODE_ES_FAIL(
00084                          (Distinct<SetView,SetView>
00085                           ::post(home,z,tmp)));
00086           GlbRanges<ConstSetView> yr(yv);
00087           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00088           IntSet yc(yrc);
00089           ConstSetView cy(home, yc);
00090           GECODE_ES_FAIL(
00091                          (Intersection<ConstSetView,
00092                           SetView,SetView>
00093                           ::post(home,cy,x,tmp)));
00094         }
00095         break;
00096       case SRT_SUB:
00097         {
00098           GlbRanges<ConstSetView> yr(yv);
00099           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00100           IntSet yc(yrc);
00101           ConstSetView cy(home, yc);
00102           GECODE_ES_FAIL(
00103                          (SuperOfInter<ConstSetView,SetView,SetView>
00104                           ::post(home,cy,x,z)));
00105 
00106         }
00107         break;
00108       case SRT_SUP:
00109         {
00110           SetVar tmp(home);
00111           GECODE_ES_FAIL(
00112                          (Subset<SetView,SetView>::post(home,z,tmp)));
00113 
00114           GlbRanges<ConstSetView> yr(yv);
00115           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00116           IntSet yc(yrc);
00117           ConstSetView cy(home, yc);
00118 
00119           SetView xv(x);
00120           GECODE_ES_FAIL(
00121                          (Intersection<ConstSetView,
00122                           SetView,SetView>
00123                           ::post(home,cy,xv,tmp)));
00124         }
00125         break;
00126       case SRT_DISJ:
00127         {
00128           SetVar tmp(home);
00129           EmptyView emptyset;
00130           GECODE_ES_FAIL((SuperOfInter<SetView,SetView,EmptyView>
00131                                ::post(home, z, tmp, emptyset)));
00132 
00133           GlbRanges<ConstSetView> yr(yv);
00134           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00135           IntSet yc(yrc);
00136           ConstSetView cy(home, yc);
00137           GECODE_ES_FAIL(
00138                          (Intersection<ConstSetView,
00139                           SetView,SetView>
00140                           ::post(home,cy,x,tmp)));
00141         }
00142         break;
00143       case SRT_CMPL:
00144         {
00145           SetView xv(x);
00146           ComplementView<SetView> cx(xv);
00147           GECODE_ES_FAIL(
00148                          (Union<ConstSetView,
00149                           ComplementView<SetView>,
00150                           SetView>::post(home, yv, cx, z)));
00151         }
00152         break;
00153       default:
00154         throw UnknownRelation("Set::rel");
00155       }
00156     } else {
00157       rel(home, y, op, x, r, z);
00158     }
00159   }
00160 }
00161 
00162 // STATISTICS: set-post