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