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: 2010-06-07 14:18:14 +0200 (Mon, 07 Jun 2010) $ by $Author: tack $ 00014 * $Revision: 11048 $ 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 View0, class View1, class View2> 00170 forceinline void 00171 rel_op_post_nocompl(Home 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( 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((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 GECODE_SET_EXPORT void 00209 post_nocompl(Home home, SetView x, SetOpType op, SetView y, 00210 SetRelType r, SetView z); 00211 GECODE_SET_EXPORT void 00212 post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y, 00213 SetRelType r, SetView z); 00214 00215 GECODE_SET_EXPORT void 00216 post_nocompl(Home home, SetView x, SetOpType op, SetView y, 00217 SetRelType r, ConstSetView z); 00218 00219 GECODE_SET_EXPORT void 00220 post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y, 00221 SetRelType r, ConstSetView z); 00222 00223 GECODE_SET_EXPORT void 00224 post_compl(Home home, SetView x, SetOpType op, SetView y, SetView z); 00225 00226 GECODE_SET_EXPORT void 00227 post_compl(Home home, ConstSetView x, SetOpType op, SetView y, SetView z); 00228 00229 GECODE_SET_EXPORT void 00230 post_compl(Home home, SetView x, SetOpType op, SetView y, ConstSetView z); 00231 00232 GECODE_SET_EXPORT void 00233 post_compl(Home home, ConstSetView x, SetOpType op, SetView y, 00234 ConstSetView z); 00235 00236 }}} 00237 00238 // STATISTICS: set-prop