Generated on Tue May 22 09:39:57 2018 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  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  Permission is hereby granted, free of charge, to any person obtaining
00017  *  a copy of this software and associated documentation files (the
00018  *  "Software"), to deal in the Software without restriction, including
00019  *  without limitation the rights to use, copy, modify, merge, publish,
00020  *  distribute, sublicense, and/or sell copies of the Software, and to
00021  *  permit persons to whom the Software is furnished to do so, subject to
00022  *  the following conditions:
00023  *
00024  *  The above copyright notice and this permission notice shall be
00025  *  included in all copies or substantial portions of the Software.
00026  *
00027  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00028  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00029  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00030  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00031  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00032  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00033  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00034  *
00035  */
00036 
00037 #include <gecode/set.hh>
00038 #include <gecode/set/rel.hh>
00039 #include <gecode/set/rel-op.hh>
00040 
00041 namespace Gecode { namespace Set { namespace RelOp {
00042 
00043   template<class View0, class View1, class Res>
00044   forceinline void
00045   rel_eq(Home home, View0 x0, SetOpType op, View1 x1, Res x2) {
00046     switch(op) {
00047     case SOT_DUNION:
00048       {
00049         EmptyView emptyset;
00050         GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView>
00051                              ::post(home, x0, x1, emptyset)));
00052         // fall through to SOT_UNION
00053       }
00054     case SOT_UNION:
00055       {
00056         GECODE_ES_FAIL(
00057                        (Union<View0,View1,Res>
00058                         ::post(home, x0, x1, x2)));
00059       }
00060       break;
00061     case SOT_INTER:
00062       {
00063         GECODE_ES_FAIL((Intersection<View0,View1,Res>
00064                              ::post(home, x0,x1,x2)));
00065       }
00066       break;
00067     case SOT_MINUS:
00068       {
00069         ComplementView<View1> cx1(x1);
00070         GECODE_ES_FAIL(
00071                        (Intersection<View0,
00072                         ComplementView<View1>,Res>
00073                         ::post(home,x0,cx1,x2)));
00074       }
00075       break;
00076     }
00077   }
00078 
00079   template<class View0, class View1, class View2>
00080   forceinline void
00081   rel_sub(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) {
00082     switch(op) {
00083     case SOT_DUNION:
00084       {
00085         EmptyView emptyset;
00086         GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView>
00087                              ::post(home, x0, x1, emptyset)));
00088         // fall through to SOT_UNION
00089       }
00090     case SOT_UNION:
00091       {
00092         SetVar tmp(home);
00093         GECODE_ES_FAIL(
00094                        (Rel::Subset<SetView,View2>::post(home,tmp,x2)));
00095 
00096         GECODE_ES_FAIL(
00097                        (Union<View0,View1,SetView>
00098                         ::post(home, x0, x1, tmp)));
00099       }
00100       break;
00101     case SOT_INTER:
00102       {
00103         GECODE_ES_FAIL((SuperOfInter<View0,View1,View2>
00104                              ::post(home, x0,x1,x2)));
00105       }
00106       break;
00107     case SOT_MINUS:
00108       {
00109         ComplementView<View1> cx1(x1);
00110         GECODE_ES_FAIL(
00111                        (SuperOfInter<View0,
00112                         ComplementView<View1>,View2>
00113                         ::post(home,x0,cx1,x2)));
00114       }
00115       break;
00116     }
00117 
00118   }
00119 
00120   template<class View0, class View1, class View2>
00121   forceinline void
00122   rel_sup(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) {
00123     switch(op) {
00124     case SOT_DUNION:
00125       {
00126         EmptyView emptyset;
00127         GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView>
00128                              ::post(home, x0, x1, emptyset)));
00129         // fall through to SOT_UNION
00130       }
00131     case SOT_UNION:
00132       {
00133         GECODE_ES_FAIL(
00134                        (SubOfUnion<View0,View1,View2>
00135                         ::post(home, x0, x1, x2)));
00136       }
00137       break;
00138     case SOT_INTER:
00139       {
00140         SetVar tmp(home);
00141         GECODE_ES_FAIL(
00142                        (Rel::Subset<View2,SetView>::post(home,x2,tmp)));
00143 
00144         GECODE_ES_FAIL((Intersection<View0,View1,SetView>
00145                              ::post(home, x0,x1,tmp)));
00146       }
00147       break;
00148     case SOT_MINUS:
00149       {
00150         SetVar tmp(home);
00151         GECODE_ES_FAIL(
00152                        (Rel::Subset<View2,SetView>::post(home,x2,tmp)));
00153 
00154         ComplementView<View1> cx1(x1);
00155         GECODE_ES_FAIL(
00156                        (Intersection<View0,
00157                         ComplementView<View1>,SetView>
00158                         ::post(home,x0,cx1,tmp)));
00159       }
00160       break;
00161     }
00162 
00163   }
00164 
00165   template<class View>
00166   forceinline void
00167   rel_op_post_lex(Home home, SetView x0, SetRelType r, View x1) {
00168     switch (r) {
00169     case SRT_LQ:
00170       GECODE_ES_FAIL((Rel::Lq<SetView,View,false>::post(home,x0,x1)));
00171       break;
00172     case SRT_LE:
00173       GECODE_ES_FAIL((Rel::Lq<SetView,View,true>::post(home,x0,x1)));
00174       break;
00175     case SRT_GQ:
00176       GECODE_ES_FAIL((Rel::Lq<View,SetView,false>::post(home,x1,x0)));
00177       break;
00178     case SRT_GR:
00179       GECODE_ES_FAIL((Rel::Lq<View,SetView,true>::post(home,x1,x0)));
00180       break;
00181     default:
00182       throw UnknownRelation("Set::rel");
00183     }
00184   }
00185 
00186   template<class View0, class View1, class View2>
00187   forceinline void
00188   rel_op_post_nocompl(Home home, View0 x, SetOpType op, View1 y,
00189                       SetRelType r, View2 z) {
00190     if (home.failed()) return;
00191     switch(r) {
00192     case SRT_EQ:
00193       rel_eq<View0,View1,View2>(home, x, op, y, z);
00194       break;
00195     case SRT_LQ: case SRT_LE: case SRT_GQ: case SRT_GR:
00196       {
00197         SetVar tmp(home,IntSet::empty,Set::Limits::min,Set::Limits::max);
00198         rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
00199         rel_op_post_lex<View2>(home,tmp,r,z);
00200       }
00201       break;
00202     case SRT_NQ:
00203       {
00204         SetVar tmp(home);
00205         GECODE_ES_FAIL(
00206                        (Rel::Distinct<SetView,View2>
00207                         ::post(home,tmp,z)));
00208         rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
00209       }
00210       break;
00211     case SRT_SUB:
00212       rel_sub<View0,View1,View2>(home, x, op, y, z);
00213       break;
00214     case SRT_SUP:
00215       rel_sup<View0,View1,View2>(home, x, op, y, z);
00216       break;
00217     case SRT_DISJ:
00218       {
00219         SetVar tmp(home);
00220         EmptyView emptyset;
00221         GECODE_ES_FAIL((SuperOfInter<View2,SetView,EmptyView>
00222                              ::post(home, z, tmp, emptyset)));
00223         rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
00224       }
00225       break;
00226     default:
00227       GECODE_NEVER;
00228     }
00229 
00230   }
00231 
00232   GECODE_SET_EXPORT void
00233   post_nocompl(Home home, SetView x, SetOpType op, SetView y,
00234                SetRelType r, SetView z);
00235   GECODE_SET_EXPORT void
00236   post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y,
00237                SetRelType r, SetView z);
00238 
00239   GECODE_SET_EXPORT void
00240   post_nocompl(Home home, SetView x, SetOpType op, SetView y,
00241                SetRelType r, ConstSetView z);
00242 
00243   GECODE_SET_EXPORT void
00244   post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y,
00245                SetRelType r, ConstSetView z);
00246 
00247   GECODE_SET_EXPORT void
00248   post_compl(Home home, SetView x, SetOpType op, SetView y, SetView z);
00249 
00250   GECODE_SET_EXPORT void
00251   post_compl(Home home, ConstSetView x, SetOpType op, SetView y, SetView z);
00252 
00253   GECODE_SET_EXPORT void
00254   post_compl(Home home, SetView x, SetOpType op, SetView y, ConstSetView z);
00255 
00256   GECODE_SET_EXPORT void
00257   post_compl(Home home, ConstSetView x, SetOpType op, SetView y,
00258              ConstSetView z);
00259 
00260 }}}
00261 
00262 // STATISTICS: set-prop