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

post.hpp

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.hh>
00042 #include <gecode/set/rel.hh>
00043 #include <gecode/set/rel-op.hh>
00044 
00045 namespace Gecode { namespace Set { namespace RelOp {
00046 
00047   template<class View0, class View1, class Res>
00048   forceinline void
00049   rel_eq(Home home, View0 x0, SetOpType op, View1 x1, Res x2) {
00050     switch(op) {
00051     case SOT_DUNION:
00052       {
00053         EmptyView emptyset;
00054         GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView>
00055                              ::post(home, x0, x1, emptyset)));
00056         // fall through to SOT_UNION
00057       }
00058     case SOT_UNION:
00059       {
00060         GECODE_ES_FAIL(
00061                        (Union<View0,View1,Res>
00062                         ::post(home, x0, x1, x2)));
00063       }
00064       break;
00065     case SOT_INTER:
00066       {
00067         GECODE_ES_FAIL((Intersection<View0,View1,Res>
00068                              ::post(home, x0,x1,x2)));
00069       }
00070       break;
00071     case SOT_MINUS:
00072       {
00073         ComplementView<View1> cx1(x1);
00074         GECODE_ES_FAIL(
00075                        (Intersection<View0,
00076                         ComplementView<View1>,Res>
00077                         ::post(home,x0,cx1,x2)));
00078       }
00079       break;
00080     }
00081   }
00082 
00083   template<class View0, class View1, class View2>
00084   forceinline void
00085   rel_sub(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) {
00086     switch(op) {
00087     case SOT_DUNION:
00088       {
00089         EmptyView emptyset;
00090         GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView>
00091                              ::post(home, x0, x1, emptyset)));
00092         // fall through to SOT_UNION
00093       }
00094     case SOT_UNION:
00095       {
00096         SetVar tmp(home);
00097         GECODE_ES_FAIL(
00098                        (Rel::Subset<SetView,View2>::post(home,tmp,x2)));
00099 
00100         GECODE_ES_FAIL(
00101                        (Union<View0,View1,SetView>
00102                         ::post(home, x0, x1, tmp)));
00103       }
00104       break;
00105     case SOT_INTER:
00106       {
00107         GECODE_ES_FAIL((SuperOfInter<View0,View1,View2>
00108                              ::post(home, x0,x1,x2)));
00109       }
00110       break;
00111     case SOT_MINUS:
00112       {
00113         ComplementView<View1> cx1(x1);
00114         GECODE_ES_FAIL(
00115                        (SuperOfInter<View0,
00116                         ComplementView<View1>,View2>
00117                         ::post(home,x0,cx1,x2)));
00118       }
00119       break;
00120     }
00121 
00122   }
00123 
00124   template<class View0, class View1, class View2>
00125   forceinline void
00126   rel_sup(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) {
00127     switch(op) {
00128     case SOT_DUNION:
00129       {
00130         EmptyView emptyset;
00131         GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView>
00132                              ::post(home, x0, x1, emptyset)));
00133         // fall through to SOT_UNION
00134       }
00135     case SOT_UNION:
00136       {
00137         GECODE_ES_FAIL(
00138                        (SubOfUnion<View0,View1,View2>
00139                         ::post(home, x0, x1, x2)));
00140       }
00141       break;
00142     case SOT_INTER:
00143       {
00144         SetVar tmp(home);
00145         GECODE_ES_FAIL(
00146                        (Rel::Subset<View2,SetView>::post(home,x2,tmp)));
00147 
00148         GECODE_ES_FAIL((Intersection<View0,View1,SetView>
00149                              ::post(home, x0,x1,tmp)));
00150       }
00151       break;
00152     case SOT_MINUS:
00153       {
00154         SetVar tmp(home);
00155         GECODE_ES_FAIL(
00156                        (Rel::Subset<View2,SetView>::post(home,x2,tmp)));
00157 
00158         ComplementView<View1> cx1(x1);
00159         GECODE_ES_FAIL(
00160                        (Intersection<View0,
00161                         ComplementView<View1>,SetView>
00162                         ::post(home,x0,cx1,tmp)));
00163       }
00164       break;
00165     }
00166 
00167   }
00168 
00169   template<class View>
00170   forceinline void
00171   rel_op_post_lex(Home home, SetView x0, SetRelType r, View x1) {
00172     switch (r) {
00173     case SRT_LQ:
00174       GECODE_ES_FAIL((Rel::Lq<SetView,View,false>::post(home,x0,x1)));
00175       break;
00176     case SRT_LE:
00177       GECODE_ES_FAIL((Rel::Lq<SetView,View,true>::post(home,x0,x1)));
00178       break;
00179     case SRT_GQ:
00180       GECODE_ES_FAIL((Rel::Lq<View,SetView,false>::post(home,x1,x0)));
00181       break;
00182     case SRT_GR:
00183       GECODE_ES_FAIL((Rel::Lq<View,SetView,true>::post(home,x1,x0)));
00184       break;
00185     default:
00186       throw UnknownRelation("Set::rel");
00187     }
00188   }
00189 
00190   template<class View0, class View1, class View2>
00191   forceinline void
00192   rel_op_post_nocompl(Home home, View0 x, SetOpType op, View1 y,
00193                       SetRelType r, View2 z) {
00194     if (home.failed()) return;
00195     switch(r) {
00196     case SRT_EQ:
00197       rel_eq<View0,View1,View2>(home, x, op, y, z);
00198       break;
00199     case SRT_LQ: case SRT_LE: case SRT_GQ: case SRT_GR:
00200       {
00201         SetVar tmp(home,IntSet::empty,Set::Limits::min,Set::Limits::max);
00202         rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
00203         rel_op_post_lex<View2>(home,tmp,r,z);
00204       }
00205       break;
00206     case SRT_NQ:
00207       {
00208         SetVar tmp(home);
00209         GECODE_ES_FAIL(
00210                        (Rel::Distinct<SetView,View2>
00211                         ::post(home,tmp,z)));
00212         rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
00213       }
00214       break;
00215     case SRT_SUB:
00216       rel_sub<View0,View1,View2>(home, x, op, y, z);
00217       break;
00218     case SRT_SUP:
00219       rel_sup<View0,View1,View2>(home, x, op, y, z);
00220       break;
00221     case SRT_DISJ:
00222       {
00223         SetVar tmp(home);
00224         EmptyView emptyset;
00225         GECODE_ES_FAIL((SuperOfInter<View2,SetView,EmptyView>
00226                              ::post(home, z, tmp, emptyset)));
00227         rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
00228       }
00229       break;
00230     default:
00231       GECODE_NEVER;
00232     }
00233 
00234   }
00235 
00236   GECODE_SET_EXPORT void
00237   post_nocompl(Home home, SetView x, SetOpType op, SetView y,
00238                SetRelType r, SetView z);
00239   GECODE_SET_EXPORT void
00240   post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y,
00241                SetRelType r, SetView z);
00242 
00243   GECODE_SET_EXPORT void
00244   post_nocompl(Home home, SetView x, SetOpType op, SetView y,
00245                SetRelType r, ConstSetView z);
00246 
00247   GECODE_SET_EXPORT void
00248   post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y,
00249                SetRelType r, ConstSetView z);
00250 
00251   GECODE_SET_EXPORT void
00252   post_compl(Home home, SetView x, SetOpType op, SetView y, SetView z);
00253 
00254   GECODE_SET_EXPORT void
00255   post_compl(Home home, ConstSetView x, SetOpType op, SetView y, SetView z);
00256 
00257   GECODE_SET_EXPORT void
00258   post_compl(Home home, SetView x, SetOpType op, SetView y, ConstSetView z);
00259 
00260   GECODE_SET_EXPORT void
00261   post_compl(Home home, ConstSetView x, SetOpType op, SetView y,
00262              ConstSetView z);
00263 
00264 }}}
00265 
00266 // STATISTICS: set-prop