Generated on Wed Nov 1 15:04:33 2006 for Gecode by doxygen 1.4.5

dom.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Contributing authors:
00006  *     Gabor Szokoli <szokoli@gecode.org>
00007  *
00008  *  Copyright:
00009  *     Guido Tack, 2004, 2005
00010  *
00011  *  Last modified:
00012  *     $Date: 2006-04-11 15:58:37 +0200 (Tue, 11 Apr 2006) $ by $Author: tack $
00013  *     $Revision: 3188 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  See the file "LICENSE" for information on usage and
00020  *  redistribution of this file, and for a
00021  *     DISCLAIMER OF ALL WARRANTIES.
00022  *
00023  */
00024 
00025 #include "gecode/set.hh"
00026 #include "gecode/iter.hh"
00027 #include "gecode/set/rel.hh"
00028 
00029 namespace Gecode {
00030 
00031   void
00032   dom(Space* home, SetVar s, SetRelType r, int i) {
00033     IntSet d(i,i);
00034     dom(home, s, r, d);
00035   }
00036 
00037   void
00038   dom(Space* home, SetVar s, SetRelType r, int i, int j) {
00039     IntSet d(i,j);
00040     dom(home, s, r, d);
00041   }
00042 
00043   void
00044   dom(Space* home, SetVar s, SetRelType r, const IntSet& is) {
00045     if (home->failed()) return;
00046 
00047     Set::SetView _s(s);
00048 
00049     switch(r) {
00050     case SRT_EQ:
00051       {
00052         if (is.size() == 1) {
00053           GECODE_ME_FAIL(home,_s.include(home, is.min(), is.max()));
00054           GECODE_ME_FAIL(home,_s.intersect(home, is.min(), is.max()));
00055         } else {
00056           IntSetRanges rd1(is);
00057           GECODE_ME_FAIL(home,_s.includeI(home, rd1));
00058           IntSetRanges rd2(is);
00059           GECODE_ME_FAIL(home,_s.intersectI(home, rd2));
00060         }
00061       }
00062       break;
00063     case SRT_DISJ:
00064       {
00065         if (is.size() == 1) {
00066           GECODE_ME_FAIL(home,_s.exclude(home, is.min(), is.max()));
00067         } else {
00068           IntSetRanges rd(is);
00069           GECODE_ME_FAIL(home,_s.excludeI(home, rd));
00070         }
00071       }
00072       break;
00073     case SRT_NQ:
00074         if (is.size() == 1) {
00075           GECODE_ME_FAIL(home,_s.exclude(home, is.min(), is.max()));
00076         } else {
00077           Set::ConstantView cv(home, is);
00078           GECODE_ES_FAIL(home,
00079                          (Set::Rel::Distinct<Set::SetView,
00080                           Set::ConstantView>::post(home, s, cv)));
00081         }
00082       break;
00083     case SRT_SUB:
00084       {
00085         if (is.size() == 1) {
00086           GECODE_ME_FAIL(home,_s.intersect(home, is.min(), is.max()));
00087         } else {
00088           IntSetRanges rd(is);
00089           GECODE_ME_FAIL(home,_s.intersectI(home, rd));
00090         }
00091       }
00092       break;
00093     case SRT_SUP:
00094       {
00095         if (is.size() == 1) {
00096           GECODE_ME_FAIL(home,_s.include(home, is.min(), is.max()));
00097         } else {
00098           IntSetRanges rd(is);
00099           GECODE_ME_FAIL(home,_s.includeI(home, rd));
00100         }
00101       }
00102       break;
00103     case SRT_CMPL:
00104       {
00105         if (is.size() == 1) {
00106           GECODE_ME_FAIL(home,_s.exclude(home, is.min(), is.max()));
00107           GECODE_ME_FAIL(home,
00108                          _s.include(home,
00109                                     Limits::Set::int_min,
00110                                     is.min()-1) );
00111           GECODE_ME_FAIL(home,
00112                          _s.include(home, is.max()+1,
00113                                     Limits::Set::int_max) );
00114         } else {
00115           IntSetRanges rd1(is);
00116           Set::RangesCompl<IntSetRanges > rdC1(rd1);
00117           GECODE_ME_FAIL(home,_s.includeI(home, rdC1));
00118           IntSetRanges rd2(is);
00119           Set::RangesCompl<IntSetRanges > rdC2(rd2);
00120           GECODE_ME_FAIL(home,_s.intersectI(home, rdC2));
00121         }
00122       }
00123       break;
00124     }
00125   }
00126 
00127   void
00128   dom(Space* home, SetVar s, SetRelType r, int i, BoolVar b) {
00129     IntSet d(i,i);
00130     dom(home, s, r, d, b);
00131   }
00132 
00133   void
00134   dom(Space* home, SetVar s, SetRelType r, int i, int j, BoolVar b) {
00135     IntSet d(i,j);
00136     dom(home, s, r, d, b);
00137   }
00138 
00139   void
00140   dom(Space* home, SetVar s, SetRelType r, const IntSet& is, BoolVar b) {
00141     if (home->failed()) return;
00142     switch(r) {
00143     case SRT_EQ:
00144       {
00145         Set::ConstantView cv(home, is);
00146         GECODE_ES_FAIL(home,
00147                        (Set::Rel::ReEq<Set::SetView,
00148                         Set::ConstantView>::post(home, s, cv, b)));
00149       }
00150       break;
00151     case SRT_NQ:
00152       {
00153         BoolVar notb(home,0,1);
00154         bool_not(home, b, notb);
00155         Set::ConstantView cv(home, is);
00156         GECODE_ES_FAIL(home,
00157                        (Set::Rel::ReEq<Set::SetView,
00158                         Set::ConstantView>::post(home, s, cv, notb)));
00159       }
00160       break;
00161     case SRT_SUB:
00162       {
00163         Set::ConstantView cv(home, is);
00164         GECODE_ES_FAIL(home,
00165                        (Set::Rel::ReSubset<Set::SetView,Set::ConstantView>
00166                         ::post(home, s, cv, b)));
00167       }
00168       break;
00169     case SRT_SUP:
00170       {
00171         Set::ConstantView cv(home, is);
00172         GECODE_ES_FAIL(home,
00173                        (Set::Rel::ReSubset<Set::ConstantView,Set::SetView>
00174                         ::post(home, cv, s, b)));
00175       }
00176       break;
00177     case SRT_DISJ:
00178       {
00179         // x||y <=> b is equivalent to
00180         // ( y <= complement(x) and x<=complement(y) ) <=> b
00181 
00182         // set up BoolVars for the conjunction
00183         BoolVar b1(home, 0, 1);
00184         BoolVar b2(home, 0, 1);
00185         bool_and(home, b1, b2, b);      
00186 
00187         // compute complement of is
00188         IntSetRanges dr1(is);
00189         Set::RangesCompl<IntSetRanges > dc1(dr1);
00190         
00191         // First conjunct: ( s <= complement(is) ) <=> b1
00192         IntSet dcompl(dc1);
00193         Set::ConstantView cvcompl(home, dcompl);
00194         GECODE_ES_FAIL(home,
00195                        (Set::Rel::ReSubset<Set::SetView,Set::ConstantView>
00196                         ::post(home, s, cvcompl, b1)));
00197 
00198         // Second conjunct: ( complement(s) <= d ) <=> b2
00199         Set::ConstantView cv(home, is);
00200         Set::SetView sv(s);
00201         Set::ComplementView<Set::SetView> cs(sv);
00202         GECODE_ES_FAIL(home,
00203                        (Set::Rel::ReSubset<Set::ConstantView,Set::ComplementView<Set::SetView> >
00204                         ::post(home, cv, cs, b2)));
00205 
00206       }
00207       break;
00208     case SRT_CMPL:
00209       {
00210         Set::SetView sv(s);
00211         Set::ComplementView<Set::SetView> cs(sv);
00212         Set::ConstantView cv(home, is);
00213         GECODE_ES_FAIL(home,
00214                        (Set::Rel::ReEq<Set::ComplementView<Set::SetView>,
00215                         Set::ConstantView>
00216                         ::post(home, cs, cv, b)));
00217       }
00218       break;
00219     }
00220   }
00221 
00222 }
00223 
00224 // STATISTICS: set-post