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