Generated on Wed Jul 27 2011 15:08:53 for Gecode by doxygen 1.7.4
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: 2010-06-07 14:18:14 +0200 (Mon, 07 Jun 2010) $ by $Author: tack $
00014  *     $Revision: 11048 $
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_NQ:
00071         {
00072           SetVar tmp(home);
00073           GECODE_ES_FAIL(
00074                          (Distinct<SetView,SetView>
00075                           ::post(home,z,tmp)));
00076           GlbRanges<ConstSetView> yr(yv);
00077           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00078           IntSet yc(yrc);
00079           ConstSetView cy(home, yc);
00080           GECODE_ES_FAIL(
00081                          (Intersection<ConstSetView,
00082                           SetView,SetView>
00083                           ::post(home,cy,x,tmp)));
00084         }
00085         break;
00086       case SRT_SUB:
00087         {
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                          (SuperOfInter<ConstSetView,SetView,SetView>
00094                           ::post(home,cy,x,z)));
00095 
00096         }
00097         break;
00098       case SRT_SUP:
00099         {
00100           SetVar tmp(home);
00101           GECODE_ES_FAIL(
00102                          (Subset<SetView,SetView>::post(home,z,tmp)));
00103 
00104           GlbRanges<ConstSetView> yr(yv);
00105           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00106           IntSet yc(yrc);
00107           ConstSetView cy(home, yc);
00108 
00109           SetView xv(x);
00110           GECODE_ES_FAIL(
00111                          (Intersection<ConstSetView,
00112                           SetView,SetView>
00113                           ::post(home,cy,xv,tmp)));
00114         }
00115         break;
00116       case SRT_DISJ:
00117         {
00118           SetVar tmp(home);
00119           EmptyView emptyset;
00120           GECODE_ES_FAIL((SuperOfInter<SetView,SetView,EmptyView>
00121                                ::post(home, z, tmp, emptyset)));
00122 
00123           GlbRanges<ConstSetView> yr(yv);
00124           RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
00125           IntSet yc(yrc);
00126           ConstSetView cy(home, yc);
00127           GECODE_ES_FAIL(
00128                          (Intersection<ConstSetView,
00129                           SetView,SetView>
00130                           ::post(home,cy,x,tmp)));
00131         }
00132         break;
00133       case SRT_CMPL:
00134         {
00135           SetView xv(x);
00136           ComplementView<SetView> cx(xv);
00137           GECODE_ES_FAIL(
00138                          (Union<ConstSetView,
00139                           ComplementView<SetView>,
00140                           SetView>::post(home, yv, cx, z)));
00141         }
00142         break;
00143       default:
00144         throw UnknownRelation("Set::rel");
00145       }
00146     } else {
00147       rel(home, y, op, x, r, z);
00148     }
00149   }
00150 }
00151 
00152 // STATISTICS: set-post