Generated on Thu Mar 22 10:39:40 2012 for Gecode by doxygen 1.6.3

rel.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: 2011-08-24 16:34:16 +0200 (Wed, 24 Aug 2011) $ by $Author: tack $
00014  *     $Revision: 12346 $
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(Home home, View0 x0, SetRelType r, View1 x1) {
00053     if (home.failed()) return;
00054     switch (r) {
00055     case SRT_EQ:
00056       {
00057         GECODE_ES_FAIL(
00058                        (Eq<View0,View1>::post(home,x0,x1)));
00059       }
00060       break;
00061     case SRT_NQ:
00062       {
00063         GECODE_ES_FAIL(
00064                        (Distinct<View0,View1>::post(home,x0,x1)));
00065       }
00066       break;
00067     case SRT_SUB:
00068       {
00069         GECODE_ES_FAIL(
00070                        (Subset<View0,View1>::post(home, x0,x1)));
00071       }
00072       break;
00073     case SRT_SUP:
00074       {
00075         GECODE_ES_FAIL(
00076                        (Subset<View1,View0>::post(home, x1,x0)));
00077       }
00078       break;
00079     case SRT_DISJ:
00080       {
00081         EmptyView emptyset;
00082         GECODE_ES_FAIL((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(
00090                        (Eq<ComplementView<View0>, View1>
00091                         ::post(home, cx0, x1)));
00092       }
00093       break;
00094     case SRT_LQ:
00095       GECODE_ES_FAIL((Lq<View0,View1,false>::post(home,x0,x1)));
00096       break;
00097     case SRT_LE:
00098       GECODE_ES_FAIL((Lq<View0,View1,true>::post(home,x0,x1)));
00099       break;
00100     case SRT_GQ:
00101       GECODE_ES_FAIL((Lq<View1,View0,false>::post(home,x1,x0)));
00102       break;
00103     case SRT_GR:
00104       GECODE_ES_FAIL((Lq<View1,View0,true>::post(home,x1,x0)));
00105       break;
00106     default:
00107       throw UnknownRelation("Set::rel");
00108     }
00109   }
00110 
00111   template<class View0, class View1>
00112   void
00113   rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b) {
00114     if (home.failed()) return;
00115     switch (r) {
00116     case SRT_EQ:
00117       {
00118         GECODE_ES_FAIL(
00119                        (ReEq<View0,View1>::post(home, x,y,b)));
00120       }
00121       break;
00122     case SRT_NQ:
00123       {
00124         BoolVar notb(home, 0, 1);
00125         rel(home, b, IRT_NQ, notb);
00126         GECODE_ES_FAIL(
00127                        (ReEq<View0,View1>::post(home,x,y,notb)));
00128       }
00129       break;
00130     case SRT_SUB:
00131       {
00132         GECODE_ES_FAIL(
00133                        (ReSubset<View0,View1>::post(home, x,y,b)));
00134       }
00135       break;
00136     case SRT_SUP:
00137       {
00138         GECODE_ES_FAIL(
00139                        (ReSubset<View1,View0>::post(home, y,x,b)));
00140       }
00141       break;
00142     case SRT_DISJ:
00143       {
00144         // x||y <=> b is equivalent to
00145         // ( y <= complement(x) ) <=> b
00146 
00147         ComplementView<View0> xc(x);
00148         GECODE_ES_FAIL(
00149                        (ReSubset<View1,ComplementView<View0> >
00150                         ::post(home, y, xc, b)));
00151       }
00152       break;
00153     case SRT_CMPL:
00154       {
00155         ComplementView<View0> xc(x);
00156         GECODE_ES_FAIL(
00157                        (ReEq<ComplementView<View0>,View1>
00158                        ::post(home, xc, y, b)));
00159       }
00160       break;
00161     case SRT_LQ:
00162       GECODE_ES_FAIL((ReLq<View0,View1,false>::post(home,x,y,b)));
00163       break;
00164     case SRT_LE:
00165       GECODE_ES_FAIL((ReLq<View0,View1,true>::post(home,x,y,b)));
00166       break;
00167     case SRT_GQ:
00168       GECODE_ES_FAIL((ReLq<View1,View0,false>::post(home,y,x,b)));
00169       break;
00170     case SRT_GR:
00171       GECODE_ES_FAIL((ReLq<View1,View0,true>::post(home,y,x,b)));
00172       break;
00173     default:
00174       throw UnknownRelation("Set::rel");
00175     }
00176   }
00177 
00178   void
00179   rel(Home home, SetVar x, SetRelType r, SetVar y) {
00180     rel_post<SetView,SetView>(home,x,r,y);
00181   }
00182 
00183   void
00184   rel(Home home, SetVar s, SetRelType r, IntVar x) {
00185     Gecode::Int::IntView xv(x);
00186     SingletonView xsingle(xv);
00187     rel_post<SetView,SingletonView>(home,s,r,xv);
00188   }
00189 
00190   void
00191   rel(Home home, IntVar x, SetRelType r, SetVar s) {
00192     switch (r) {
00193     case SRT_SUB:
00194       rel(home, s, SRT_SUP, x);
00195       break;
00196     case SRT_SUP:
00197       rel(home, s, SRT_SUB, x);
00198       break;
00199     default:
00200       rel(home, s, r, x);
00201     }
00202   }
00203 
00204   void
00205   rel(Home home, SetVar x, SetRelType r, SetVar y, BoolVar b) {
00206     rel_re<SetView,SetView>(home,x,r,y,b);
00207   }
00208 
00209   void
00210   rel(Home home, SetVar s, SetRelType r, IntVar x, BoolVar b) {
00211     Gecode::Int::IntView xv(x);
00212     SingletonView xsingle(xv);
00213     rel_re<SetView,SingletonView>(home,s,r,xsingle,b);
00214   }
00215 
00216   void
00217   rel(Home home, IntVar x, SetRelType r, SetVar s, BoolVar b) {
00218     switch (r) {
00219     case SRT_SUB:
00220       rel(home, s, SRT_SUP, x, b);
00221       break;
00222     case SRT_SUP:
00223       rel(home, s, SRT_SUB, x, b);
00224       break;
00225     default:
00226       rel(home, s, r, x, b);
00227     }
00228   }
00229 
00230 }
00231 
00232 // STATISTICS: set-post