main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Mar 13 2014 04:39:30 for Gecode by
doxygen
1.8.1.2
gecode
int
dom
range.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, 2004
8
*
9
* Last modified:
10
* $Date: 2012-02-22 16:04:20 +1100 (Wed, 22 Feb 2012) $ by $Author: tack $
11
* $Revision: 12537 $
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/rel.hh
>
39
40
namespace
Gecode {
namespace
Int {
namespace
Dom {
41
42
template
<
class
View>
43
forceinline
44
ReRange<View>::ReRange
(
Home
home, View x,
int
min0,
int
max0,
BoolView
b
)
45
:
ReUnaryPropagator
<View,
PC_INT_BND
,
BoolView
>(home,x,b),
46
min
(min0),
max
(max0) {}
47
48
template
<
class
View>
49
ExecStatus
50
ReRange<View>::post
(
Home
home, View x,
int
min
,
int
max
,
BoolView
b
) {
51
if
(min == max) {
52
return
Rel::ReEqDomInt<View,BoolView>::post
(home,x,min,b);
53
}
else
if
((min > max) || (max < x.min()) || (min > x.max())) {
54
GECODE_ME_CHECK
(b.
zero
(home));
55
}
else
if
((min <= x.min()) && (x.max() <=
max
)) {
56
GECODE_ME_CHECK
(b.
one
(home));
57
}
else
if
(b.
one
()) {
58
GECODE_ME_CHECK
(x.gq(home,min));
59
GECODE_ME_CHECK
(x.lq(home,max));
60
}
else
if
(b.
zero
()) {
61
Iter::Ranges::Singleton
r
(min,max);
62
GECODE_ME_CHECK
(x.minus_r(home,r,
false
));
63
}
else
{
64
(void)
new
(home)
ReRange<View>
(home,x,
min
,
max
,
b
);
65
}
66
return
ES_OK
;
67
}
68
69
70
template
<
class
View>
71
forceinline
72
ReRange<View>::ReRange
(
Space
& home,
bool
share,
ReRange
& p)
73
:
ReUnaryPropagator
<View,
PC_INT_BND
,
BoolView
>(home,share,p),
74
min
(p.
min
),
max
(p.
max
) {}
75
76
template
<
class
View>
77
Actor
*
78
ReRange<View>::copy
(
Space
& home,
bool
share) {
79
return
new
(home)
ReRange<View>
(home,share,*
this
);
80
}
81
82
template
<
class
View>
83
ExecStatus
84
ReRange<View>::propagate
(
Space
& home,
const
ModEventDelta
&) {
85
if
(
b
.one()) {
86
GECODE_ME_CHECK
(x0.gq(home,
min
));
87
GECODE_ME_CHECK
(x0.lq(home,
max
));
88
}
else
if
(
b
.zero()) {
89
Iter::Ranges::Singleton
r
(
min
,
max
);
90
GECODE_ME_CHECK
(x0.minus_r(home,r,
false
));
91
}
else
if
((x0.max() <=
max
) && (x0.min() >=
min
)) {
92
GECODE_ME_CHECK
(
b
.one_none(home));
93
}
else
if
((x0.max() <
min
) || (x0.min() >
max
)) {
94
GECODE_ME_CHECK
(
b
.zero_none(home));
95
}
else
{
96
return
ES_FIX
;
97
}
98
return
home.
ES_SUBSUMED
(*
this
);
99
}
100
101
102
}}}
103
104
// STATISTICS: int-prop
105