main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 for Gecode by
doxygen
1.8.17
gecode
int
element.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, 2004
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/element.hh
>
35
36
namespace
Gecode
{
37
38
void
39
element
(
Home
home,
IntSharedArray
c
,
IntVar
x0,
IntVar
x1,
40
IntPropLevel
) {
41
using namespace
Int;
42
if
(
c
.size() == 0)
43
throw
TooFewArguments
(
"Int::element"
);
44
GECODE_POST
;
45
for
(
int
i
=0;
i
<
c
.size();
i
++)
46
Limits::check
(
c
[
i
],
"Int::element"
);
47
GECODE_ES_FAIL
((Element::post_int<IntView,IntView>(home,
c
,x0,x1)));
48
}
49
50
void
51
element
(
Home
home,
IntSharedArray
c
,
IntVar
x0,
BoolVar
x1,
52
IntPropLevel
) {
53
using namespace
Int;
54
if
(
c
.size() == 0)
55
throw
TooFewArguments
(
"Int::element"
);
56
GECODE_POST
;
57
for
(
int
i
=0;
i
<
c
.size();
i
++)
58
Limits::check
(
c
[
i
],
"Int::element"
);
59
GECODE_ES_FAIL
((Element::post_int<IntView,BoolView>(home,
c
,x0,x1)));
60
}
61
62
void
63
element
(
Home
home,
IntSharedArray
c
,
IntVar
x0,
int
x1,
64
IntPropLevel
) {
65
using namespace
Int;
66
if
(
c
.size() == 0)
67
throw
TooFewArguments
(
"Int::element"
);
68
Limits::check
(x1,
"Int::element"
);
69
GECODE_POST
;
70
for
(
int
i
=0;
i
<
c
.size();
i
++)
71
Limits::check
(
c
[
i
],
"Int::element"
);
72
ConstIntView
cx1(x1);
73
GECODE_ES_FAIL
(
74
(Element::post_int<IntView,ConstIntView>(home,
c
,x0,cx1)));
75
}
76
77
void
78
element
(
Home
home,
const
IntVarArgs
&
c
,
IntVar
x0,
IntVar
x1,
79
IntPropLevel
ipl) {
80
using namespace
Int;
81
if
(
c
.size() == 0)
82
throw
TooFewArguments
(
"Int::element"
);
83
GECODE_POST
;
84
IdxViewArray<IntView>
iv(home,
c
);
85
if
((
vbd
(ipl) ==
IPL_DOM
) || (
vbd
(ipl) ==
IPL_DEF
)) {
86
GECODE_ES_FAIL
((
Element::ViewDom<IntView,IntView,IntView>
87
::
post
(home,iv,x0,x1)));
88
}
else
{
89
GECODE_ES_FAIL
((
Element::ViewBnd<IntView,IntView,IntView>
90
::
post
(home,iv,x0,x1)));
91
}
92
}
93
94
void
95
element
(
Home
home,
const
IntVarArgs
&
c
,
IntVar
x0,
int
x1,
96
IntPropLevel
ipl) {
97
using namespace
Int;
98
if
(
c
.size() == 0)
99
throw
TooFewArguments
(
"Int::element"
);
100
Limits::check
(x1,
"Int::element"
);
101
GECODE_POST
;
102
IdxViewArray<IntView>
iv(home,
c
);
103
ConstIntView
v1
(x1);
104
if
((
vbd
(ipl) ==
IPL_DOM
) || (
vbd
(ipl) ==
IPL_DEF
)) {
105
GECODE_ES_FAIL
((
Element::ViewDom<IntView,IntView,ConstIntView>
106
::
post
(home,iv,x0,
v1
)));
107
}
else
{
108
GECODE_ES_FAIL
((
Element::ViewBnd<IntView,IntView,ConstIntView>
109
::
post
(home,iv,x0,
v1
)));
110
}
111
}
112
113
void
114
element
(
Home
home,
const
BoolVarArgs
&
c
,
IntVar
x0,
BoolVar
x1,
115
IntPropLevel
) {
116
using namespace
Int;
117
if
(
c
.size() == 0)
118
throw
TooFewArguments
(
"Int::element"
);
119
GECODE_POST
;
120
IdxViewArray<BoolView>
iv(home,
c
);
121
GECODE_ES_FAIL
((
Element::ViewBnd<BoolView,IntView,BoolView>
122
::
post
(home,iv,x0,x1)));
123
}
124
125
void
126
element
(
Home
home,
const
BoolVarArgs
&
c
,
IntVar
x0,
int
x1,
127
IntPropLevel
) {
128
using namespace
Int;
129
if
(
c
.size() == 0)
130
throw
TooFewArguments
(
"Int::element"
);
131
Limits::check
(x1,
"Int::element"
);
132
GECODE_POST
;
133
IdxViewArray<BoolView>
iv(home,
c
);
134
ConstIntView
v1
(x1);
135
GECODE_ES_FAIL
((
Element::ViewBnd<BoolView,IntView,ConstIntView>
136
::
post
(home,iv,x0,
v1
)));
137
}
138
139
namespace
{
140
IntVar
141
pair(Home home, IntVar
x
,
int
w, IntVar
y
,
int
h) {
142
IntVar xy(home,0,w*h-1);
143
if
(
Int::Element::Pair::post
(home,
x
,
y
,xy,w,h) !=
ES_OK
)
144
home.fail();
145
return
xy;
146
}
147
}
148
149
void
150
element
(
Home
home,
IntSharedArray
a
,
151
IntVar
x
,
int
w,
IntVar
y
,
int
h,
IntVar
z
,
152
IntPropLevel
ipl) {
153
using namespace
Int;
154
if
(
a
.size() != w*h)
155
throw
Int::ArgumentSizeMismatch
(
"Int::element"
);
156
GECODE_POST
;
157
element
(home,
a
, pair(home,
x
,w,
y
,h),
z
, ipl);
158
}
159
160
void
161
element
(
Home
home,
IntSharedArray
a
,
162
IntVar
x
,
int
w,
IntVar
y
,
int
h,
BoolVar
z
,
163
IntPropLevel
ipl) {
164
using namespace
Int;
165
if
(
a
.size() != w*h)
166
throw
Int::ArgumentSizeMismatch
(
"Int::element"
);
167
GECODE_POST
;
168
element
(home,
a
, pair(home,
x
,w,
y
,h),
z
, ipl);
169
}
170
171
void
172
element
(
Home
home,
const
IntVarArgs
&
a
,
173
IntVar
x
,
int
w,
IntVar
y
,
int
h,
IntVar
z
,
174
IntPropLevel
ipl) {
175
using namespace
Int;
176
if
(
a
.size() != w*h)
177
throw
Int::ArgumentSizeMismatch
(
"Int::element"
);
178
GECODE_POST
;
179
element
(home,
a
, pair(home,
x
,w,
y
,h),
z
, ipl);
180
}
181
182
void
183
element
(
Home
home,
const
BoolVarArgs
&
a
,
184
IntVar
x
,
int
w,
IntVar
y
,
int
h,
BoolVar
z
,
185
IntPropLevel
ipl) {
186
using namespace
Int;
187
if
(
a
.size() != w*h)
188
throw
Int::ArgumentSizeMismatch
(
"Int::element"
);
189
GECODE_POST
;
190
element
(home,
a
, pair(home,
x
,w,
y
,h),
z
, ipl);
191
}
192
193
}
194
195
// STATISTICS: int-post
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::Int::ArgumentSizeMismatch
Exception: Arguments are of different size
Definition:
exception.hpp:73
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::Int::IdxViewArray
An array of IdxView pairs.
Definition:
idx-view.hh:67
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:656
Gecode::element
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
Post domain consistent propagator for .
Definition:
element.cpp:39
Test::Int::Distinct::v1
Gecode::IntArgs v1({Gecode::Int::Limits::min+4, 0, 1, Gecode::Int::Limits::max})
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
Test::Int::Element::c
Create c
Definition:
element.cpp:610
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition:
int.hh:974
Gecode::Int::Element::Pair::post
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition:
pair.hpp:43
Gecode
Gecode toplevel namespace
Gecode::vbd
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition:
ipl.hpp:37
Gecode::Int::Element::ViewBnd
Bounds consistent element propagator for array of views.
Definition:
element.hh:232
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:712
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
element.hh
Gecode::Int::Element::ViewDom
Domain consistent element propagator for array of views.
Definition:
element.hh:262
Gecode::BoolVar
Boolean integer variables.
Definition:
int.hh:512
Gecode::IPL_DOM
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition:
int.hh:979
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition:
filter.cpp:138
Gecode::IntVar
Integer variables.
Definition:
int.hh:371
a
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Gecode::IPL_DEF
@ IPL_DEF
Simple propagation levels.
Definition:
int.hh:976
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:40
Gecode::SharedArray
Shared array with arbitrary number of elements.
Definition:
shared-array.hpp:53
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition:
core.hpp:476
Gecode::Int::TooFewArguments
Exception: Too few arguments available in argument array
Definition:
exception.hpp:66