main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Jul 27 2020 00:00:00 for Gecode by
doxygen
1.8.18
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
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
#include <
gecode/int/nvalues.hh
>
35
#include <
gecode/int/rel.hh
>
36
37
namespace
Gecode
{
38
39
void
40
nvalues
(
Home
home,
const
IntVarArgs
&
x
,
IntRelType
irt,
int
y
,
41
IntPropLevel
) {
42
using namespace
Int;
43
Limits::check
(
y
,
"Int::nvalues"
);
44
// Due to the quadratic Boolean matrix used in propagation
45
long
long
int
n
=
x
.size();
46
Limits::check
(
n
*
n
,
"Int::nvalues"
);
47
48
GECODE_POST
;
49
50
ViewArray<IntView>
xv(home,
x
);
51
52
switch
(irt) {
53
case
IRT_EQ
:
54
{
55
ConstIntView
yv(
y
);
56
GECODE_ES_FAIL
(
NValues::EqInt<ConstIntView>::post
(home,xv,yv));
57
}
58
break
;
59
case
IRT_NQ
:
60
{
61
IntVar
z
(home,0,
x
.size());
62
GECODE_ME_FAIL
(
IntView
(
z
).nq(home,
y
));
63
GECODE_ES_FAIL
(
NValues::EqInt<IntView>::post
(home,xv,
z
));
64
}
65
break
;
66
case
IRT_LE
:
67
y
--;
68
// Fall through
69
case
IRT_LQ
:
70
{
71
ConstIntView
yv(
y
);
72
GECODE_ES_FAIL
(
NValues::LqInt<ConstIntView>::post
(home,xv,yv));
73
}
74
break
;
75
case
IRT_GR
:
76
y
++;
77
// Fall through
78
case
IRT_GQ
:
79
{
80
ConstIntView
yv(
y
);
81
GECODE_ES_FAIL
(
NValues::GqInt<ConstIntView>::post
(home,xv,yv));
82
}
83
break
;
84
default
:
85
throw
UnknownRelation
(
"Int::nvalues"
);
86
}
87
}
88
89
void
90
nvalues
(
Home
home,
const
IntVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
91
IntPropLevel
) {
92
using namespace
Int;
93
// Due to the quadratic Boolean matrix used in propagation
94
long
long
int
n
=
x
.size();
95
Limits::check
(
n
*
n
,
"Int::nvalues"
);
96
97
GECODE_POST
;
98
99
if
(
y
.
assigned
()) {
100
nvalues
(home,
x
, irt,
y
.val());
101
return
;
102
}
103
104
ViewArray<IntView>
xv(home,
x
);
105
106
switch
(irt) {
107
case
IRT_EQ
:
108
GECODE_ES_FAIL
(
NValues::EqInt<IntView>::post
(home,xv,
y
));
109
break
;
110
case
IRT_NQ
:
111
{
112
IntVar
z
(home,0,
x
.size());
113
GECODE_ES_FAIL
((
Rel::Nq<IntView,IntView>::post
(home,
y
,
z
)));
114
GECODE_ES_FAIL
(
NValues::EqInt<IntView>::post
(home,xv,
z
));
115
}
116
break
;
117
case
IRT_LE
:
118
{
119
OffsetView
z
(
y
,-1);
120
GECODE_ES_FAIL
(
NValues::LqInt<OffsetView>::post
(home,xv,
z
));
121
}
122
break
;
123
case
IRT_LQ
:
124
GECODE_ES_FAIL
(
NValues::LqInt<IntView>::post
(home,xv,
y
));
125
break
;
126
case
IRT_GR
:
127
{
128
OffsetView
z
(
y
,1);
129
GECODE_ES_FAIL
(
NValues::GqInt<OffsetView>::post
(home,xv,
z
));
130
}
131
break
;
132
case
IRT_GQ
:
133
GECODE_ES_FAIL
(
NValues::GqInt<IntView>::post
(home,xv,
y
));
134
break
;
135
default
:
136
throw
UnknownRelation
(
"Int::nvalues"
);
137
}
138
}
139
140
void
141
nvalues
(
Home
home,
const
BoolVarArgs
&
x
,
IntRelType
irt,
int
y
,
142
IntPropLevel
) {
143
using namespace
Int;
144
Limits::check
(
y
,
"Int::nvalues"
);
145
146
GECODE_POST
;
147
148
Region
region;
149
ViewArray<BoolView>
xv(region,
x
);
150
151
switch
(irt) {
152
case
IRT_EQ
:
153
{
154
ConstIntView
yv(
y
);
155
GECODE_ES_FAIL
(
NValues::EqBool<ConstIntView>::post
(home,xv,yv));
156
}
157
break
;
158
case
IRT_NQ
:
159
{
160
IntVar
z
(home,0,2);
161
GECODE_ME_FAIL
(
IntView
(
z
).nq(home,
y
));
162
GECODE_ES_FAIL
(
NValues::EqBool<IntView>::post
(home,xv,
z
));
163
}
164
break
;
165
case
IRT_LE
:
166
y
--;
167
// Fall through
168
case
IRT_LQ
:
169
{
170
ConstIntView
yv(
y
);
171
GECODE_ES_FAIL
(
NValues::LqBool<ConstIntView>::post
(home,xv,yv));
172
}
173
break
;
174
case
IRT_GR
:
175
y
++;
176
// Fall through
177
case
IRT_GQ
:
178
{
179
ConstIntView
yv(
y
);
180
GECODE_ES_FAIL
(
NValues::GqBool<ConstIntView>::post
(home,xv,yv));
181
}
182
break
;
183
default
:
184
throw
UnknownRelation
(
"Int::nvalues"
);
185
}
186
}
187
188
void
189
nvalues
(
Home
home,
const
BoolVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
190
IntPropLevel
) {
191
using namespace
Int;
192
193
GECODE_POST
;
194
195
if
(
y
.
assigned
()) {
196
nvalues
(home,
x
, irt,
y
.val());
197
return
;
198
}
199
200
Region
region;
201
ViewArray<BoolView>
xv(region,
x
);
202
203
switch
(irt) {
204
case
IRT_EQ
:
205
GECODE_ES_FAIL
(
NValues::EqBool<IntView>::post
(home,xv,
y
));
206
break
;
207
case
IRT_NQ
:
208
{
209
IntVar
z
(home,0,2);
210
GECODE_ES_FAIL
((
Rel::Nq<IntView,IntView>::post
(home,
y
,
z
)));
211
GECODE_ES_FAIL
(
NValues::EqBool<IntView>::post
(home,xv,
z
));
212
}
213
break
;
214
case
IRT_LE
:
215
{
216
OffsetView
z
(
y
,-1);
217
GECODE_ES_FAIL
(
NValues::LqBool<OffsetView>::post
(home,xv,
z
));
218
}
219
break
;
220
case
IRT_LQ
:
221
GECODE_ES_FAIL
(
NValues::LqBool<IntView>::post
(home,xv,
y
));
222
break
;
223
case
IRT_GR
:
224
{
225
OffsetView
z
(
y
,1);
226
GECODE_ES_FAIL
(
NValues::GqBool<OffsetView>::post
(home,xv,
z
));
227
}
228
break
;
229
case
IRT_GQ
:
230
GECODE_ES_FAIL
(
NValues::GqBool<IntView>::post
(home,xv,
y
));
231
break
;
232
default
:
233
throw
UnknownRelation
(
"Int::nvalues"
);
234
}
235
}
236
237
}
238
239
// STATISTICS: int-post
240
nvalues.hh
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::IntRelType
IntRelType
Relation types for integers.
Definition:
int.hh:925
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
Gecode::Int::ConstIntView
Constant integer view.
Definition:
view.hpp:851
GECODE_ES_FAIL
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition:
macros.hpp:103
Gecode::IRT_GQ
@ IRT_GQ
Greater or equal ( )
Definition:
int.hh:930
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:656
Gecode::IRT_LE
@ IRT_LE
Less ( )
Definition:
int.hh:929
Gecode::Int::NValues::EqInt
Equal to number of values propagator for integer views.
Definition:
nvalues.hh:185
Gecode::z
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition:
set.hh:767
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:46
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition:
int.hh:974
Gecode::Int::NValues::GqBool
Greater or equal to number of values propagator for Boolean views.
Definition:
nvalues.hh:391
Gecode::VarImpVar::assigned
bool assigned(void) const
Test whether view is assigned.
Definition:
var.hpp:111
Gecode::nvalues
void nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntPropLevel)
Post propagator for .
Definition:
nvalues.cpp:40
Gecode::Int::Rel::Nq
Binary disequality propagator.
Definition:
rel.hh:460
Gecode::Int::NValues::EqBool
Equal to number of values propagator for Boolean views.
Definition:
nvalues.hh:327
Gecode
Gecode toplevel namespace
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:712
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::Region
Handle to region.
Definition:
region.hpp:55
Gecode::IntVar
Integer variables.
Definition:
int.hh:371
Gecode::Int::NValues::LqInt
Less or equal to number of values propagator for integer views.
Definition:
nvalues.hh:219
Gecode::Int::OffsetView
Offset integer view.
Definition:
view.hpp:443
Gecode::Int::NValues::LqBool
Less or equal to number of values propagator for Boolean views.
Definition:
nvalues.hh:359
rel.hh
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:40
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:77
Gecode::IRT_EQ
@ IRT_EQ
Equality ( )
Definition:
int.hh:926
Gecode::Int::UnknownRelation
Exception: Unknown relation passed as argument
Definition:
exception.hpp:87
Gecode::IRT_NQ
@ IRT_NQ
Disequality ( )
Definition:
int.hh:927
Gecode::ViewArray< IntView >
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::IRT_GR
@ IRT_GR
Greater ( )
Definition:
int.hh:931
Gecode::IRT_LQ
@ IRT_LQ
Less or equal ( )
Definition:
int.hh:928
Gecode::Int::NValues::GqInt
Greater or equal to number of values propagator for integer views.
Definition:
nvalues.hh:251