main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:29 for Gecode by
doxygen
1.8.4
gecode
int
no-overlap
box.hpp
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
* Last modified:
10
* $Date: 2011-07-13 18:16:57 +0200 (Wed, 13 Jul 2011) $ by $Author: schulte $
11
* $Revision: 12192 $
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
namespace
Gecode {
namespace
Int {
namespace
NoOverlap {
39
40
/*
41
* Mandatory boxes
42
*
43
*/
44
template
<
class
Dim,
int
n>
45
forceinline
const
Dim&
46
ManBox<Dim,n>::operator []
(
int
i
)
const
{
47
assert((i >= 0) && (i <
n
));
48
return
d
[
i
];
49
}
50
template
<
class
Dim,
int
n>
51
forceinline
Dim&
52
ManBox<Dim,n>::operator []
(
int
i
) {
53
assert((i >= 0) && (i <
n
));
54
return
d
[
i
];
55
}
56
template
<
class
Dim,
int
n>
57
forceinline
int
58
ManBox<Dim,n>::dim
(
void
) {
59
return
n
;
60
}
61
62
template
<
class
Dim,
int
n>
63
forceinline
bool
64
ManBox<Dim,n>::mandatory
(
void
)
const
{
65
return
true
;
66
}
67
template
<
class
Dim,
int
n>
68
forceinline
bool
69
ManBox<Dim,n>::excluded
(
void
)
const
{
70
return
false
;
71
}
72
template
<
class
Dim,
int
n>
73
forceinline
bool
74
ManBox<Dim,n>::optional
(
void
)
const
{
75
return
false
;
76
}
77
78
template
<
class
Dim,
int
n>
79
forceinline
ExecStatus
80
ManBox<Dim,n>::exclude
(
Space
&) {
81
return
ES_FAILED
;
82
}
83
84
template
<
class
Dim,
int
n>
85
forceinline
bool
86
ManBox<Dim,n>::nooverlap
(
const
ManBox<Dim,n>
& box)
const
{
87
for
(
int
i
=0;
i
<
n
;
i
++)
88
if
((
d
[
i
].lec() <= box.
d
[
i
].ssc()) || (box.
d
[
i
].lec() <=
d
[
i
].ssc()))
89
return
true
;
90
return
false
;
91
}
92
93
template
<
class
Dim,
int
n>
94
forceinline
bool
95
ManBox<Dim,n>::overlap
(
const
ManBox<Dim,n>
& box)
const
{
96
for
(
int
i
=0;
i
<
n
;
i
++)
97
if
((
d
[
i
].sec() <= box.
d
[
i
].lsc()) || (box.
d
[
i
].sec() <=
d
[
i
].lsc()))
98
return
false
;
99
return
true
;
100
}
101
102
template
<
class
Dim,
int
n>
103
forceinline
ExecStatus
104
ManBox<Dim,n>::nooverlap
(
Space
& home,
ManBox<Dim,n>
& box) {
105
for
(
int
i
=0;
i
<
n
;
i
++)
106
if
((
d
[
i
].sec() <= box.
d
[
i
].lsc()) ||
107
(box.
d
[
i
].sec() <=
d
[
i
].lsc())) {
108
// Does not overlap for dimension i
109
for
(
int
j=
i
+1; j<
n
; j++)
110
if
((
d
[j].sec() <= box.
d
[j].lsc()) ||
111
(box.
d
[j].sec() <=
d
[j].lsc()))
112
return
ES_OK
;
113
// Does not overlap for only dimension i, hence propagate
114
d
[
i
].nooverlap(home, box.
d
[
i
]);
115
box.
d
[
i
].nooverlap(home,
d
[
i
]);
116
return
ES_OK
;
117
}
118
// Overlaps in all dimensions
119
return
ES_FAILED
;
120
}
121
122
template
<
class
Dim,
int
n>
123
forceinline
void
124
ManBox<Dim,n>::update
(
Space
& home,
bool
share,
ManBox<Dim,n>
&
b
) {
125
for
(
int
i
=0;
i
<
n
;
i
++)
126
d
[
i
].update(home,share,b.
d
[
i
]);
127
}
128
129
template
<
class
Dim,
int
n>
130
forceinline
void
131
ManBox<Dim,n>::subscribe
(
Space
& home,
Propagator
&
p
) {
132
for
(
int
i
=0;
i
<
n
;
i
++)
133
d
[
i
].
subscribe
(home,p);
134
}
135
template
<
class
Dim,
int
n>
136
forceinline
void
137
ManBox<Dim,n>::cancel
(
Space
& home,
Propagator
&
p
) {
138
for
(
int
i
=0;
i
<
n
;
i
++)
139
d
[
i
].
cancel
(home,p);
140
}
141
142
143
/*
144
* Optional boxes
145
*
146
*/
147
template
<
class
Dim,
int
n>
148
forceinline
void
149
OptBox<Dim,n>::optional
(
BoolView
o0) {
150
o = o0;
151
}
152
template
<
class
Dim,
int
n>
153
forceinline
bool
154
OptBox<Dim,n>::mandatory
(
void
)
const
{
155
return
o.one();
156
}
157
template
<
class
Dim,
int
n>
158
forceinline
bool
159
OptBox<Dim,n>::excluded
(
void
)
const
{
160
return
o.zero();
161
}
162
template
<
class
Dim,
int
n>
163
forceinline
bool
164
OptBox<Dim,n>::optional
(
void
)
const
{
165
return
o.none();
166
}
167
168
template
<
class
Dim,
int
n>
169
forceinline
ExecStatus
170
OptBox<Dim,n>::exclude
(
Space
& home) {
171
GECODE_ME_CHECK
(o.zero(home));
172
return
ES_OK
;
173
}
174
175
template
<
class
Dim,
int
n>
176
forceinline
void
177
OptBox<Dim,n>::update
(
Space
& home,
bool
share,
OptBox<Dim,n>
&
b
) {
178
ManBox<Dim,n>::update
(home, share, b);
179
o.update(home, share, b.
o
);
180
}
181
182
template
<
class
Dim,
int
n>
183
forceinline
void
184
OptBox<Dim,n>::subscribe
(
Space
& home,
Propagator
&
p
) {
185
ManBox<Dim,n>::subscribe
(home,p);
186
o.subscribe(home, p,
PC_BOOL_VAL
);
187
}
188
template
<
class
Dim,
int
n>
189
forceinline
void
190
OptBox<Dim,n>::cancel
(
Space
& home,
Propagator
&
p
) {
191
ManBox<Dim,n>::cancel
(home,p);
192
o.cancel(home, p,
PC_BOOL_VAL
);
193
}
194
195
}}}
196
197
// STATISTICS: int-prop
198