main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
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: 2016-11-08 17:23:24 +0100 (Tue, 08 Nov 2016) $ by $Author: schulte $
11
* $Revision: 15253 $
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
irt,
int
y
,
45
IntPropLevel
) {
46
using namespace
Int;
47
Limits::check
(
y
,
"Int::nvalues"
);
48
// Due to the quadratic Boolean matrix used in propagation
49
long
long
int
n
=
x
.size();
50
Limits::check
(
n
*
n
,
"Int::nvalues"
);
51
52
GECODE_POST
;
53
54
ViewArray<IntView>
xv(home,
x
);
55
56
switch
(irt) {
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
irt,
IntVar
y
,
95
IntPropLevel
) {
96
using namespace
Int;
97
// Due to the quadratic Boolean matrix used in propagation
98
long
long
int
n
=
x
.size();
99
Limits::check
(
n
*
n
,
"Int::nvalues"
);
100
101
GECODE_POST
;
102
103
if
(
y
.
assigned
()) {
104
nvalues
(home,
x
, irt,
y
.val());
105
return
;
106
}
107
108
ViewArray<IntView>
xv(home,
x
);
109
110
switch
(irt) {
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,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
irt,
int
y
,
146
IntPropLevel
) {
147
using namespace
Int;
148
Limits::check
(
y
,
"Int::nvalues"
);
149
150
GECODE_POST
;
151
152
Region
region(home);
153
ViewArray<BoolView>
xv(region,
x
);
154
155
switch
(irt) {
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
irt,
IntVar
y
,
194
IntPropLevel
) {
195
using namespace
Int;
196
197
GECODE_POST
;
198
199
if
(
y
.
assigned
()) {
200
nvalues
(home,
x
, irt,
y
.val());
201
return
;
202
}
203
204
Region
region(home);
205
ViewArray<BoolView>
xv(region,
x
);
206
207
switch
(irt) {
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,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
nvalues.hh
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::IntRelType
IntRelType
Relation types for integers.
Definition:
int.hh:906
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:784
Gecode::Int::ConstIntView
Constant integer view.
Definition:
view.hpp:804
GECODE_ES_FAIL
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition:
macros.hpp:107
Gecode::IRT_GQ
@ IRT_GQ
Greater or equal ( )
Definition:
int.hh:911
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:639
Gecode::IRT_LE
@ IRT_LE
Less ( )
Definition:
int.hh:910
Gecode::Int::NValues::EqInt
Equal to number of values propagator for integer views.
Definition:
nvalues.hh:191
Gecode::z
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition:
set.hh:784
Gecode::Int::Limits::check
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition:
limits.hpp:50
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition:
int.hh:955
Gecode::Int::NValues::GqBool
Greater or equal to number of values propagator for Boolean views.
Definition:
nvalues.hh:397
Gecode::VarImpVar::assigned
bool assigned(void) const
Test whether view is assigned.
Definition:
var.hpp:123
Gecode::nvalues
void nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntPropLevel)
Post propagator for .
Definition:
nvalues.cpp:44
Gecode::Int::Rel::Nq
Binary disequality propagator.
Definition:
rel.hh:464
Gecode::Int::NValues::EqBool
Equal to number of values propagator for Boolean views.
Definition:
nvalues.hh:333
Gecode
Gecode toplevel namespace
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:693
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
Gecode::Region
Handle to region.
Definition:
region.hpp:61
Gecode::IntVar
Integer variables.
Definition:
int.hh:353
Gecode::Int::NValues::LqInt
Less or equal to number of values propagator for integer views.
Definition:
nvalues.hh:225
Gecode::Int::OffsetView
Offset integer view.
Definition:
view.hpp:422
Gecode::Int::NValues::LqBool
Less or equal to number of values propagator for Boolean views.
Definition:
nvalues.hh:365
rel.hh
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:44
Gecode::Int::IntView
Integer view for integer variables.
Definition:
view.hpp:129
GECODE_ME_FAIL
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition:
macros.hpp:81
Gecode::IRT_EQ
@ IRT_EQ
Equality ( )
Definition:
int.hh:907
Gecode::Int::UnknownRelation
Exception: Unknown relation passed as argument
Definition:
exception.hpp:91
Gecode::IRT_NQ
@ IRT_NQ
Disequality ( )
Definition:
int.hh:908
Gecode::ViewArray< IntView >
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::IRT_GR
@ IRT_GR
Greater ( )
Definition:
int.hh:912
Gecode::IRT_LQ
@ IRT_LQ
Less or equal ( )
Definition:
int.hh:909
Gecode::Int::NValues::GqInt
Greater or equal to number of values propagator for integer views.
Definition:
nvalues.hh:257