main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Oct 22 2013 00:49:05 for Gecode by
doxygen
1.8.4
gecode
int
no-overlap
dim.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:55:08 +0200 (Wed, 13 Jul 2011) $ by $Author: schulte $
11
* $Revision: 12194 $
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
* Dimension with integer size
42
*
43
*/
44
forceinline
45
FixDim::FixDim
(
void
)
46
: s(0) {}
47
forceinline
48
FixDim::FixDim
(
IntView
c0,
int
s0)
49
:
c
(c0), s(s0) {}
50
51
forceinline
int
52
FixDim::ssc
(
void
)
const
{
53
return
c
.
min
();
54
}
55
forceinline
int
56
FixDim::lsc
(
void
)
const
{
57
return
c
.
max
();
58
}
59
forceinline
int
60
FixDim::sec
(
void
)
const
{
61
return
c
.
min
() +
s
;
62
}
63
forceinline
int
64
FixDim::lec
(
void
)
const
{
65
return
c
.
max
() +
s
;
66
}
67
68
forceinline
ExecStatus
69
FixDim::ssc
(
Space
& home,
int
n
) {
70
GECODE_ME_CHECK
(
c
.
gq
(home, n));
71
return
ES_OK
;
72
}
73
forceinline
ExecStatus
74
FixDim::lec
(
Space
& home,
int
n
) {
75
GECODE_ME_CHECK
(
c
.
lq
(home, n -
s
));
76
return
ES_OK
;
77
}
78
forceinline
ExecStatus
79
FixDim::nooverlap
(
Space
& home,
int
n
,
int
m) {
80
if
(n <= m) {
81
Iter::Ranges::Singleton
r
(n-
s
+1,m);
82
GECODE_ME_CHECK
(
c
.
minus_r
(home,r,
false
));
83
}
84
return
ES_OK
;
85
}
86
forceinline
ExecStatus
87
FixDim::nooverlap
(
Space
& home,
FixDim
&
d
) {
88
if
(d.
sec
() >
lsc
()) {
89
// Propagate that d must be after this
90
GECODE_ES_CHECK
(
lec
(home,d.
lsc
()));
91
GECODE_ES_CHECK
(d.
ssc
(home,
sec
()));
92
}
else
{
93
nooverlap
(home, d.
lsc
(), d.
sec
()-1);
94
}
95
return
ES_OK
;
96
}
97
98
forceinline
void
99
FixDim::update
(
Space
& home,
bool
share,
FixDim
&
d
) {
100
c
.
update
(home,share,d.
c
);
101
s
= d.
s
;
102
}
103
104
forceinline
void
105
FixDim::subscribe
(
Space
& home,
Propagator
&
p
) {
106
c
.
subscribe
(home,p,
PC_INT_DOM
);
107
}
108
forceinline
void
109
FixDim::cancel
(
Space
& home,
Propagator
&
p
) {
110
c
.
cancel
(home,p,
PC_INT_DOM
);
111
}
112
113
114
/*
115
* Dimension with integer view size
116
*
117
*/
118
forceinline
119
FlexDim::FlexDim
(
void
) {}
120
forceinline
121
FlexDim::FlexDim
(
IntView
c00,
IntView
s0,
IntView
c10)
122
: c0(c00), s(s0), c1(c10) {}
123
124
forceinline
int
125
FlexDim::ssc
(
void
)
const
{
126
return
c0
.
min
();
127
}
128
forceinline
int
129
FlexDim::lsc
(
void
)
const
{
130
return
c0
.
max
();
131
}
132
forceinline
int
133
FlexDim::sec
(
void
)
const
{
134
return
c1
.
min
();
135
}
136
forceinline
int
137
FlexDim::lec
(
void
)
const
{
138
return
c1
.
max
();
139
}
140
141
forceinline
ExecStatus
142
FlexDim::ssc
(
Space
& home,
int
n
) {
143
GECODE_ME_CHECK
(
c0
.
gq
(home, n));
144
return
ES_OK
;
145
}
146
forceinline
ExecStatus
147
FlexDim::lec
(
Space
& home,
int
n
) {
148
GECODE_ME_CHECK
(
c1
.
lq
(home, n));
149
return
ES_OK
;
150
}
151
forceinline
ExecStatus
152
FlexDim::nooverlap
(
Space
& home,
int
n
,
int
m) {
153
if
(n <= m) {
154
Iter::Ranges::Singleton
r0(n-
s
.
min
()+1,m);
155
GECODE_ME_CHECK
(
c0
.
minus_r
(home,r0,
false
));
156
Iter::Ranges::Singleton
r1(n+1,
s
.
min
()+m);
157
GECODE_ME_CHECK
(
c1
.
minus_r
(home,r1,
false
));
158
}
159
return
ES_OK
;
160
}
161
forceinline
ExecStatus
162
FlexDim::nooverlap
(
Space
& home,
FlexDim
&
d
) {
163
if
(d.
sec
() >
lsc
()) {
164
// Propagate that d must be after this
165
GECODE_ES_CHECK
(
lec
(home,d.
lsc
()));
166
GECODE_ES_CHECK
(d.
ssc
(home,
sec
()));
167
}
else
{
168
nooverlap
(home, d.
lsc
(), d.
sec
()-1);
169
}
170
return
ES_OK
;
171
}
172
173
174
forceinline
void
175
FlexDim::update
(
Space
& home,
bool
share,
FlexDim
&
d
) {
176
c0
.
update
(home,share,d.
c0
);
177
s
.
update
(home,share,d.
s
);
178
c1
.
update
(home,share,d.
c1
);
179
}
180
181
forceinline
void
182
FlexDim::subscribe
(
Space
& home,
Propagator
&
p
) {
183
c0
.
subscribe
(home,p,
PC_INT_DOM
);
184
s
.
subscribe
(home,p,
PC_INT_BND
);
185
c1
.
subscribe
(home,p,
PC_INT_DOM
);
186
}
187
forceinline
void
188
FlexDim::cancel
(
Space
& home,
Propagator
&
p
) {
189
c0
.
cancel
(home,p,
PC_INT_DOM
);
190
s
.
cancel
(home,p,
PC_INT_BND
);
191
c1
.
cancel
(home,p,
PC_INT_DOM
);
192
}
193
194
}}}
195
196
// STATISTICS: int-prop
197