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