main page
modules
namespaces
classes
files
Gecode home
Generated on Sat May 25 2013 18:00:39 for Gecode by
doxygen
1.8.3.1
gecode
kernel
brancher-view-val.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, 2012
8
*
9
* Last modified:
10
* $Date: 2013-03-07 02:18:29 +0100 (Thu, 07 Mar 2013) $ by $Author: mears $
11
* $Revision: 13455 $
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 {
39
48
49
template
<
class
Val>
50
class
GECODE_VTABLE_EXPORT
PosValChoice
:
public
PosChoice
{
51
private
:
53
const
Val _val;
54
public
:
56
PosValChoice
(
const
Brancher
&
b
,
unsigned
int
a
,
const
Pos
&
p
,
const
Val&
n
);
58
const
Val& val(
void
)
const
;
60
virtual
size_t
size
(
void
)
const
;
62
virtual
void
archive(
Archive
& e)
const
;
63
};
64
72
template
<
class
View,
int
n,
class
Val,
unsigned
int
a>
73
class
ViewValBrancher
:
public
ViewBrancher
<View,n> {
74
typedef
typename
ViewBrancher<View,n>::BranchFilter
BranchFilter;
75
protected
:
76
using
ViewBrancher<View,n>::vs
;
77
using
ViewBrancher<View,n>::x
;
79
ValSelCommitBase<View,Val>
*
vsc
;
81
ViewValBrancher
(
Space
& home,
bool
share,
ViewValBrancher
&
b
);
83
ViewValBrancher
(
Home
home,
84
ViewArray<View>
&
x
,
85
ViewSel<View>
*
vs
[
n
],
86
ValSelCommitBase<View,Val>
*
vsc
,
87
BranchFilter
bf
);
88
public
:
90
virtual
const
Choice
*
choice
(
Space
& home);
92
virtual
const
Choice
*
choice
(
const
Space
& home,
Archive
& e);
94
virtual
ExecStatus
commit
(
Space
& home,
const
Choice
&
c
,
unsigned
int
b
);
96
virtual
Actor
*
copy
(
Space
& home,
bool
share);
98
virtual
size_t
dispose
(
Space
& home);
100
static
BrancherHandle
post
(
Home
home,
101
ViewArray<View>
&
x
,
102
ViewSel<View>
*
vs
[
n
],
103
ValSelCommitBase<View,Val>
*
vsc
,
104
BranchFilter
bf
);
105
};
107
108
/*
109
* %Choice with position and value
110
*
111
*/
112
template
<
class
Val>
113
forceinline
114
PosValChoice<Val>::PosValChoice
(
const
Brancher
&
b
,
unsigned
int
a
,
115
const
Pos
&
p
,
const
Val&
n
)
116
:
PosChoice
(b,a,p), _val(n) {}
117
118
template
<
class
Val>
119
forceinline
const
Val&
120
PosValChoice<Val>::val
(
void
)
const
{
121
return
_val;
122
}
123
124
template
<
class
Val>
125
forceinline
size_t
126
PosValChoice<Val>::size
(
void
)
const
{
127
return
sizeof
(
PosValChoice<Val>
);
128
}
129
130
template
<
class
Val>
131
forceinline
void
132
PosValChoice<Val>::archive
(
Archive
& e)
const
{
133
PosChoice::archive
(e);
134
e << _val;
135
}
136
137
/*
138
* Generic brancher based on variable/value selection
139
*
140
*/
141
142
143
144
template
<
class
View,
int
n,
class
Val,
unsigned
int
a>
145
forceinline
146
ViewValBrancher<View,n,Val,a>::
147
ViewValBrancher
(
Home
home,
148
ViewArray<View>
&
x
,
149
ViewSel<View>
* vs[
n
],
150
ValSelCommitBase<View,Val>
* vsc0,
151
BranchFilter bf)
152
:
ViewBrancher
<View,n>(home,x,vs,bf), vsc(vsc0) {
153
if
(
vsc
->
notice
()) {
154
for
(
int
i
=0;
i
<
n
;
i
++)
155
if
(
vs
[
i
]->notice())
156
goto
not_needed;
157
home.
notice
(*
this
,
AP_DISPOSE
);
158
not_needed: ;
159
}
160
}
161
162
template
<
class
View,
int
n,
class
Val,
unsigned
int
a>
163
forceinline
BrancherHandle
164
ViewValBrancher<View,n,Val,a>::
165
post
(
Home
home,
ViewArray<View>
&
x
,
166
ViewSel<View>
* vs[
n
],
ValSelCommitBase<View,Val>
* vsc,
167
BranchFilter bf) {
168
return
*
new
(home)
ViewValBrancher<View,n,Val,a>
(home,x,vs,vsc,bf);
169
}
170
171
template
<
class
View,
int
n,
class
Val,
unsigned
int
a>
172
forceinline
173
ViewValBrancher<View,n,Val,a>::
174
ViewValBrancher
(
Space
& home,
bool
shared
,
ViewValBrancher<View,n,Val,a>
&
b
)
175
:
ViewBrancher
<View,
n
>(home,shared,b),
176
vsc(b.vsc->copy(home,shared)) {}
177
178
template
<
class
View,
int
n,
class
Val,
unsigned
int
a>
179
Actor
*
180
ViewValBrancher<View,n,Val,a>::copy
(
Space
& home,
bool
shared
) {
181
return
new
(home)
ViewValBrancher<View,n,Val,a>
(home,shared,*
this
);
182
}
183
184
template
<
class
View,
int
n,
class
Val,
unsigned
int
a>
185
const
Choice
*
186
ViewValBrancher<View,n,Val,a>::choice
(
Space
& home) {
187
Pos
p
=
ViewBrancher<View,n>::pos
(home);
188
View
v
=
ViewBrancher<View,n>::view
(p);
189
return
new
PosValChoice<Val>
(*
this
,
a
,
p
,vsc->val(home,v,p.
pos
));
190
}
191
192
template
<
class
View,
int
n,
class
Val,
unsigned
int
a>
193
const
Choice
*
194
ViewValBrancher<View,n,Val,a>::choice
(
const
Space
& home,
Archive
& e) {
195
(void) home;
196
int
p
; e >>
p
;
197
Val
v
; e >>
v
;
198
return
new
PosValChoice<Val>
(*
this
,
a
,
p
,
v
);
199
}
200
201
template
<
class
View,
int
n,
class
Val,
unsigned
int
a>
202
ExecStatus
203
ViewValBrancher<View,n,Val,a>
204
::commit
(
Space
& home,
const
Choice
&
c
,
unsigned
int
b
) {
205
const
PosValChoice<Val>
& pvc
206
=
static_cast<
const
PosValChoice<Val>
&
>
(
c
);
207
return
me_failed
(vsc->commit(home,b,
208
ViewBrancher<View,n>::view
(pvc.
pos
()),
209
pvc.
pos
().
pos
,
210
pvc.
val
()))
211
?
ES_FAILED
:
ES_OK
;
212
}
213
214
template
<
class
View,
int
n,
class
Val,
unsigned
int
a>
215
forceinline
size_t
216
ViewValBrancher<View,n,Val,a>::dispose
(
Space
& home) {
217
if
(vsc->notice()) {
218
for
(
int
i
=0;
i
<
n
;
i
++)
219
if
(vs[
i
]->notice())
220
goto
not_needed;
221
home.
ignore
(*
this
,
AP_DISPOSE
);
222
not_needed: ;
223
}
224
vsc->dispose(home);
225
(void)
ViewBrancher<View,n>::dispose
(home);
226
return
sizeof
(
ViewValBrancher<View,n,Val,a>
);
227
}
228
229
}
230
231
// STATISTICS: kernel-branch