this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Guido Tack <tack@gecode.org> 5 * 6 * Contributing authors: 7 * Gabor Szokoli <szokoli@gecode.org> 8 * 9 * Copyright: 10 * Guido Tack, 2004, 2005 11 * 12 * This file is part of Gecode, the generic constraint 13 * development environment: 14 * http://www.gecode.org 15 * 16 * Permission is hereby granted, free of charge, to any person obtaining 17 * a copy of this software and associated documentation files (the 18 * "Software"), to deal in the Software without restriction, including 19 * without limitation the rights to use, copy, modify, merge, publish, 20 * distribute, sublicense, and/or sell copies of the Software, and to 21 * permit persons to whom the Software is furnished to do so, subject to 22 * the following conditions: 23 * 24 * The above copyright notice and this permission notice shall be 25 * included in all copies or substantial portions of the Software. 26 * 27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 31 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 32 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 33 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 * 35 */ 36 37#include <gecode/set.hh> 38#include <gecode/set/rel.hh> 39#include <gecode/set/rel-op.hh> 40 41namespace Gecode { namespace Set { namespace RelOp { 42 43 template<class View0, class View1, class Res> 44 forceinline void 45 rel_eq(Home home, View0 x0, SetOpType op, View1 x1, Res x2) { 46 switch(op) { 47 case SOT_DUNION: 48 { 49 EmptyView emptyset; 50 GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView> 51 ::post(home, x0, x1, emptyset))); 52 } 53 // fall through 54 case SOT_UNION: 55 { 56 GECODE_ES_FAIL( 57 (Union<View0,View1,Res> 58 ::post(home, x0, x1, x2))); 59 } 60 break; 61 case SOT_INTER: 62 { 63 GECODE_ES_FAIL((Intersection<View0,View1,Res> 64 ::post(home, x0,x1,x2))); 65 } 66 break; 67 case SOT_MINUS: 68 { 69 ComplementView<View1> cx1(x1); 70 GECODE_ES_FAIL( 71 (Intersection<View0, 72 ComplementView<View1>,Res> 73 ::post(home,x0,cx1,x2))); 74 } 75 break; 76 } 77 } 78 79 template<class View0, class View1, class View2> 80 forceinline void 81 rel_sub(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) { 82 switch(op) { 83 case SOT_DUNION: 84 { 85 EmptyView emptyset; 86 GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView> 87 ::post(home, x0, x1, emptyset))); 88 } 89 // fall through 90 case SOT_UNION: 91 { 92 SetVar tmp(home); 93 GECODE_ES_FAIL( 94 (Rel::Subset<SetView,View2>::post(home,tmp,x2))); 95 96 GECODE_ES_FAIL( 97 (Union<View0,View1,SetView> 98 ::post(home, x0, x1, tmp))); 99 } 100 break; 101 case SOT_INTER: 102 { 103 GECODE_ES_FAIL((SuperOfInter<View0,View1,View2> 104 ::post(home, x0,x1,x2))); 105 } 106 break; 107 case SOT_MINUS: 108 { 109 ComplementView<View1> cx1(x1); 110 GECODE_ES_FAIL( 111 (SuperOfInter<View0, 112 ComplementView<View1>,View2> 113 ::post(home,x0,cx1,x2))); 114 } 115 break; 116 } 117 118 } 119 120 template<class View0, class View1, class View2> 121 forceinline void 122 rel_sup(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) { 123 switch(op) { 124 case SOT_DUNION: 125 { 126 EmptyView emptyset; 127 GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView> 128 ::post(home, x0, x1, emptyset))); 129 } 130 // fall through 131 case SOT_UNION: 132 { 133 GECODE_ES_FAIL( 134 (SubOfUnion<View0,View1,View2> 135 ::post(home, x0, x1, x2))); 136 } 137 break; 138 case SOT_INTER: 139 { 140 SetVar tmp(home); 141 GECODE_ES_FAIL( 142 (Rel::Subset<View2,SetView>::post(home,x2,tmp))); 143 144 GECODE_ES_FAIL((Intersection<View0,View1,SetView> 145 ::post(home, x0,x1,tmp))); 146 } 147 break; 148 case SOT_MINUS: 149 { 150 SetVar tmp(home); 151 GECODE_ES_FAIL( 152 (Rel::Subset<View2,SetView>::post(home,x2,tmp))); 153 154 ComplementView<View1> cx1(x1); 155 GECODE_ES_FAIL( 156 (Intersection<View0, 157 ComplementView<View1>,SetView> 158 ::post(home,x0,cx1,tmp))); 159 } 160 break; 161 } 162 163 } 164 165 template<class View> 166 forceinline void 167 rel_op_post_lex(Home home, SetView x0, SetRelType r, View x1) { 168 switch (r) { 169 case SRT_LQ: 170 GECODE_ES_FAIL((Rel::Lq<SetView,View,false>::post(home,x0,x1))); 171 break; 172 case SRT_LE: 173 GECODE_ES_FAIL((Rel::Lq<SetView,View,true>::post(home,x0,x1))); 174 break; 175 case SRT_GQ: 176 GECODE_ES_FAIL((Rel::Lq<View,SetView,false>::post(home,x1,x0))); 177 break; 178 case SRT_GR: 179 GECODE_ES_FAIL((Rel::Lq<View,SetView,true>::post(home,x1,x0))); 180 break; 181 default: 182 throw UnknownRelation("Set::rel"); 183 } 184 } 185 186 template<class View0, class View1, class View2> 187 forceinline void 188 rel_op_post_nocompl(Home home, View0 x, SetOpType op, View1 y, 189 SetRelType r, View2 z) { 190 if (home.failed()) return; 191 switch(r) { 192 case SRT_EQ: 193 rel_eq<View0,View1,View2>(home, x, op, y, z); 194 break; 195 case SRT_LQ: case SRT_LE: case SRT_GQ: case SRT_GR: 196 { 197 SetVar tmp(home,IntSet::empty,Set::Limits::min,Set::Limits::max); 198 rel_eq<View0,View1,SetView>(home, x, op, y, tmp); 199 rel_op_post_lex<View2>(home,tmp,r,z); 200 } 201 break; 202 case SRT_NQ: 203 { 204 SetVar tmp(home); 205 GECODE_ES_FAIL( 206 (Rel::Distinct<SetView,View2> 207 ::post(home,tmp,z))); 208 rel_eq<View0,View1,SetView>(home, x, op, y, tmp); 209 } 210 break; 211 case SRT_SUB: 212 rel_sub<View0,View1,View2>(home, x, op, y, z); 213 break; 214 case SRT_SUP: 215 rel_sup<View0,View1,View2>(home, x, op, y, z); 216 break; 217 case SRT_DISJ: 218 { 219 SetVar tmp(home); 220 EmptyView emptyset; 221 GECODE_ES_FAIL((SuperOfInter<View2,SetView,EmptyView> 222 ::post(home, z, tmp, emptyset))); 223 rel_eq<View0,View1,SetView>(home, x, op, y, tmp); 224 } 225 break; 226 default: 227 GECODE_NEVER; 228 } 229 230 } 231 232 GECODE_SET_EXPORT void 233 post_nocompl(Home home, SetView x, SetOpType op, SetView y, 234 SetRelType r, SetView z); 235 GECODE_SET_EXPORT void 236 post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y, 237 SetRelType r, SetView z); 238 239 GECODE_SET_EXPORT void 240 post_nocompl(Home home, SetView x, SetOpType op, SetView y, 241 SetRelType r, ConstSetView z); 242 243 GECODE_SET_EXPORT void 244 post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y, 245 SetRelType r, ConstSetView z); 246 247 GECODE_SET_EXPORT void 248 post_compl(Home home, SetView x, SetOpType op, SetView y, SetView z); 249 250 GECODE_SET_EXPORT void 251 post_compl(Home home, ConstSetView x, SetOpType op, SetView y, SetView z); 252 253 GECODE_SET_EXPORT void 254 post_compl(Home home, SetView x, SetOpType op, SetView y, ConstSetView z); 255 256 GECODE_SET_EXPORT void 257 post_compl(Home home, ConstSetView x, SetOpType op, SetView y, 258 ConstSetView z); 259 260}}} 261 262// STATISTICS: set-prop