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
channel.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
* Last modified:
12
* $Date: 2016-05-23 22:18:23 +0200 (Mon, 23 May 2016) $ by $Author: schulte $
13
* $Revision: 15073 $
14
*
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
*
38
*/
39
40
#include <
gecode/int/channel.hh
>
41
42
namespace
Gecode
{
43
44
void
45
channel
(
Home
home,
const
IntVarArgs
&
x
,
int
xoff,
46
const
IntVarArgs
&
y
,
int
yoff,
47
IntPropLevel
ipl) {
48
using namespace
Int;
49
using namespace
Channel;
50
int
n
=
x
.size();
51
if
(
n
!=
y
.size())
52
throw
ArgumentSizeMismatch
(
"Int::channel"
);
53
if
(
x
.
same
(home) ||
y
.
same
(home))
54
throw
ArgumentSame
(
"Int::channel"
);
55
Limits::check
(xoff,
"Int::channel"
);
56
Limits::check
(yoff,
"Int::channel"
);
57
if
((xoff < 0) || (yoff < 0))
58
throw
OutOfLimits
(
"Int::channel"
);
59
GECODE_POST
;
60
if
(
n
== 0)
61
return
;
62
63
if
((xoff < 2) && (yoff < 2) && (xoff == yoff)) {
64
if
(
vbd
(ipl) ==
IPL_DOM
) {
65
DomInfo<IntView,NoOffset<IntView> >* di =
66
static_cast<
Space
&
>
(home).
67
alloc<DomInfo<
IntView
,
NoOffset<IntView>
> >(2*(
n
+xoff));
68
for
(
int
i
=
n
;
i
--; ) {
69
di[xoff+
i
].init(
x
[
i
],
n
+xoff);
70
di[2*xoff+
i
+
n
].init(
y
[
i
],
n
+xoff);
71
}
72
if
(xoff == 1) {
73
IntVar
x0(home,0,0);
74
di[0].init(x0,
n
+xoff);
75
IntVar
y0(home,0,0);
76
di[
n
+xoff].init(y0,
n
+xoff);
77
}
78
NoOffset<IntView>
noff;
79
if
(
x
.
same
(home,
y
)) {
80
GECODE_ES_FAIL
((Dom<
IntView
,
NoOffset<IntView>
,
true
>
81
::
post
(home,
n
+xoff,di,noff,noff)));
82
}
else
{
83
GECODE_ES_FAIL
((Dom<
IntView
,
NoOffset<IntView>
,
false
>
84
::
post
(home,
n
+xoff,di,noff,noff)));
85
}
86
}
else
{
87
ValInfo<IntView>* vi =
88
static_cast<
Space
&
>
(home).alloc<ValInfo<IntView> >(2*(
n
+xoff));
89
for
(
int
i
=
n
;
i
--; ) {
90
vi[xoff+
i
].init(
x
[
i
],
n
+xoff);
91
vi[2*xoff+
i
+
n
].init(
y
[
i
],
n
+xoff);
92
}
93
if
(xoff == 1) {
94
IntVar
x0(home,0,0);
95
vi[0].init(x0,
n
+xoff);
96
IntVar
y0(home,0,0);
97
vi[
n
+xoff].init(y0,
n
+xoff);
98
}
99
NoOffset<IntView>
noff;
100
if
(
x
.
same
(home,
y
)) {
101
GECODE_ES_FAIL
((Val<
IntView
,
NoOffset<IntView>
,
true
>
102
::
post
(home,
n
+xoff,vi,noff,noff)));
103
}
else
{
104
GECODE_ES_FAIL
((Val<
IntView
,
NoOffset<IntView>
,
false
>
105
::
post
(home,
n
+xoff,vi,noff,noff)));
106
}
107
}
108
}
else
{
109
if
(
vbd
(ipl) ==
IPL_DOM
) {
110
DomInfo<IntView,Offset>* di =
111
static_cast<
Space
&
>
(home).alloc<DomInfo<IntView,Offset> >(2*
n
);
112
for
(
int
i
=
n
;
i
--; ) {
113
di[
i
].init(
x
[
i
],
n
);
114
di[
i
+
n
].init(
y
[
i
],
n
);
115
}
116
Offset
ox(-xoff);
117
Offset
oy(-yoff);
118
if
(
x
.
same
(home,
y
)) {
119
GECODE_ES_FAIL
((Dom<IntView,Offset,true>
120
::
post
(home,
n
,di,ox,oy)));
121
}
else
{
122
GECODE_ES_FAIL
((Dom<IntView,Offset,false>
123
::
post
(home,
n
,di,ox,oy)));
124
}
125
}
else
{
126
ValInfo<IntView>* vi =
127
static_cast<
Space
&
>
(home).alloc<ValInfo<IntView> >(2*
n
);
128
for
(
int
i
=
n
;
i
--; ) {
129
vi[
i
].init(
x
[
i
],
n
);
130
vi[
i
+
n
].init(
y
[
i
],
n
);
131
}
132
Offset
ox(-xoff);
133
Offset
oy(-yoff);
134
if
(
x
.
same
(home,
y
)) {
135
GECODE_ES_FAIL
((Val<IntView,Offset,true>
136
::
post
(home,
n
,vi,ox,oy)));
137
}
else
{
138
GECODE_ES_FAIL
((Val<IntView,Offset,false>
139
::
post
(home,
n
,vi,ox,oy)));
140
}
141
}
142
}
143
144
}
145
146
void
147
channel
(
Home
home,
const
IntVarArgs
&
x
,
const
IntVarArgs
&
y
,
148
IntPropLevel
ipl) {
149
channel
(home,
x
, 0,
y
, 0, ipl);
150
}
151
void
152
channel
(
Home
home,
BoolVar
x0,
IntVar
x1,
IntPropLevel
) {
153
using namespace
Int;
154
GECODE_POST
;
155
GECODE_ES_FAIL
(
Channel::LinkSingle::post
(home,x0,x1));
156
}
157
158
void
159
channel
(
Home
home,
const
BoolVarArgs
&
x
,
IntVar
y
,
int
o,
160
IntPropLevel
) {
161
using namespace
Int;
162
if
(
x
.
same
(home))
163
throw
ArgumentSame
(
"Int::channel"
);
164
Limits::check
(o,
"Int::channel"
);
165
GECODE_POST
;
166
ViewArray<BoolView>
xv(home,
x
);
167
GECODE_ES_FAIL
(
Channel::LinkMulti::post
(home,xv,
y
,o));
168
}
169
170
}
171
172
// 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_ES_FAIL
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition:
macros.hpp:107
Gecode::Int::Offset
Converter with fixed offset.
Definition:
view.hpp:617
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:639
Gecode::Int::Channel::LinkSingle::post
static ExecStatus post(Home home, BoolView x0, IntView x1)
Post propagator for .
Definition:
link-single.hpp:46
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::VarImpVar::same
bool same(const VarImpVar< VarImp > &y) const
Test whether variable is the same as y.
Definition:
var.hpp:133
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::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::Int::Channel::LinkMulti::post
static ExecStatus post(Home home, ViewArray< BoolView > &x, IntView y, int o)
Post propagator for .
Definition:
link-multi.hpp:57
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::ArgumentSame
Exception: Arguments contain same variable multiply
Definition:
exception.hpp:84
Gecode::Int::NoOffset
Converter without offsets.
Definition:
view.hpp:585
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:693
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
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
channel.hh
Gecode::IntVar
Integer variables.
Definition:
int.hh:353
Gecode::channel
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition:
channel.cpp:45
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::Int::OutOfLimits
Exception: Value out of limits
Definition:
exception.hpp:48
Gecode::ViewArray< BoolView >
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238