Generated on Mon Aug 25 11:35:33 2008 for Gecode by doxygen 1.5.6

dom.cc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Patrick Pekczynski <pekczynski@ps.uni-sb.de>
00005  *
00006  *  Copyright:
00007  *     Patrick Pekczynski, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-06 18:48:22 +0100 (Wed, 06 Feb 2008) $ by $Author: schulte $
00011  *     $Revision: 6102 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include "gecode/cpltset.hh"
00039 
00040 namespace Gecode {
00041   
00042   void 
00043   dom(Space* home, CpltSetVar x, SetRelType r, const IntSet& s) {
00044     Set::Limits::check(s, "CpltSet::dom");
00045     if (home->failed()) return;
00046     CpltSet::CpltSetView bv(x);
00047 
00048     switch(r) {
00049     case SRT_EQ:
00050       {
00051         if (s.size() == 1) {
00052           GECODE_ME_FAIL(home, bv.eq(home, s.min(), s.max()));
00053         } else {
00054           IntSetRanges ir(s);
00055           GECODE_ME_FAIL(home,bv.eqI(home, ir));
00056         }
00057       }
00058       break;
00059     case SRT_DISJ:
00060       {
00061         if (s.size() == 1) {
00062           GECODE_ME_FAIL(home,bv.exclude(home, s.min(), s.max()));
00063         } else {
00064           IntSetRanges rd(s);
00065           GECODE_ME_FAIL(home,bv.excludeI(home, rd));
00066         }
00067       }
00068       break;
00069     case SRT_NQ:
00070       {
00071         if (s.size() == 1) {
00072           GECODE_ME_FAIL(home, bv.nq(home, s.min(), s.max()));
00073         } else {
00074           IntSetRanges ir(s);
00075           GECODE_ME_FAIL(home, bv.nqI(home, ir));
00076         }
00077       }
00078       break;
00079     case SRT_SUB:
00080       {
00081          if (s.size() == 1) {
00082            GECODE_ME_FAIL(home,bv.intersect(home, s.min(), s.max()));
00083          } else {
00084            IntSetRanges rd(s);
00085            GECODE_ME_FAIL(home,bv.intersectI(home, rd));
00086          }
00087       }
00088       break;
00089     case SRT_SUP:
00090       {
00091         if (s.size() == 1) {
00092           GECODE_ME_FAIL(home,bv.include(home, s.min(), s.max()));
00093         } else {
00094           IntSetRanges rd(s);
00095           GECODE_ME_FAIL(home,bv.includeI(home, rd));
00096         }
00097       }
00098       break;
00099     case SRT_CMPL:
00100       {
00101         if (s.size() == 1) {
00102           GECODE_ME_FAIL(home,bv.exclude(home, s.min(), s.max()));
00103           GECODE_ME_FAIL(home,
00104                          bv.include(home,
00105                                     Set::Limits::min,
00106                                     s.min()-1) );
00107           GECODE_ME_FAIL(home,
00108                          bv.include(home, s.max()+1,
00109                                     Set::Limits::max) );
00110         } else {
00111           IntSetRanges rd1(s);
00112           Iter::Ranges::Compl<Set::Limits::min, 
00113             Set::Limits::max, IntSetRanges > rdC1(rd1);
00114           GECODE_ME_FAIL(home,bv.includeI(home, rdC1));
00115           IntSetRanges rd2(s);
00116           Iter::Ranges::Compl<Set::Limits::min, 
00117             Set::Limits::max, IntSetRanges > rdC2(rd2);
00118           GECODE_ME_FAIL(home,bv.intersectI(home, rdC2));
00119         }
00120       }
00121       break;
00122     default:
00123       {
00124         // could implement here lex ordering constraints s < 1 or something
00125         // thats nice
00126         throw CpltSet::InvalidRelation("rel lex not implemented");
00127         return;
00128       }
00129     }
00130   }
00131 
00132   void
00133   dom(Space* home, CpltSetVar x, SetRelType r, int i) {
00134     IntSet d(i,i);
00135     dom(home, x, r, d);
00136   }
00137 
00138   void
00139   dom(Space* home, CpltSetVar x, SetRelType r, int i, int j) {
00140     IntSet d(i,j);
00141     dom(home, x, r, d);
00142   }
00143 
00144 
00145 }
00146 
00147 // STATISTICS: cpltset-post