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

rel.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-19 16:09:54 +0100 (Tue, 19 Feb 2008) $ by $Author: tack $
00014  *     $Revision: 6236 $
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/rel.hh"
00042 #include "gecode/set/rel-op.hh"
00043 #include "gecode/set/int.hh"
00044 
00045 namespace Gecode {
00046   using namespace Set;
00047   using namespace Set::Rel;
00048   using namespace Set::RelOp;
00049   
00050   template <class View0, class View1>
00051   void
00052   rel_post(Space* home, View0 x0, SetRelType r, View1 x1) {
00053     if (home->failed()) return;
00054     switch(r) {
00055     case SRT_EQ:
00056       {
00057         GECODE_ES_FAIL(home,
00058                        (Eq<View0,View1>::post(home,x0,x1)));
00059       }
00060       break;
00061     case SRT_NQ:
00062       {
00063         GECODE_ES_FAIL(home,
00064                        (Distinct<View0,View1>::post(home,x0,x1)));
00065       }
00066       break;
00067     case SRT_SUB:
00068       {
00069         GECODE_ES_FAIL(home,
00070                        (SubSet<View0,View1>::post(home, x0,x1)));
00071       }
00072       break;
00073     case SRT_SUP:
00074       {
00075         GECODE_ES_FAIL(home,
00076                        (SubSet<View1,View0>::post(home, x1,x0)));
00077       }
00078       break;
00079     case SRT_DISJ:
00080       {
00081         EmptyView emptyset;
00082         GECODE_ES_FAIL(home,(SuperOfInter<View0,View1,EmptyView>
00083                              ::post(home, x0, x1, emptyset)));
00084       }
00085       break;
00086     case SRT_CMPL:
00087       {
00088         ComplementView<View0> cx0(x0);
00089         GECODE_ES_FAIL(home,
00090                        (Eq<ComplementView<View0>, View1>
00091                         ::post(home, cx0, x1)));
00092       }
00093       break;
00094     }
00095   }
00096 
00097   template <class View0, class View1>
00098   void
00099   rel_re(Space* home, View0 x, SetRelType r, View1 y, BoolVar b) {
00100     if (home->failed()) return;
00101     switch(r) {
00102     case SRT_EQ:
00103       {
00104         GECODE_ES_FAIL(home,
00105                        (ReEq<View0,View1>::post(home, x,y,b)));
00106       }
00107       break;
00108     case SRT_NQ:
00109       {
00110         BoolVar notb(home, 0, 1);
00111         rel(home, b, IRT_NQ, notb);
00112         GECODE_ES_FAIL(home,
00113                        (ReEq<View0,View1>::post(home,x,y,notb)));
00114       }
00115       break;
00116     case SRT_SUB:
00117       {
00118         GECODE_ES_FAIL(home,
00119                        (ReSubset<View0,View1>::post(home, x,y,b)));
00120       }
00121       break;
00122     case SRT_SUP:
00123       {
00124         GECODE_ES_FAIL(home,
00125                        (ReSubset<View1,View0>::post(home, y,x,b)));
00126       }
00127       break;
00128     case SRT_DISJ:
00129       {
00130         // x||y <=> b is equivalent to
00131         // ( y <= complement(x) ) <=> b
00132 
00133         ComplementView<View0> xc(x);
00134         GECODE_ES_FAIL(home,
00135                        (ReSubset<View1,ComplementView<View0> >
00136                         ::post(home, y, xc, b)));
00137       }
00138       break;
00139     case SRT_CMPL:
00140       {
00141         ComplementView<View0> xc(x);
00142         GECODE_ES_FAIL(home,
00143                        (ReEq<ComplementView<View0>,View1>
00144                        ::post(home, xc, y, b)));
00145       }
00146       break;
00147     }
00148   }
00149 
00150   void
00151   rel(Space* home, SetVar x, SetRelType r, SetVar y) {
00152     rel_post<SetView,SetView>(home,x,r,y);
00153   }
00154 
00155   void
00156   rel(Space* home, SetVar s, SetRelType r, IntVar x) {
00157     Gecode::Int::IntView xv(x);
00158     SingletonView xsingle(xv);
00159     rel_post<SetView,SingletonView>(home,s,r,xv);
00160   }
00161 
00162   void
00163   rel(Space* home, IntVar x, SetRelType r, SetVar s) {
00164     switch(r) {
00165     case SRT_SUB:
00166       rel(home, s, SRT_SUP, x);
00167       break;
00168     case SRT_SUP:
00169       rel(home, s, SRT_SUB, x);
00170       break;
00171     default:
00172       rel(home, s, r, x);
00173     }
00174   }
00175 
00176   void
00177   rel(Space* home, SetVar x, SetRelType r, SetVar y, BoolVar b) {
00178     rel_re<SetView,SetView>(home,x,r,y,b);
00179   }
00180 
00181   void
00182   rel(Space* home, SetVar s, SetRelType r, IntVar x, BoolVar b) {
00183     Gecode::Int::IntView xv(x);
00184     SingletonView xsingle(xv);
00185     rel_re<SetView,SingletonView>(home,s,r,xsingle,b);
00186   }
00187 
00188   void
00189   rel(Space* home, IntVar x, SetRelType r, SetVar s, BoolVar b) {
00190     switch(r) {
00191     case SRT_SUB:
00192       rel(home, s, SRT_SUP, x, b);
00193       break;
00194     case SRT_SUP:
00195       rel(home, s, SRT_SUB, x, b);
00196       break;
00197     default:
00198       rel(home, s, r, x, b);
00199     }
00200   }  
00201 
00202   namespace {
00203     GECODE_REGISTER1(Rel::DistinctDoit<ConstantView>);
00204     GECODE_REGISTER1(Rel::DistinctDoit<SingletonView>);
00205     GECODE_REGISTER1(Rel::DistinctDoit<ComplementView<SetView> >);
00206     GECODE_REGISTER1(Rel::DistinctDoit<SetView>);
00207     GECODE_REGISTER2(Rel::Eq<ConstantView, ComplementView<SetView> >);
00208     GECODE_REGISTER2(Rel::Eq<ConstantView, SetView>);
00209     GECODE_REGISTER2(Rel::Eq<ConstantView, ConstantView>);
00210     GECODE_REGISTER2(Rel::Eq<SingletonView, SetView>);
00211     GECODE_REGISTER2(Rel::Eq<ComplementView<SetView>, ConstantView>);
00212     GECODE_REGISTER2(Rel::Eq<ComplementView<SetView>, SingletonView>);
00213     GECODE_REGISTER2(Rel::Eq<ComplementView<SetView>, SetView>);
00214     GECODE_REGISTER2(Rel::Eq<SetView, ConstantView>);
00215     GECODE_REGISTER2(Rel::Eq<SetView, SingletonView>);
00216     GECODE_REGISTER2(Rel::Eq<SetView, ComplementView<SetView> >);
00217     GECODE_REGISTER2(Rel::Eq<SetView, SetView>);
00218     GECODE_REGISTER2(Rel::ReEq<ComplementView<SetView>, ConstantView>);
00219     GECODE_REGISTER2(Rel::ReEq<ComplementView<SetView>, SingletonView>);
00220     GECODE_REGISTER2(Rel::ReEq<ComplementView<SetView>, SetView>);
00221     GECODE_REGISTER2(Rel::ReEq<SetView, ConstantView>);
00222     GECODE_REGISTER2(Rel::ReEq<SetView, SingletonView>);
00223     GECODE_REGISTER2(Rel::ReEq<SetView, SetView>);
00224     GECODE_REGISTER2(Rel::SubSet<ConstantView, SetView>);
00225     GECODE_REGISTER2(Rel::SubSet<SingletonView, SetView>);
00226     GECODE_REGISTER2(Rel::SubSet<ComplementView<SetView>, ConstantView>);
00227     GECODE_REGISTER2(Rel::SubSet<ComplementView<SetView>, SingletonView>);
00228     GECODE_REGISTER2(Rel::SubSet<ComplementView<SetView>, SetView>);
00229     GECODE_REGISTER2(Rel::SubSet<SetView, ConstantView>);
00230     GECODE_REGISTER2(Rel::SubSet<SetView, SingletonView>);
00231     GECODE_REGISTER2(Rel::SubSet<SetView, SetView>);
00232     GECODE_REGISTER2(Rel::Distinct<ComplementView<SetView>, ConstantView>);
00233     GECODE_REGISTER2(Rel::Distinct<ComplementView<SetView>, SingletonView>);
00234     GECODE_REGISTER2(Rel::Distinct<ComplementView<SetView>, SetView>);
00235     GECODE_REGISTER2(Rel::Distinct<SetView, ConstantView>);
00236     GECODE_REGISTER2(Rel::Distinct<SetView, SingletonView>);
00237     GECODE_REGISTER2(Rel::Distinct<SetView, SetView>);
00238     GECODE_REGISTER2(Rel::NoSubSet<ConstantView, SetView>);
00239     GECODE_REGISTER2(Rel::NoSubSet<SingletonView, SetView>);
00240     GECODE_REGISTER2(Rel::NoSubSet<ComplementView<SetView>, ConstantView>);
00241     GECODE_REGISTER2(Rel::NoSubSet<ComplementView<SetView>, SingletonView>);
00242     GECODE_REGISTER2(Rel::NoSubSet<ComplementView<SetView>, SetView>);
00243     GECODE_REGISTER2(Rel::NoSubSet<SetView, ConstantView>);
00244     GECODE_REGISTER2(Rel::NoSubSet<SetView, SingletonView>);
00245     GECODE_REGISTER2(Rel::NoSubSet<SetView, SetView>);
00246     GECODE_REGISTER2(Rel::ReSubset<ConstantView, SetView>);
00247     GECODE_REGISTER2(Rel::ReSubset<SingletonView, SetView>);
00248     GECODE_REGISTER2(Rel::ReSubset<ConstantView, ComplementView<SetView> >);
00249     GECODE_REGISTER2(Rel::ReSubset<SingletonView, ComplementView<SetView> >);
00250     GECODE_REGISTER2(Rel::ReSubset<SetView, ComplementView<SetView> >);
00251     GECODE_REGISTER2(Rel::ReSubset<SetView, ConstantView>);
00252     GECODE_REGISTER2(Rel::ReSubset<SetView, SingletonView>);
00253     GECODE_REGISTER2(Rel::ReSubset<SetView, SetView>);  
00254   }
00255 
00256 }
00257 
00258 // STATISTICS: set-post