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
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
* Last modified:
10
* $Date: 2016-05-23 22:18:23 +0200 (Mon, 23 May 2016) $ by $Author: schulte $
11
* $Revision: 15073 $
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/element.hh
>
39
40
namespace
Gecode
{
41
42
void
43
element
(
Home
home,
IntSharedArray
c
,
IntVar
x0,
IntVar
x1,
44
IntPropLevel
) {
45
using namespace
Int;
46
if
(
c
.size() == 0)
47
throw
TooFewArguments
(
"Int::element"
);
48
GECODE_POST
;
49
for
(
int
i
=
c
.size();
i
--; )
50
Limits::check
(
c
[
i
],
"Int::element"
);
51
GECODE_ES_FAIL
((Element::post_int<IntView,IntView>(home,
c
,x0,x1)));
52
}
53
54
void
55
element
(
Home
home,
IntSharedArray
c
,
IntVar
x0,
BoolVar
x1,
56
IntPropLevel
) {
57
using namespace
Int;
58
if
(
c
.size() == 0)
59
throw
TooFewArguments
(
"Int::element"
);
60
GECODE_POST
;
61
for
(
int
i
=
c
.size();
i
--; )
62
Limits::check
(
c
[
i
],
"Int::element"
);
63
GECODE_ES_FAIL
((Element::post_int<IntView,BoolView>(home,
c
,x0,x1)));
64
}
65
66
void
67
element
(
Home
home,
IntSharedArray
c
,
IntVar
x0,
int
x1,
68
IntPropLevel
) {
69
using namespace
Int;
70
if
(
c
.size() == 0)
71
throw
TooFewArguments
(
"Int::element"
);
72
Limits::check
(x1,
"Int::element"
);
73
GECODE_POST
;
74
for
(
int
i
=
c
.size();
i
--; )
75
Limits::check
(
c
[
i
],
"Int::element"
);
76
ConstIntView
cx1(x1);
77
GECODE_ES_FAIL
(
78
(Element::post_int<IntView,ConstIntView>(home,
c
,x0,cx1)));
79
}
80
81
void
82
element
(
Home
home,
const
IntVarArgs
&
c
,
IntVar
x0,
IntVar
x1,
83
IntPropLevel
ipl) {
84
using namespace
Int;
85
if
(
c
.size() == 0)
86
throw
TooFewArguments
(
"Int::element"
);
87
GECODE_POST
;
88
IdxViewArray<IntView>
iv(home,
c
);
89
if
((
vbd
(ipl) ==
IPL_DOM
) || (
vbd
(ipl) ==
IPL_DEF
)) {
90
GECODE_ES_FAIL
((
Element::ViewDom<IntView,IntView,IntView>
91
::
post
(home,iv,x0,x1)));
92
}
else
{
93
GECODE_ES_FAIL
((
Element::ViewBnd<IntView,IntView,IntView>
94
::
post
(home,iv,x0,x1)));
95
}
96
}
97
98
void
99
element
(
Home
home,
const
IntVarArgs
&
c
,
IntVar
x0,
int
x1,
100
IntPropLevel
ipl) {
101
using namespace
Int;
102
if
(
c
.size() == 0)
103
throw
TooFewArguments
(
"Int::element"
);
104
Limits::check
(x1,
"Int::element"
);
105
GECODE_POST
;
106
IdxViewArray<IntView>
iv(home,
c
);
107
ConstIntView
v1
(x1);
108
if
((
vbd
(ipl) ==
IPL_DOM
) || (
vbd
(ipl) ==
IPL_DEF
)) {
109
GECODE_ES_FAIL
((
Element::ViewDom<IntView,IntView,ConstIntView>
110
::
post
(home,iv,x0,
v1
)));
111
}
else
{
112
GECODE_ES_FAIL
((
Element::ViewBnd<IntView,IntView,ConstIntView>
113
::
post
(home,iv,x0,
v1
)));
114
}
115
}
116
117
void
118
element
(
Home
home,
const
BoolVarArgs
&
c
,
IntVar
x0,
BoolVar
x1,
119
IntPropLevel
) {
120
using namespace
Int;
121
if
(
c
.size() == 0)
122
throw
TooFewArguments
(
"Int::element"
);
123
GECODE_POST
;
124
IdxViewArray<BoolView>
iv(home,
c
);
125
GECODE_ES_FAIL
((
Element::ViewBnd<BoolView,IntView,BoolView>
126
::
post
(home,iv,x0,x1)));
127
}
128
129
void
130
element
(
Home
home,
const
BoolVarArgs
&
c
,
IntVar
x0,
int
x1,
131
IntPropLevel
) {
132
using namespace
Int;
133
if
(
c
.size() == 0)
134
throw
TooFewArguments
(
"Int::element"
);
135
Limits::check
(x1,
"Int::element"
);
136
GECODE_POST
;
137
IdxViewArray<BoolView>
iv(home,
c
);
138
ConstIntView
v1
(x1);
139
GECODE_ES_FAIL
((
Element::ViewBnd<BoolView,IntView,ConstIntView>
140
::
post
(home,iv,x0,
v1
)));
141
}
142
143
namespace
{
144
IntVar
145
pair(Home home, IntVar
x
,
int
w, IntVar
y
,
int
h) {
146
IntVar xy(home,0,w*h-1);
147
if
(
Int::Element::Pair::post
(home,
x
,
y
,xy,w,h) !=
ES_OK
)
148
home.fail();
149
return
xy;
150
}
151
}
152
153
void
154
element
(
Home
home,
IntSharedArray
a
,
155
IntVar
x
,
int
w,
IntVar
y
,
int
h,
IntVar
z
,
156
IntPropLevel
ipl) {
157
using namespace
Int;
158
if
(
a
.size() != w*h)
159
throw
Int::ArgumentSizeMismatch
(
"Int::element"
);
160
GECODE_POST
;
161
element
(home,
a
, pair(home,
x
,w,
y
,h),
z
, ipl);
162
}
163
164
void
165
element
(
Home
home,
IntSharedArray
a
,
166
IntVar
x
,
int
w,
IntVar
y
,
int
h,
BoolVar
z
,
167
IntPropLevel
ipl) {
168
using namespace
Int;
169
if
(
a
.size() != w*h)
170
throw
Int::ArgumentSizeMismatch
(
"Int::element"
);
171
GECODE_POST
;
172
element
(home,
a
, pair(home,
x
,w,
y
,h),
z
, ipl);
173
}
174
175
void
176
element
(
Home
home,
const
IntVarArgs
&
a
,
177
IntVar
x
,
int
w,
IntVar
y
,
int
h,
IntVar
z
,
178
IntPropLevel
ipl) {
179
using namespace
Int;
180
if
(
a
.size() != w*h)
181
throw
Int::ArgumentSizeMismatch
(
"Int::element"
);
182
GECODE_POST
;
183
element
(home,
a
, pair(home,
x
,w,
y
,h),
z
, ipl);
184
}
185
186
void
187
element
(
Home
home,
const
BoolVarArgs
&
a
,
188
IntVar
x
,
int
w,
IntVar
y
,
int
h,
BoolVar
z
,
189
IntPropLevel
ipl) {
190
using namespace
Int;
191
if
(
a
.size() != w*h)
192
throw
Int::ArgumentSizeMismatch
(
"Int::element"
);
193
GECODE_POST
;
194
element
(home,
a
, pair(home,
x
,w,
y
,h),
z
, ipl);
195
}
196
197
}
198
199
// STATISTICS: int-post
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::Int::ArgumentSizeMismatch
Exception: Arguments are of different size
Definition:
exception.hpp:77
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::Int::IdxViewArray
An array of IdxView pairs.
Definition:
idx-view.hh:71
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:639
Gecode::element
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
Post domain consistent propagator for .
Definition:
element.cpp:43
Gecode::z
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition:
set.hh:784
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Test::Int::Distinct::v1
Gecode::IntArgs v1(4, Gecode::Int::Limits::min+4, 0, 1, Gecode::Int::Limits::max)
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
Test::Int::Element::c
Create c
Definition:
element.cpp:614
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition:
int.hh:955
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:47
Gecode
Gecode toplevel namespace
Gecode::vbd
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition:
ipl.hpp:41
Gecode::Int::Element::ViewBnd
Bounds consistent element propagator for array of views.
Definition:
element.hh:236
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:693
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
a
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
element.hh
Gecode::Int::Element::ViewDom
Domain consistent element propagator for array of views.
Definition:
element.hh:266
Gecode::BoolVar
Boolean integer variables.
Definition:
int.hh:494
Gecode::IPL_DOM
@ IPL_DOM
Domain propagation Preferences: prefer speed or memory.
Definition:
int.hh:960
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition:
trace-filter.cpp:142
Gecode::IntVar
Integer variables.
Definition:
int.hh:353
Gecode::IPL_DEF
@ IPL_DEF
Simple propagation levels.
Definition:
int.hh:957
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:44
Gecode::SharedArray< int >
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition:
core.hpp:544
Gecode::Int::TooFewArguments
Exception: Too few arguments available in argument array
Definition:
exception.hpp:70