main page
modules
namespaces
classes
files
Gecode home
Generated on Wed Sep 5 2012 18:51:56 for Gecode by
doxygen
1.8.1.1
gecode
int
nvalues.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2011
8
*
9
* Last modified:
10
* $Date: 2011-08-22 00:27:00 +1000 (Mon, 22 Aug 2011) $ by $Author: schulte $
11
* $Revision: 12319 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#include <
gecode/int/nvalues.hh
>
39
#include <
gecode/int/rel.hh
>
40
41
namespace
Gecode {
42
43
void
44
nvalues
(
Home
home,
const
IntVarArgs
& x,
IntRelType
r
,
int
y,
45
IntConLevel
) {
46
using namespace
Int;
47
Limits::check
(y,
"Int::nvalues"
);
48
// Due to the quadratic Boolean matrix used in propagation
49
Limits::check
(static_cast<double>(x.
size
())*static_cast<double>(x.
size
()),
50
"Int::nvalues"
);
51
52
if
(home.
failed
())
return
;
53
54
ViewArray<IntView>
xv(home,x);
55
56
switch
(r) {
57
case
IRT_EQ
:
58
{
59
ConstIntView
yv(y);
60
GECODE_ES_FAIL
(
NValues::EqInt<ConstIntView>::post
(home,xv,yv));
61
}
62
break
;
63
case
IRT_NQ
:
64
{
65
IntVar
z(home,0,x.
size
());
66
GECODE_ME_FAIL
(
IntView
(z).nq(home,y));
67
GECODE_ES_FAIL
(
NValues::EqInt<IntView>::post
(home,xv,z));
68
}
69
break
;
70
case
IRT_LE
:
71
y--;
72
// Fall through
73
case
IRT_LQ
:
74
{
75
ConstIntView
yv(y);
76
GECODE_ES_FAIL
(
NValues::LqInt<ConstIntView>::post
(home,xv,yv));
77
}
78
break
;
79
case
IRT_GR
:
80
y++;
81
// Fall through
82
case
IRT_GQ
:
83
{
84
ConstIntView
yv(y);
85
GECODE_ES_FAIL
(
NValues::GqInt<ConstIntView>::post
(home,xv,yv));
86
}
87
break
;
88
default
:
89
throw
UnknownRelation
(
"Int::nvalues"
);
90
}
91
}
92
93
void
94
nvalues
(
Home
home,
const
IntVarArgs
& x,
IntRelType
r
,
IntVar
y,
95
IntConLevel
) {
96
using namespace
Int;
97
// Due to the quadratic Boolean matrix used in propagation
98
Limits::check
(static_cast<double>(x.
size
())*static_cast<double>(x.
size
()),
99
"Int::nvalues"
);
100
101
if
(home.
failed
())
return
;
102
103
if
(y.
assigned
()) {
104
nvalues
(home, x, r, y.
val
());
105
return
;
106
}
107
108
ViewArray<IntView>
xv(home,x);
109
110
switch
(r) {
111
case
IRT_EQ
:
112
GECODE_ES_FAIL
(
NValues::EqInt<IntView>::post
(home,xv,y));
113
break
;
114
case
IRT_NQ
:
115
{
116
IntVar
z(home,0,x.
size
());
117
GECODE_ES_FAIL
(
Rel::Nq<IntView>::post
(home,y,z));
118
GECODE_ES_FAIL
(
NValues::EqInt<IntView>::post
(home,xv,z));
119
}
120
break
;
121
case
IRT_LE
:
122
{
123
OffsetView
z(y,-1);
124
GECODE_ES_FAIL
(
NValues::LqInt<OffsetView>::post
(home,xv,z));
125
}
126
break
;
127
case
IRT_LQ
:
128
GECODE_ES_FAIL
(
NValues::LqInt<IntView>::post
(home,xv,y));
129
break
;
130
case
IRT_GR
:
131
{
132
OffsetView
z(y,1);
133
GECODE_ES_FAIL
(
NValues::GqInt<OffsetView>::post
(home,xv,z));
134
}
135
break
;
136
case
IRT_GQ
:
137
GECODE_ES_FAIL
(
NValues::GqInt<IntView>::post
(home,xv,y));
138
break
;
139
default
:
140
throw
UnknownRelation
(
"Int::nvalues"
);
141
}
142
}
143
144
void
145
nvalues
(
Home
home,
const
BoolVarArgs
& x,
IntRelType
r
,
int
y,
146
IntConLevel
) {
147
using namespace
Int;
148
Limits::check
(y,
"Int::nvalues"
);
149
150
if
(home.
failed
())
return
;
151
152
Region
region(home);
153
ViewArray<BoolView>
xv(region,x);
154
155
switch
(r) {
156
case
IRT_EQ
:
157
{
158
ConstIntView
yv(y);
159
GECODE_ES_FAIL
(
NValues::EqBool<ConstIntView>::post
(home,xv,yv));
160
}
161
break
;
162
case
IRT_NQ
:
163
{
164
IntVar
z(home,0,2);
165
GECODE_ME_FAIL
(
IntView
(z).nq(home,y));
166
GECODE_ES_FAIL
(
NValues::EqBool<IntView>::post
(home,xv,z));
167
}
168
break
;
169
case
IRT_LE
:
170
y--;
171
// Fall through
172
case
IRT_LQ
:
173
{
174
ConstIntView
yv(y);
175
GECODE_ES_FAIL
(
NValues::LqBool<ConstIntView>::post
(home,xv,yv));
176
}
177
break
;
178
case
IRT_GR
:
179
y++;
180
// Fall through
181
case
IRT_GQ
:
182
{
183
ConstIntView
yv(y);
184
GECODE_ES_FAIL
(
NValues::GqBool<ConstIntView>::post
(home,xv,yv));
185
}
186
break
;
187
default
:
188
throw
UnknownRelation
(
"Int::nvalues"
);
189
}
190
}
191
192
void
193
nvalues
(
Home
home,
const
BoolVarArgs
& x,
IntRelType
r
,
IntVar
y,
194
IntConLevel
) {
195
using namespace
Int;
196
197
if
(home.
failed
())
return
;
198
199
if
(y.
assigned
()) {
200
nvalues
(home, x, r, y.
val
());
201
return
;
202
}
203
204
Region
region(home);
205
ViewArray<BoolView>
xv(region,x);
206
207
switch
(r) {
208
case
IRT_EQ
:
209
GECODE_ES_FAIL
(
NValues::EqBool<IntView>::post
(home,xv,y));
210
break
;
211
case
IRT_NQ
:
212
{
213
IntVar
z(home,0,2);
214
GECODE_ES_FAIL
(
Rel::Nq<IntView>::post
(home,y,z));
215
GECODE_ES_FAIL
(
NValues::EqBool<IntView>::post
(home,xv,z));
216
}
217
break
;
218
case
IRT_LE
:
219
{
220
OffsetView
z(y,-1);
221
GECODE_ES_FAIL
(
NValues::LqBool<OffsetView>::post
(home,xv,z));
222
}
223
break
;
224
case
IRT_LQ
:
225
GECODE_ES_FAIL
(
NValues::LqBool<IntView>::post
(home,xv,y));
226
break
;
227
case
IRT_GR
:
228
{
229
OffsetView
z(y,1);
230
GECODE_ES_FAIL
(
NValues::GqBool<OffsetView>::post
(home,xv,z));
231
}
232
break
;
233
case
IRT_GQ
:
234
GECODE_ES_FAIL
(
NValues::GqBool<IntView>::post
(home,xv,y));
235
break
;
236
default
:
237
throw
UnknownRelation
(
"Int::nvalues"
);
238
}
239
}
240
241
}
242
243
// STATISTICS: int-post
244