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  *     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: 2008-02-28 14:12:40 +0100 (Thu, 28 Feb 2008) $ by $Author: tack $
00014  *     $Revision: 6344 $
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 
00044 namespace Gecode {
00045 
00046   void
00047   dom(Space* home, SetVar s, SetRelType r, int i) {
00048     Set::Limits::check(i, "Set::dom");
00049     IntSet d(i,i);
00050     dom(home, s, r, d);
00051   }
00052 
00053   void
00054   dom(Space* home, SetVar s, SetRelType r, int i, int j) {
00055     Set::Limits::check(i, "Set::dom");
00056     Set::Limits::check(j, "Set::dom");
00057     IntSet d(i,j);
00058     dom(home, s, r, d);
00059   }
00060 
00061   void
00062   dom(Space* home, SetVar s, SetRelType r, const IntSet& is) {
00063     Set::Limits::check(is, "Set::dom");
00064     if (home->failed()) return;
00065 
00066     Set::SetView _s(s);
00067 
00068     switch(r) {
00069     case SRT_EQ:
00070       {
00071         if (is.size() == 1) {
00072           GECODE_ME_FAIL(home,_s.include(home, is.min(), is.max()));
00073           GECODE_ME_FAIL(home,_s.intersect(home, is.min(), is.max()));
00074         } else {
00075           IntSetRanges rd1(is);
00076           GECODE_ME_FAIL(home,_s.includeI(home, rd1));
00077           IntSetRanges rd2(is);
00078           GECODE_ME_FAIL(home,_s.intersectI(home, rd2));
00079         }
00080       }
00081       break;
00082     case SRT_DISJ:
00083       {
00084         if (is.size() == 1) {
00085           GECODE_ME_FAIL(home,_s.exclude(home, is.min(), is.max()));
00086         } else {
00087           IntSetRanges rd(is);
00088           GECODE_ME_FAIL(home,_s.excludeI(home, rd));
00089         }
00090       }
00091       break;
00092     case SRT_NQ:
00093       {
00094         Set::ConstantView cv(home, is);
00095         GECODE_ES_FAIL(home,
00096                        (Set::Rel::DistinctDoit<Set::SetView>::post(home, s, 
00097                                                                    cv)));
00098       }
00099       break;
00100     case SRT_SUB:
00101       {
00102          if (is.size() == 1) {
00103            GECODE_ME_FAIL(home,_s.intersect(home, is.min(), is.max()));
00104          } else {
00105           IntSetRanges rd(is);
00106           GECODE_ME_FAIL(home,_s.intersectI(home, rd));
00107          }
00108       }
00109       break;
00110     case SRT_SUP:
00111       {
00112         if (is.size() == 1) {
00113           GECODE_ME_FAIL(home,_s.include(home, is.min(), is.max()));
00114         } else {
00115           IntSetRanges rd(is);
00116           GECODE_ME_FAIL(home,_s.includeI(home, rd));
00117         }
00118       }
00119       break;
00120     case SRT_CMPL:
00121       {
00122         if (is.size() == 1) {
00123           GECODE_ME_FAIL(home,_s.exclude(home, is.min(), is.max()));
00124           GECODE_ME_FAIL(home,
00125                          _s.include(home,
00126                                     Set::Limits::min,
00127                                     is.min()-1) );
00128           GECODE_ME_FAIL(home,
00129                          _s.include(home, is.max()+1,
00130                                     Set::Limits::max) );
00131         } else {
00132           IntSetRanges rd1(is);
00133           Set::RangesCompl<IntSetRanges > rdC1(rd1);
00134           GECODE_ME_FAIL(home,_s.includeI(home, rdC1));
00135           IntSetRanges rd2(is);
00136           Set::RangesCompl<IntSetRanges > rdC2(rd2);
00137           GECODE_ME_FAIL(home,_s.intersectI(home, rdC2));
00138         }
00139       }
00140       break;
00141     }
00142   }
00143 
00144   void
00145   dom(Space* home, SetVar s, SetRelType r, int i, BoolVar b) {
00146     Set::Limits::check(i, "Set::dom");
00147     IntSet d(i,i);
00148     dom(home, s, r, d, b);
00149   }
00150 
00151   void
00152   dom(Space* home, SetVar s, SetRelType r, int i, int j, BoolVar b) {
00153     Set::Limits::check(i, "Set::dom");
00154     Set::Limits::check(j, "Set::dom");
00155     IntSet d(i,j);
00156     dom(home, s, r, d, b);
00157   }
00158 
00159   void
00160   dom(Space* home, SetVar s, SetRelType r, const IntSet& is, BoolVar b) {
00161     Set::Limits::check(is, "Set::dom");
00162     if (home->failed()) return;
00163     switch(r) {
00164     case SRT_EQ:
00165       {
00166         Set::ConstantView cv(home, is);
00167         GECODE_ES_FAIL(home,
00168                        (Set::Rel::ReEq<Set::SetView,
00169                         Set::ConstantView>::post(home, s, cv, b)));
00170       }
00171       break;
00172     case SRT_NQ:
00173       {
00174         BoolVar notb(home,0,1);
00175         rel(home, b, IRT_NQ, notb);
00176         Set::ConstantView cv(home, is);
00177         GECODE_ES_FAIL(home,
00178                        (Set::Rel::ReEq<Set::SetView,
00179                         Set::ConstantView>::post(home, s, cv, notb)));
00180       }
00181       break;
00182     case SRT_SUB:
00183       {
00184         Set::ConstantView cv(home, is);
00185         GECODE_ES_FAIL(home,
00186                        (Set::Rel::ReSubset<Set::SetView,Set::ConstantView>
00187                         ::post(home, s, cv, b)));
00188       }
00189       break;
00190     case SRT_SUP:
00191       {
00192         Set::ConstantView cv(home, is);
00193         GECODE_ES_FAIL(home,
00194                        (Set::Rel::ReSubset<Set::ConstantView,Set::SetView>
00195                         ::post(home, cv, s, b)));
00196       }
00197       break;
00198     case SRT_DISJ:
00199       {
00200         // x||y <=> b is equivalent to
00201         // ( y <= complement(x) and x<=complement(y) ) <=> b
00202 
00203         // compute complement of is
00204         IntSetRanges dr1(is);
00205         Set::RangesCompl<IntSetRanges > dc1(dr1);
00206         IntSet dcompl(dc1);
00207         Set::ConstantView cvcompl(home, dcompl);
00208         GECODE_ES_FAIL(home,
00209                        (Set::Rel::ReSubset<Set::SetView,Set::ConstantView>
00210                         ::post(home, s, cvcompl, b)));
00211       }
00212       break;
00213     case SRT_CMPL:
00214       {
00215         Set::SetView sv(s);
00216         
00217         IntSetRanges dr1(is);
00218         Set::RangesCompl<IntSetRanges> dc1(dr1);
00219         IntSet dcompl(dc1);
00220         Set::ConstantView cvcompl(home, dcompl);
00221         
00222         GECODE_ES_FAIL(home,
00223                        (Set::Rel::ReEq<Set::SetView,Set::ConstantView>
00224                         ::post(home, sv, cvcompl, b)));
00225       }
00226       break;
00227     }
00228   }
00229 
00230 }
00231 
00232 // STATISTICS: set-post