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