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

post.icc

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: 2007-08-09 15:30:21 +0200 (Thu, 09 Aug 2007) $ by $Author: tack $
00014  *     $Revision: 4790 $
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(Space* home, View0 x0, SetOpType op, View1 x1, Res x2) {
00050     switch(op) {
00051     case SOT_DUNION:
00052       {
00053         EmptyView emptyset;
00054         GECODE_ES_FAIL(home,(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(home,
00061                        (Union<View0,View1,Res>
00062                         ::post(home, x0, x1, x2)));
00063       }
00064       break;
00065     case SOT_INTER:
00066       {
00067         GECODE_ES_FAIL(home,(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(home,
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(Space* home, View0 x0, SetOpType op, View1 x1, View2 x2) {
00086     switch(op) {
00087     case SOT_DUNION:
00088       {
00089         EmptyView emptyset;
00090         GECODE_ES_FAIL(home,(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(home,
00098                        (Rel::SubSet<SetView,View2>::post(home,tmp,x2)));
00099 
00100         GECODE_ES_FAIL(home,
00101                        (Union<View0,View1,SetView>
00102                         ::post(home, x0, x1, tmp)));
00103       }
00104       break;
00105     case SOT_INTER:
00106       {
00107         GECODE_ES_FAIL(home,(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(home,
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(Space* home, View0 x0, SetOpType op, View1 x1, View2 x2) {
00127     switch(op) {
00128     case SOT_DUNION:
00129       {
00130         EmptyView emptyset;
00131         GECODE_ES_FAIL(home,(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(home,
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(home,
00146                        (Rel::SubSet<View2,SetView>::post(home,x2,tmp)));
00147 
00148         GECODE_ES_FAIL(home,(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(home,
00156                        (Rel::SubSet<View2,SetView>::post(home,x2,tmp)));
00157 
00158         ComplementView<View1> cx1(x1);
00159         GECODE_ES_FAIL(home,
00160                        (Intersection<View0,
00161                         ComplementView<View1>,SetView>
00162                         ::post(home,x0,cx1,tmp)));
00163       }
00164       break;
00165     }
00166     
00167   }
00168   
00169   template <class View0, class View1, class View2>
00170   forceinline void
00171   rel_op_post_nocompl(Space* home, View0 x, SetOpType op, View1 y,
00172            SetRelType r, View2 z) {
00173     if (home->failed()) return;
00174     switch(r) {
00175     case SRT_EQ:
00176       rel_eq<View0,View1,View2>(home, x, op, y, z);
00177       break;
00178     case SRT_NQ:
00179       {
00180         SetVar tmp(home);
00181         GECODE_ES_FAIL(home,
00182                        (Rel::Distinct<SetView,View2>
00183                         ::post(home,tmp,z)));
00184         rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
00185       }
00186       break;
00187     case SRT_SUB:
00188       rel_sub<View0,View1,View2>(home, x, op, y, z);
00189       break;
00190     case SRT_SUP:
00191       rel_sup<View0,View1,View2>(home, x, op, y, z);
00192       break;
00193     case SRT_DISJ:
00194       {
00195         SetVar tmp(home);
00196         EmptyView emptyset;
00197         GECODE_ES_FAIL(home,(SuperOfInter<View2,SetView,EmptyView>
00198                              ::post(home, z, tmp, emptyset)));
00199         rel_eq<View0,View1,SetView>(home, x, op, y, tmp);
00200       }
00201       break;
00202     default:
00203       GECODE_NEVER;
00204     }
00205 
00206   }
00207 
00208   template <class View0, class View1, class View2>
00209   forceinline void
00210   rel_op_post(Space* home, View0 x, SetOpType op, View1 y,
00211            SetRelType r, View2 z) {
00212     if (home->failed()) return;
00213     if (r == SRT_CMPL) {
00214       ComplementView<View2> cz(z);
00215       rel_eq<View0,View1,ComplementView<View2> >(home, x, op, y, cz);      
00216     } else {
00217       rel_op_post_nocompl<View0,View1,View2>(home, x, op, y, r, z);
00218     }
00219   }
00220 
00221 }}}
00222 
00223 // STATISTICS: set-prop