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

post.icc

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/set/rel.hh"
00027 #include "gecode/set/rel-op.hh"
00028 
00029 namespace Gecode { namespace Set { namespace RelOp {
00030   
00031   template <class View0, class View1, class Res>
00032   forceinline void
00033   rel_eq(Space* home, View0 x0, SetOpType op, View1 x1, Res x2) {
00034     switch(op) {
00035     case SOT_DUNION:
00036       {
00037         EmptyView emptyset;
00038         GECODE_ES_FAIL(home,(SuperOfInter<View0,View1,EmptyView>
00039                              ::post(home, x0, x1, emptyset)));
00040         // fall through to SOT_UNION
00041       }
00042     case SOT_UNION:
00043       {
00044         GECODE_ES_FAIL(home,
00045                        (Union<View0,View1,Res>
00046                         ::post(home, x0, x1, x2)));
00047       }
00048       break;
00049     case SOT_INTER:
00050       {
00051         GECODE_ES_FAIL(home,(Intersection<View0,View1,Res>
00052                              ::post(home, x0,x1,x2)));
00053       }
00054       break;
00055     case SOT_MINUS:
00056       {
00057         ComplementView<View1> cx1(x1);
00058         GECODE_ES_FAIL(home,
00059                        (Intersection<View0,
00060                         ComplementView<View1>,Res>
00061                         ::post(home,x0,cx1,x2)));
00062       }
00063       break;
00064     }
00065   }
00066 
00067   template <class View0, class View1, class View2>
00068   forceinline void
00069   rel_sub(Space* home, View0 x0, SetOpType op, View1 x1, View2 x2) {
00070     switch(op) {
00071     case SOT_DUNION:
00072       {
00073         EmptyView emptyset;
00074         GECODE_ES_FAIL(home,(SuperOfInter<View0,View1,EmptyView>
00075                              ::post(home, x0, x1, emptyset)));
00076         // fall through to SOT_UNION
00077       }
00078     case SOT_UNION:
00079       {
00080         SetVar tmp(home);
00081         GECODE_ES_FAIL(home,
00082                        (Rel::SubSet<SetView,View2>::post(home,tmp,x2)));
00083 
00084         GECODE_ES_FAIL(home,
00085                        (Union<View0,View1,SetView>
00086                         ::post(home, x0, x1, tmp)));
00087       }
00088       break;
00089     case SOT_INTER:
00090       {
00091         GECODE_ES_FAIL(home,(SuperOfInter<View0,View1,View2>
00092                              ::post(home, x0,x1,x2)));
00093       }
00094       break;
00095     case SOT_MINUS:
00096       {
00097         ComplementView<View1> cx1(x1);
00098         GECODE_ES_FAIL(home,
00099                        (SuperOfInter<View0,
00100                         ComplementView<View1>,View2>
00101                         ::post(home,x0,cx1,x2)));
00102       }
00103       break;
00104     }
00105     
00106   }
00107 
00108   template <class View0, class View1, class View2>
00109   forceinline void
00110   rel_sup(Space* home, View0 x0, SetOpType op, View1 x1, View2 x2) {
00111     switch(op) {
00112     case SOT_DUNION:
00113       {
00114         EmptyView emptyset;
00115         GECODE_ES_FAIL(home,(SuperOfInter<View0,View1,EmptyView>
00116                              ::post(home, x0, x1, emptyset)));
00117         // fall through to SOT_UNION
00118       }
00119     case SOT_UNION:
00120       {
00121         GECODE_ES_FAIL(home,
00122                        (SubOfUnion<View0,View1,View2>
00123                         ::post(home, x0, x1, x2)));
00124       }
00125       break;
00126     case SOT_INTER:
00127       { 
00128         SetVar tmp(home);
00129         GECODE_ES_FAIL(home,
00130                        (Rel::SubSet<View2,SetView>::post(home,x2,tmp)));
00131 
00132         GECODE_ES_FAIL(home,(Intersection<View0,View1,SetView>
00133                              ::post(home, x0,x1,tmp)));
00134       }
00135       break;
00136     case SOT_MINUS:
00137       {
00138         SetVar tmp(home);
00139         GECODE_ES_FAIL(home,
00140                        (Rel::SubSet<View2,SetView>::post(home,x2,tmp)));
00141 
00142         ComplementView<View1> cx1(x1);
00143         GECODE_ES_FAIL(home,
00144                        (Intersection<View0,
00145                         ComplementView<View1>,SetView>
00146                         ::post(home,x0,cx1,tmp)));
00147       }
00148       break;
00149     }
00150     
00151   }
00152   
00153   template <class View0, class View1, class View2>
00154   forceinline void
00155   rel_op_post(Space* home, View0 x, SetOpType op, View1 y,
00156            SetRelType r, View2 z) {
00157     if (home->failed()) return;
00158     switch(r) {
00159     case SRT_EQ:
00160       rel_eq<View0,View1,View2>(home, x, op, y, z);
00161       break;
00162     case SRT_NQ:
00163       {
00164         SetVar tmp(home);
00165         GECODE_ES_FAIL(home,
00166                        (Rel::Distinct<View2,SetView>
00167                         ::post(home,z,tmp)));
00168         rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
00169       }
00170       break;
00171     case SRT_SUB:
00172       rel_sub<View0,View1,View2>(home, x, op, y, z);
00173       break;
00174     case SRT_SUP:
00175       rel_sup<View0,View1,View2>(home, x, op, y, z);
00176       break;
00177     case SRT_DISJ:
00178       {
00179         SetVar tmp(home);
00180         EmptyView emptyset;
00181         GECODE_ES_FAIL(home,(SuperOfInter<View2,SetView,EmptyView>
00182                              ::post(home, z, tmp, emptyset)));
00183         rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
00184       }
00185       break;
00186     case SRT_CMPL:
00187       {
00188         ComplementView<View2> cz(z);
00189         rel_eq<View0,View1,ComplementView<View2> >(home, x, op, y, cz);
00190       }
00191       break;
00192     }
00193 
00194   }
00195 
00196 }}}
00197 
00198 // STATISTICS: set-prop