main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 26 2012 08:43:21 for Gecode by
doxygen
1.8.1.1
gecode
set
rel-op-const-vcc.cpp
Go to the documentation of this file.
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
* Last modified:
13
* $Date: 2011-08-25 00:34:16 +1000 (Thu, 25 Aug 2011) $ by $Author: tack $
14
* $Revision: 12346 $
15
*
16
* This file is part of Gecode, the generic constraint
17
* development environment:
18
* http://www.gecode.org
19
*
20
* Permission is hereby granted, free of charge, to any person obtaining
21
* a copy of this software and associated documentation files (the
22
* "Software"), to deal in the Software without restriction, including
23
* without limitation the rights to use, copy, modify, merge, publish,
24
* distribute, sublicense, and/or sell copies of the Software, and to
25
* permit persons to whom the Software is furnished to do so, subject to
26
* the following conditions:
27
*
28
* The above copyright notice and this permission notice shall be
29
* included in all copies or substantial portions of the Software.
30
*
31
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38
*
39
*/
40
41
#include <
gecode/set.hh
>
42
#include <
gecode/set/rel.hh
>
43
#include <
gecode/set/rel-op.hh
>
44
45
namespace
Gecode {
46
using namespace
Gecode::Set;
47
using namespace
Gecode::Set::Rel;
48
using namespace
Gecode::Set::RelOp;
49
50
void
51
rel
(
Home
home,
SetVar
x,
SetOpType
op,
const
IntSet
& y,
SetRelType
r
,
52
const
IntSet
& z) {
53
Set::Limits::check
(y,
"Set::rel"
);
54
Set::Limits::check
(z,
"Set::rel"
);
55
ConstSetView
yv(home, y);
56
ConstSetView
zv(home, z);
57
58
if
(op==
SOT_MINUS
) {
59
switch
(r) {
60
case
SRT_EQ
:
61
{
62
GlbRanges<ConstSetView>
yr(yv);
63
RangesCompl<GlbRanges<ConstSetView>
> yrc(yr);
64
IntSet
yc(yrc);
65
ConstSetView
cy(home, yc);
66
GECODE_ES_FAIL
(
67
(
Intersection
<
ConstSetView
,
68
SetView
,
ConstSetView
>
69
::
post
(home,cy,x,zv)));
70
}
71
break
;
72
case
SRT_LQ
:
case
SRT_LE
:
case
SRT_GQ
:
case
SRT_GR
:
73
{
74
GlbRanges<ConstSetView>
yr(yv);
75
RangesCompl<GlbRanges<ConstSetView>
> yrc(yr);
76
IntSet
yc(yrc);
77
ConstSetView
cy(home, yc);
78
SetVar
tmp(home,
IntSet::empty
,
Set::Limits::min
,
Set::Limits::max
);
79
GECODE_ES_FAIL
(
80
(
Intersection
<
ConstSetView
,
81
SetView
,
SetView
>
82
::
post
(home,cy,x,tmp)));
83
dom
(home,tmp,r,z);
84
}
85
break
;
86
case
SRT_NQ
:
87
{
88
SetVar
tmp(home);
89
GECODE_ES_FAIL
(
90
(
Distinct<SetView,ConstSetView>
91
::
post
(home,tmp,zv)));
92
GlbRanges<ConstSetView>
yr(yv);
93
RangesCompl<GlbRanges<ConstSetView>
> yrc(yr);
94
IntSet
yc(yrc);
95
ConstSetView
cy(home, yc);
96
GECODE_ES_FAIL
(
97
(
Intersection
<
ConstSetView
,
98
SetView
,
SetView
>
99
::
post
(home,cy,x,tmp)));
100
}
101
break
;
102
case
SRT_SUB
:
103
{
104
GlbRanges<ConstSetView>
yr(yv);
105
RangesCompl<GlbRanges<ConstSetView>
> yrc(yr);
106
IntSet
yc(yrc);
107
ConstSetView
cy(home, yc);
108
GECODE_ES_FAIL
(
109
(
SuperOfInter<ConstSetView,SetView,ConstSetView>
110
::
post
(home,cy,x,zv)));
111
112
}
113
break
;
114
case
SRT_SUP
:
115
{
116
// z <= tmp
117
SetVar
tmp(home,z,
Limits::min
,
Limits::max
);
118
SetView
xv(x);
119
120
GlbRanges<ConstSetView>
yr(yv);
121
RangesCompl<GlbRanges<ConstSetView>
> yrc(yr);
122
IntSet
yc(yrc);
123
ConstSetView
cy(home, yc);
124
125
GECODE_ES_FAIL
(
126
(
Intersection
<
ConstSetView
,
127
SetView
,
SetView
>
128
::
post
(home,cy,xv,tmp)));
129
}
130
break
;
131
case
SRT_DISJ
:
132
{
133
SetVar
tmp(home);
134
SetView
tmpv(tmp);
135
IntSetRanges
zi(z);
136
GECODE_ME_FAIL
( tmpv.
excludeI
(home, zi));
137
138
GlbRanges<ConstSetView>
yr(yv);
139
RangesCompl<GlbRanges<ConstSetView>
> yrc(yr);
140
IntSet
yc(yrc);
141
ConstSetView
cy(home, yc);
142
GECODE_ES_FAIL
(
143
(
Intersection
<
ConstSetView
,
144
SetView
,
SetView
>
145
::
post
(home,cy,x,tmp)));
146
}
147
break
;
148
case
SRT_CMPL
:
149
{
150
SetView
xv(x);
151
ComplementView<SetView>
cx(xv);
152
GECODE_ES_FAIL
(
153
(
Union
<
ConstSetView
,
154
ComplementView<SetView>
,
155
ConstSetView
>::
post
(home, yv, cx, zv)));
156
}
157
break
;
158
default
:
159
throw
UnknownRelation
(
"Set::rel"
);
160
}
161
}
else
{
162
rel
(home, y, op, x, r, z);
163
}
164
}
165
166
}
167
168
// STATISTICS: set-post