main page
modules
namespaces
classes
files
Gecode home
Generated on Sat May 25 2013 18:00:36 for Gecode by
doxygen
1.8.3.1
gecode
int
count
int-lq.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, 2006
8
*
9
* Last modified:
10
* $Date: 2011-08-29 14:59:24 +0200 (Mon, 29 Aug 2011) $ by $Author: schulte $
11
* $Revision: 12359 $
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
Count {
39
40
template
<
class
VX,
class
VY>
41
forceinline
42
LqInt<VX,VY>::LqInt
(
Home
home,
ViewArray<VX>
&
x
,
int
n_s, VY y,
int
c
)
43
:
IntBase
<VX,VY>(home,x,n_s,y,c) {}
44
45
template
<
class
VX,
class
VY>
46
ExecStatus
47
LqInt<VX,VY>::post
(
Home
home,
ViewArray<VX>
&
x
, VY y,
int
c
) {
48
// Eliminate decided views
49
int
n_x = x.
size
();
50
for
(
int
i
=n_x;
i
--; )
51
switch
(
holds
(x[
i
],y)) {
52
case
RT_FALSE
:
53
x[
i
] = x[--n_x];
break
;
54
case
RT_TRUE
:
55
x[
i
] = x[--n_x]; c--;
break
;
56
case
RT_MAYBE
:
57
break
;
58
default
:
59
GECODE_NEVER
;
60
}
61
x.
size
(n_x);
62
if
(c < 0)
63
return
ES_FAILED
;
64
if
(c >= n_x)
65
return
ES_OK
;
66
// All views must be different
67
if
(c == 0)
68
return
post_false
(home,x,y);
69
(void)
new
(home)
LqInt<VX,VY>
(home,
x
,n_x-c+1,y,
c
);
70
return
ES_OK
;
71
}
72
73
template
<
class
VX,
class
VY>
74
forceinline
75
LqInt<VX,VY>::LqInt
(
Space
& home,
bool
share,
LqInt<VX,VY>
&
p
)
76
:
IntBase
<VX,VY>(home,share,p) {}
77
78
template
<
class
VX,
class
VY>
79
Actor
*
80
LqInt<VX,VY>::copy
(
Space
& home,
bool
share) {
81
return
new
(home)
LqInt<VX,VY>
(home,share,*
this
);
82
}
83
84
template
<
class
VX,
class
VY>
85
ExecStatus
86
LqInt<VX,VY>::propagate
(
Space
& home,
const
ModEventDelta
&) {
87
// Eliminate decided views from subscribed views
88
int
n_x =
x
.size();
89
for
(
int
i
=n_s;
i
--; )
90
switch
(
holds
(
x
[
i
],y)) {
91
case
RT_FALSE
:
92
x
[
i
].cancel(home,*
this
,
PC_INT_DOM
);
93
x
[
i
]=
x
[--n_s];
x
[n_s]=
x
[--n_x];
94
break
;
95
case
RT_TRUE
:
96
x
[
i
].cancel(home,*
this
,
PC_INT_DOM
);
97
x
[
i
]=
x
[--n_s];
x
[n_s]=
x
[--n_x];
c
--;
98
break
;
99
case
RT_MAYBE
:
100
break
;
101
default
:
102
GECODE_NEVER
;
103
}
104
x
.size(n_x);
105
if
(
c
< 0)
106
return
ES_FAILED
;
107
if
(
c
>= n_x)
108
return
home.
ES_SUBSUMED
(*
this
);
109
// Eliminate decided views from unsubscribed views
110
for
(
int
i=n_x; i-- > n_s; )
111
switch
(
holds
(
x
[i],y)) {
112
case
RT_FALSE
:
x
[
i
]=
x
[--n_x];
break
;
113
case
RT_TRUE
:
x
[
i
]=
x
[--n_x];
c
--;
break
;
114
case
RT_MAYBE
:
break
;
115
default
:
GECODE_NEVER
;
116
}
117
x
.size(n_x);
118
if
(
c
< 0)
119
return
ES_FAILED
;
120
if
(
c
>= n_x)
121
return
home.
ES_SUBSUMED
(*
this
);
122
if
(
c
== 0) {
123
// All views must be different
124
GECODE_ES_CHECK
(
post_false
(home,
x
,y));
125
return
home.
ES_SUBSUMED
(*
this
);
126
}
127
// Now, there must be new subscriptions from x[n_s] up to x[n_x-c+1]
128
int
m = n_x-
c
;
129
while
(n_s <= m)
130
x
[n_s++].subscribe(home,*
this
,
PC_INT_DOM
,
false
);
131
return
ES_FIX
;
132
}
133
134
}}}
135
136
// STATISTICS: int-prop