main page
modules
namespaces
classes
files
Gecode home
Generated on Wed Jan 1 2020 10:37:59 for Gecode by
doxygen
1.8.16
gecode
int
circuit.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
* Guido Tack <tack@gecode.org>
6
*
7
* Copyright:
8
* Christian Schulte, 2006
9
* Guido Tack, 2011
10
*
11
* This file is part of Gecode, the generic constraint
12
* development environment:
13
* http://www.gecode.org
14
*
15
* Permission is hereby granted, free of charge, to any person obtaining
16
* a copy of this software and associated documentation files (the
17
* "Software"), to deal in the Software without restriction, including
18
* without limitation the rights to use, copy, modify, merge, publish,
19
* distribute, sublicense, and/or sell copies of the Software, and to
20
* permit persons to whom the Software is furnished to do so, subject to
21
* the following conditions:
22
*
23
* The above copyright notice and this permission notice shall be
24
* included in all copies or substantial portions of the Software.
25
*
26
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
*
34
*/
35
36
#include <
gecode/int/circuit.hh
>
37
38
namespace
Gecode
{
39
40
void
41
circuit
(
Home
home,
int
offset,
const
IntVarArgs
&
x
,
IntPropLevel
ipl) {
42
Int::Limits::nonnegative
(offset,
"Int::circuit"
);
43
if
(
x
.size() == 0)
44
throw
Int::TooFewArguments
(
"Int::circuit"
);
45
if
(
same
(
x
))
46
throw
Int::ArgumentSame
(
"Int::circuit"
);
47
GECODE_POST
;
48
ViewArray<Int::IntView>
xv(home,
x
);
49
50
if
(offset == 0) {
51
typedef
Int::NoOffset<Int::IntView>
NOV;
52
NOV no;
53
if
(
vbd
(ipl) ==
IPL_DOM
) {
54
GECODE_ES_FAIL
((
Int::Circuit::Dom<Int::IntView,NOV>
55
::
post
(home,xv,no)));
56
}
else
{
57
GECODE_ES_FAIL
((
Int::Circuit::Val<Int::IntView,NOV>
58
::
post
(home,xv,no)));
59
}
60
}
else
{
61
typedef
Int::Offset
OV;
62
OV off(-offset);
63
if
(
vbd
(ipl) ==
IPL_DOM
) {
64
GECODE_ES_FAIL
((
Int::Circuit::Dom<Int::IntView,OV>
65
::
post
(home,xv,off)));
66
}
else
{
67
GECODE_ES_FAIL
((
Int::Circuit::Val<Int::IntView,OV>
68
::
post
(home,xv,off)));
69
}
70
}
71
}
72
void
73
circuit
(
Home
home,
const
IntVarArgs
&
x
,
IntPropLevel
ipl) {
74
circuit
(home,0,
x
,ipl);
75
}
76
77
void
78
circuit
(
Home
home,
const
IntArgs
&
c
,
int
offset,
79
const
IntVarArgs
&
x
,
const
IntVarArgs
&
y
,
IntVar
z
,
80
IntPropLevel
ipl) {
81
Int::Limits::nonnegative
(offset,
"Int::circuit"
);
82
int
n
=
x
.size();
83
if
(
n
== 0)
84
throw
Int::TooFewArguments
(
"Int::circuit"
);
85
if
(
same
(
x
))
86
throw
Int::ArgumentSame
(
"Int::circuit"
);
87
if
((
y
.size() !=
n
) || (
c
.size() !=
n
*
n
))
88
throw
Int::ArgumentSizeMismatch
(
"Int::circuit"
);
89
circuit
(home, offset,
x
, ipl);
90
GECODE_POST
;
91
IntArgs
cx(offset+
n
);
92
for
(
int
i
=0;
i
<offset;
i
++)
93
cx[
i
] = 0;
94
for
(
int
i
=0;
i
<
n
;
i
++) {
95
for
(
int
j=0; j<
n
; j++)
96
cx[offset+j] =
c
[
i
*
n
+j];
97
element
(home, cx,
x
[
i
],
y
[
i
]);
98
}
99
linear
(home,
y
,
IRT_EQ
,
z
);
100
}
101
void
102
circuit
(
Home
home,
const
IntArgs
&
c
,
103
const
IntVarArgs
&
x
,
const
IntVarArgs
&
y
,
IntVar
z
,
104
IntPropLevel
ipl) {
105
circuit
(home,
c
,0,
x
,
y
,
z
,ipl);
106
}
107
void
108
circuit
(
Home
home,
const
IntArgs
&
c
,
int
offset,
109
const
IntVarArgs
&
x
,
IntVar
z
,
110
IntPropLevel
ipl) {
111
Int::Limits::nonnegative
(offset,
"Int::circuit"
);
112
GECODE_POST
;
113
IntVarArgs
y
(home,
x
.size(),
Int::Limits::min
,
Int::Limits::max
);
114
circuit
(home,
c
, offset,
x
,
y
,
z
, ipl);
115
}
116
void
117
circuit
(
Home
home,
const
IntArgs
&
c
,
118
const
IntVarArgs
&
x
,
IntVar
z
,
119
IntPropLevel
ipl) {
120
circuit
(home,
c
,0,
x
,
z
,ipl);
121
}
122
123
void
124
path
(
Home
home,
int
offset,
const
IntVarArgs
&
x
,
IntVar
s,
IntVar
e,
125
IntPropLevel
ipl) {
126
Int::Limits::nonnegative
(offset,
"Int::path"
);
127
int
n
=
x
.size();
128
if
(
n
== 0)
129
throw
Int::TooFewArguments
(
"Int::path"
);
130
if
(
same
(
x
))
131
throw
Int::ArgumentSame
(
"Int::path"
);
132
GECODE_POST
;
133
ViewArray<Int::IntView>
xv(home,
n
+1);
134
for
(
int
i
=0;
i
<
n
;
i
++)
135
xv[
i
] =
Int::IntView
(
x
[
i
]);
136
xv[
n
] = s;
137
138
if
(offset == 0) {
139
element
(home,
x
, e,
n
);
140
typedef
Int::NoOffset<Int::IntView>
NOV;
141
NOV no;
142
if
(
vbd
(ipl) ==
IPL_DOM
) {
143
GECODE_ES_FAIL
((
Int::Circuit::Dom<Int::IntView,NOV>
144
::
post
(home,xv,no)));
145
}
else
{
146
GECODE_ES_FAIL
((
Int::Circuit::Val<Int::IntView,NOV>
147
::
post
(home,xv,no)));
148
}
149
}
else
{
150
IntVarArgs
ox(
n
+offset);
151
IntVar
y
(home, -1,-1);
152
for
(
int
i
=0;
i
<offset;
i
++)
153
ox[
i
] =
y
;
154
for
(
int
i
=0;
i
<
n
;
i
++)
155
ox[offset +
i
] =
x
[
i
];
156
element
(home, ox, e, offset+
n
);
157
typedef
Int::Offset
OV;
158
OV off(-offset);
159
if
(
vbd
(ipl) ==
IPL_DOM
) {
160
GECODE_ES_FAIL
((
Int::Circuit::Dom<Int::IntView,OV>
161
::
post
(home,xv,off)));
162
}
else
{
163
GECODE_ES_FAIL
((
Int::Circuit::Val<Int::IntView,OV>
164
::
post
(home,xv,off)));
165
}
166
}
167
}
168
void
169
path
(
Home
home,
const
IntVarArgs
&
x
,
IntVar
s,
IntVar
e,
170
IntPropLevel
ipl) {
171
path
(home,0,
x
,s,e,ipl);
172
}
173
174
void
175
path
(
Home
home,
const
IntArgs
&
c
,
int
offset,
176
const
IntVarArgs
&
x
,
IntVar
s,
IntVar
e,
177
const
IntVarArgs
&
y
,
IntVar
z
,
178
IntPropLevel
ipl) {
179
Int::Limits::nonnegative
(offset,
"Int::path"
);
180
int
n
=
x
.size();
181
if
(
n
== 0)
182
throw
Int::TooFewArguments
(
"Int::path"
);
183
if
(
same
(
x
))
184
throw
Int::ArgumentSame
(
"Int::path"
);
185
if
((
y
.size() !=
n
) || (
c
.size() !=
n
*
n
))
186
throw
Int::ArgumentSizeMismatch
(
"Int::path"
);
187
GECODE_POST
;
188
path
(home, offset,
x
, s, e, ipl);
189
IntArgs
cx(offset+
n
+1);
190
for
(
int
i
=0;
i
<offset;
i
++)
191
cx[
i
] = 0;
192
cx[offset+
n
] = 0;
193
for
(
int
i
=0;
i
<
n
;
i
++) {
194
for
(
int
j=0; j<
n
; j++)
195
cx[offset+j] =
c
[
i
*
n
+j];
196
element
(home, cx,
x
[
i
],
y
[
i
]);
197
}
198
linear
(home,
y
,
IRT_EQ
,
z
);
199
}
200
void
201
path
(
Home
home,
const
IntArgs
&
c
,
202
const
IntVarArgs
&
x
,
IntVar
s,
IntVar
e,
203
const
IntVarArgs
&
y
,
IntVar
z
,
204
IntPropLevel
ipl) {
205
path
(home,
c
,0,
x
,s,e,
y
,
z
,ipl);
206
}
207
void
208
path
(
Home
home,
const
IntArgs
&
c
,
int
offset,
209
const
IntVarArgs
&
x
,
IntVar
s,
IntVar
e,
IntVar
z
,
210
IntPropLevel
ipl) {
211
Int::Limits::nonnegative
(offset,
"Int::path"
);
212
GECODE_POST
;
213
IntVarArgs
y
(home,
x
.size(),
Int::Limits::min
,
Int::Limits::max
);
214
path
(home,
c
, offset,
x
, s, e,
y
,
z
, ipl);
215
}
216
void
217
path
(
Home
home,
const
IntArgs
&
c
,
218
const
IntVarArgs
&
x
,
IntVar
s,
IntVar
e,
IntVar
z
,
219
IntPropLevel
ipl) {
220
path
(home,
c
,0,
x
,s,e,
z
,ipl);
221
}
222
223
}
224
225
// 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_ES_FAIL
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition:
macros.hpp:103
Gecode::Int::Offset
Converter with fixed offset.
Definition:
view.hpp:650
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
circuit.hh
Gecode::z
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition:
set.hh:767
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition:
int.hh:974
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::ArgumentSame
Exception: Arguments contain same variable multiply
Definition:
exception.hpp:80
Gecode::Int::NoOffset
Converter without offsets.
Definition:
view.hpp:618
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::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::Int::Limits::nonnegative
void nonnegative(int n, const char *l)
Check whether n is in range and nonnegative, otherwise throw out of limits with information l.
Definition:
limits.hpp:68
Gecode::circuit
void circuit(Home home, int offset, const IntVarArgs &x, IntPropLevel ipl)
Post propagator such that x forms a circuit.
Definition:
circuit.cpp:41
Gecode::Int::Limits::max
const int max
Largest allowed integer value.
Definition:
int.hh:116
Gecode::IntVar
Integer variables.
Definition:
int.hh:371
Gecode::Int::Circuit::Dom
"Domain consistent" circuit propagator
Definition:
circuit.hh:121
Gecode::linear
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
Definition:
linear.cpp:41
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:40
Test::Int::Circuit::c
Create c
Definition:
circuit.cpp:354
Gecode::Int::IntView
Integer view for integer variables.
Definition:
view.hpp:129
Gecode::path
void path(Home home, int offset, const IntVarArgs &x, IntVar s, IntVar e, IntPropLevel ipl)
Post propagator such that x forms a Hamiltonian path.
Definition:
circuit.cpp:124
Gecode::Int::Limits::min
const int min
Smallest allowed integer value.
Definition:
int.hh:118
Gecode::IRT_EQ
Equality ( )
Definition:
int.hh:926
Gecode::same
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition:
array.hpp:1937
Gecode::ViewArray< Int::IntView >
Gecode::Int::Circuit::Val
"Value-consistent" circuit propagator
Definition:
circuit.hh:88
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::IntArgs
Passing integer arguments.
Definition:
int.hh:628
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::Int::TooFewArguments
Exception: Too few arguments available in argument array
Definition:
exception.hpp:66