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 {
42 using namespace Gecode::Set;
43 using namespace Gecode::Set::Rel;
44 using namespace Gecode::Set::RelOp;
45
46 void
47 rel(Home home, SetVar x, SetOpType op, const IntSet& y, SetRelType r,
48 const IntSet& z) {
49 Set::Limits::check(y, "Set::rel");
50 Set::Limits::check(z, "Set::rel");
51 ConstSetView yv(home, y);
52 ConstSetView zv(home, z);
53
54 if (op==SOT_MINUS) {
55 switch (r) {
56 case SRT_EQ:
57 {
58 GlbRanges<ConstSetView> yr(yv);
59 RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
60 IntSet yc(yrc);
61 ConstSetView cy(home, yc);
62 GECODE_ES_FAIL(
63 (Intersection<ConstSetView,
64 SetView,ConstSetView>
65 ::post(home,cy,x,zv)));
66 }
67 break;
68 case SRT_LQ: case SRT_LE: case SRT_GQ: case SRT_GR:
69 {
70 GlbRanges<ConstSetView> yr(yv);
71 RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
72 IntSet yc(yrc);
73 ConstSetView cy(home, yc);
74 SetVar tmp(home,IntSet::empty,Set::Limits::min,Set::Limits::max);
75 GECODE_ES_FAIL(
76 (Intersection<ConstSetView,
77 SetView,SetView>
78 ::post(home,cy,x,tmp)));
79 dom(home,tmp,r,z);
80 }
81 break;
82 case SRT_NQ:
83 {
84 SetVar tmp(home);
85 GECODE_ES_FAIL(
86 (Distinct<SetView,ConstSetView>
87 ::post(home,tmp,zv)));
88 GlbRanges<ConstSetView> yr(yv);
89 RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
90 IntSet yc(yrc);
91 ConstSetView cy(home, yc);
92 GECODE_ES_FAIL(
93 (Intersection<ConstSetView,
94 SetView,SetView>
95 ::post(home,cy,x,tmp)));
96 }
97 break;
98 case SRT_SUB:
99 {
100 GlbRanges<ConstSetView> yr(yv);
101 RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
102 IntSet yc(yrc);
103 ConstSetView cy(home, yc);
104 GECODE_ES_FAIL(
105 (SuperOfInter<ConstSetView,SetView,ConstSetView>
106 ::post(home,cy,x,zv)));
107
108 }
109 break;
110 case SRT_SUP:
111 {
112 // z <= tmp
113 SetVar tmp(home,z,Limits::min, Limits::max);
114 SetView xv(x);
115
116 GlbRanges<ConstSetView> yr(yv);
117 RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
118 IntSet yc(yrc);
119 ConstSetView cy(home, yc);
120
121 GECODE_ES_FAIL(
122 (Intersection<ConstSetView,
123 SetView,SetView>
124 ::post(home,cy,xv,tmp)));
125 }
126 break;
127 case SRT_DISJ:
128 {
129 SetVar tmp(home);
130 SetView tmpv(tmp);
131 IntSetRanges zi(z);
132 GECODE_ME_FAIL( tmpv.excludeI(home, zi));
133
134 GlbRanges<ConstSetView> yr(yv);
135 RangesCompl<GlbRanges<ConstSetView> > yrc(yr);
136 IntSet yc(yrc);
137 ConstSetView cy(home, yc);
138 GECODE_ES_FAIL(
139 (Intersection<ConstSetView,
140 SetView,SetView>
141 ::post(home,cy,x,tmp)));
142 }
143 break;
144 case SRT_CMPL:
145 {
146 SetView xv(x);
147 ComplementView<SetView> cx(xv);
148 GECODE_ES_FAIL(
149 (Union<ConstSetView,
150 ComplementView<SetView>,
151 ConstSetView>::post(home, yv, cx, zv)));
152 }
153 break;
154 default:
155 throw UnknownRelation("Set::rel");
156 }
157 } else {
158 rel(home, y, op, x, r, z);
159 }
160 }
161
162}
163
164// STATISTICS: set-post