Generated on Mon Jul 6 18:09:18 2009 for Gecode by doxygen 1.5.9

rel-op-const.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: 2009-03-02 10:08:11 +0100 (Mon, 02 Mar 2009) $ by $Author: schulte $
00014  *     $Revision: 8320 $
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(Space& home, const IntSet& x, SetOpType op, SetVar y, SetRelType r,
00052       SetVar z) {
00053     Set::Limits::check(x, "Set::rel");
00054     ConstantView xv(home, x);
00055     rel_op_post<ConstantView,SetView,SetView>(home, xv, op, y, r, z);
00056   }
00057 
00058   void
00059   rel(Space& home, SetVar x, SetOpType op, const IntSet& y, SetRelType r,
00060       SetVar z) {
00061     Set::Limits::check(y, "Set::rel");
00062     ConstantView yv(home, y);
00063 
00064     if (op==SOT_MINUS) {
00065       switch (r) {
00066       case SRT_EQ:
00067         {
00068           GlbRanges<ConstantView> yr(yv);
00069           RangesCompl<GlbRanges<ConstantView> > yrc(yr);
00070           IntSet yc(yrc);
00071           ConstantView cy(home, yc);
00072           GECODE_ES_FAIL(home,
00073                          (Intersection<ConstantView,
00074                           SetView,SetView>
00075                           ::post(home,cy,x,z)));
00076         }
00077         break;
00078       case SRT_NQ:
00079         {
00080           SetVar tmp(home);
00081           GECODE_ES_FAIL(home,
00082                          (Distinct<SetView,SetView>
00083                           ::post(home,z,tmp)));
00084           GlbRanges<ConstantView> yr(yv);
00085           RangesCompl<GlbRanges<ConstantView> > yrc(yr);
00086           IntSet yc(yrc);
00087           ConstantView cy(home, yc);
00088           GECODE_ES_FAIL(home,
00089                          (Intersection<ConstantView,
00090                           SetView,SetView>
00091                           ::post(home,cy,x,tmp)));
00092         }
00093         break;
00094       case SRT_SUB:
00095         {
00096           GlbRanges<ConstantView> yr(yv);
00097           RangesCompl<GlbRanges<ConstantView> > yrc(yr);
00098           IntSet yc(yrc);
00099           ConstantView cy(home, yc);
00100           GECODE_ES_FAIL(home,
00101                          (SuperOfInter<ConstantView,SetView,SetView>
00102                           ::post(home,cy,x,z)));
00103 
00104         }
00105         break;
00106       case SRT_SUP:
00107         {
00108           SetVar tmp(home);
00109           GECODE_ES_FAIL(home,
00110                          (Subset<SetView,SetView>::post(home,z,tmp)));
00111 
00112           GlbRanges<ConstantView> yr(yv);
00113           RangesCompl<GlbRanges<ConstantView> > yrc(yr);
00114           IntSet yc(yrc);
00115           ConstantView cy(home, yc);
00116 
00117           SetView xv(x);
00118           GECODE_ES_FAIL(home,
00119                          (Intersection<ConstantView,
00120                           SetView,SetView>
00121                           ::post(home,cy,xv,tmp)));
00122         }
00123         break;
00124       case SRT_DISJ:
00125         {
00126           SetVar tmp(home);
00127           EmptyView emptyset;
00128           GECODE_ES_FAIL(home,(SuperOfInter<SetView,SetView,EmptyView>
00129                                ::post(home, z, tmp, emptyset)));
00130 
00131           GlbRanges<ConstantView> yr(yv);
00132           RangesCompl<GlbRanges<ConstantView> > yrc(yr);
00133           IntSet yc(yrc);
00134           ConstantView cy(home, yc);
00135           GECODE_ES_FAIL(home,
00136                          (Intersection<ConstantView,
00137                           SetView,SetView>
00138                           ::post(home,cy,x,tmp)));
00139         }
00140         break;
00141       case SRT_CMPL:
00142         {
00143           SetView xv(x);
00144           ComplementView<SetView> cx(xv);
00145           GECODE_ES_FAIL(home,
00146                          (Union<ConstantView,
00147                           ComplementView<SetView>,
00148                           SetView>::post(home, yv, cx, z)));
00149         }
00150         break;
00151       default:
00152         throw UnknownRelation("Set::rel");
00153       }
00154     } else {
00155       rel_op_post<ConstantView,SetView,SetView>(home, yv, op, x, r, z);
00156     }
00157   }
00158 
00159   void
00160   rel(Space& home, SetVar x, SetOpType op, SetVar y, SetRelType r,
00161       const IntSet& z) {
00162     Set::Limits::check(z, "Set::rel");
00163     if (r == SRT_CMPL) {
00164       IntSetRanges zr(z);
00165       RangesCompl<IntSetRanges> zrc(zr);
00166       IntSet zc(zrc);
00167       ConstantView cz(home, zc);
00168       rel_eq<SetView,SetView,ConstantView>(home, x, op, y, cz);
00169     } else {
00170       ConstantView zv(home, z);
00171       rel_op_post_nocompl<SetView,SetView,ConstantView>(home, x, op, y, r, zv);
00172     }
00173   }
00174 
00175   void
00176   rel(Space& home, const IntSet& x, SetOpType op, SetVar y, SetRelType r,
00177       const IntSet& z) {
00178     Set::Limits::check(x, "Set::rel");
00179     Set::Limits::check(z, "Set::rel");
00180     ConstantView xv(home, x);
00181     if (r == SRT_CMPL) {
00182       IntSetRanges zr(z);
00183       RangesCompl<IntSetRanges> zrc(zr);
00184       IntSet zc(zrc);
00185       ConstantView cz(home, zc);
00186       rel_eq<ConstantView,SetView,ConstantView>(home, xv, op, y, cz);
00187     } else {
00188       ConstantView zv(home, z);
00189       rel_op_post_nocompl<ConstantView,SetView,ConstantView>(home, xv, op, y, r, zv);
00190     }
00191   }
00192 
00193   void
00194   rel(Space& home, SetVar x, SetOpType op, const IntSet& y, SetRelType r,
00195       const IntSet& z) {
00196     Set::Limits::check(y, "Set::rel");
00197     Set::Limits::check(z, "Set::rel");
00198     ConstantView yv(home, y);
00199     ConstantView zv(home, z);
00200 
00201     if (op==SOT_MINUS) {
00202       switch (r) {
00203       case SRT_EQ:
00204         {
00205           GlbRanges<ConstantView> yr(yv);
00206           RangesCompl<GlbRanges<ConstantView> > yrc(yr);
00207           IntSet yc(yrc);
00208           ConstantView cy(home, yc);
00209           GECODE_ES_FAIL(home,
00210                          (Intersection<ConstantView,
00211                           SetView,ConstantView>
00212                           ::post(home,cy,x,zv)));
00213         }
00214         break;
00215       case SRT_NQ:
00216         {
00217           SetVar tmp(home);
00218           GECODE_ES_FAIL(home,
00219                          (Distinct<SetView,ConstantView>
00220                           ::post(home,tmp,zv)));
00221           GlbRanges<ConstantView> yr(yv);
00222           RangesCompl<GlbRanges<ConstantView> > yrc(yr);
00223           IntSet yc(yrc);
00224           ConstantView cy(home, yc);
00225           GECODE_ES_FAIL(home,
00226                          (Intersection<ConstantView,
00227                           SetView,SetView>
00228                           ::post(home,cy,x,tmp)));
00229         }
00230         break;
00231       case SRT_SUB:
00232         {
00233           GlbRanges<ConstantView> yr(yv);
00234           RangesCompl<GlbRanges<ConstantView> > yrc(yr);
00235           IntSet yc(yrc);
00236           ConstantView cy(home, yc);
00237           GECODE_ES_FAIL(home,
00238                          (SuperOfInter<ConstantView,SetView,ConstantView>
00239                           ::post(home,cy,x,zv)));
00240 
00241         }
00242         break;
00243       case SRT_SUP:
00244         {
00245           // z <= tmp
00246           SetVar tmp(home,z,Limits::min, Limits::max);
00247           SetView xv(x);
00248 
00249           GlbRanges<ConstantView> yr(yv);
00250           RangesCompl<GlbRanges<ConstantView> > yrc(yr);
00251           IntSet yc(yrc);
00252           ConstantView cy(home, yc);
00253 
00254           GECODE_ES_FAIL(home,
00255                          (Intersection<ConstantView,
00256                           SetView,SetView>
00257                           ::post(home,cy,xv,tmp)));
00258         }
00259         break;
00260       case SRT_DISJ:
00261         {
00262           SetVar tmp(home);
00263           SetView tmpv(tmp);
00264           IntSetRanges zi(z);
00265           GECODE_ME_FAIL(home, tmpv.excludeI(home, zi));
00266 
00267           GlbRanges<ConstantView> yr(yv);
00268           RangesCompl<GlbRanges<ConstantView> > yrc(yr);
00269           IntSet yc(yrc);
00270           ConstantView cy(home, yc);
00271           GECODE_ES_FAIL(home,
00272                          (Intersection<ConstantView,
00273                           SetView,SetView>
00274                           ::post(home,cy,x,tmp)));
00275         }
00276         break;
00277       case SRT_CMPL:
00278         {
00279           SetView xv(x);
00280           ComplementView<SetView> cx(xv);
00281           GECODE_ES_FAIL(home,
00282                          (Union<ConstantView,
00283                           ComplementView<SetView>,
00284                           ConstantView>::post(home, yv, cx, zv)));
00285         }
00286         break;
00287       default:
00288         throw UnknownRelation("Set::rel");
00289       }
00290     } else if (r == SRT_CMPL) {
00291       IntSetRanges zr(z);
00292       RangesCompl<IntSetRanges> zrc(zr);
00293       IntSet zc(zrc);
00294       ConstantView cz(home, zc);
00295       rel_eq<ConstantView,SetView,ConstantView>(home, yv, op, x, cz);
00296     } else {
00297       rel_op_post_nocompl<ConstantView,SetView,ConstantView>(home, yv, op, x, r, zv);
00298     }
00299   }
00300 
00301 }
00302 
00303 // STATISTICS: set-post