main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Oct 22 2013 00:49:00 for Gecode by
doxygen
1.8.4
gecode
int
branch
val-sel-commit.cpp
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-05 20:51:24 +0100 (Tue, 05 Mar 2013) $ by $Author: schulte $
11
* $Revision: 13438 $
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/branch.hh
>
39
40
namespace
Gecode {
namespace
Int {
namespace
Branch {
41
42
ValSelCommitBase<IntView,int>*
43
valselcommitint
(
Space
& home,
int
n
,
const
IntValBranch
& ivb) {
44
assert((ivb.
select
() !=
IntValBranch::SEL_VALUES_MIN
) &&
45
(ivb.
select
() !=
IntValBranch::SEL_VALUES_MAX
));
46
switch
(ivb.
select
()) {
47
case
IntValBranch::SEL_MIN
:
48
return
new
(home)
49
ValSelCommit
<
ValSelMin<IntView>
,
ValCommitEq<IntView>
>(home,ivb);
50
case
IntValBranch::SEL_MED
:
51
return
new
(home)
52
ValSelCommit
<
ValSelMed<IntView>
,
ValCommitEq<IntView>
>(home,ivb);
53
case
IntValBranch::SEL_MAX
:
54
return
new
(home)
55
ValSelCommit
<
ValSelMax<IntView>
,
ValCommitEq<IntView>
>(home,ivb);
56
case
IntValBranch::SEL_RND
:
57
return
new
(home)
58
ValSelCommit
<
ValSelRnd<IntView>
,
ValCommitEq<IntView>
>(home,ivb);
59
case
IntValBranch::SEL_SPLIT_MIN
:
60
return
new
(home)
61
ValSelCommit
<
ValSelAvg<IntView>
,
ValCommitLq<IntView>
>(home,ivb);
62
case
IntValBranch::SEL_SPLIT_MAX
:
63
return
new
(home)
64
ValSelCommit
<
ValSelAvg<IntView>
,
ValCommitGr<IntView>
>(home,ivb);
65
case
IntValBranch::SEL_RANGE_MIN
:
66
return
new
(home)
67
ValSelCommit
<
ValSelRangeMin
,
ValCommitLq<IntView>
>(home,ivb);
68
case
IntValBranch::SEL_RANGE_MAX
:
69
return
new
(home)
70
ValSelCommit
<
ValSelRangeMax
,
ValCommitGq<IntView>
>(home,ivb);
71
case
IntValBranch::SEL_VAL_COMMIT
:
72
if
(ivb.
commit
() == NULL) {
73
return
new
(home)
74
ValSelCommit
<
ValSelFunction<IntView>
,
ValCommitEq<IntView>
>(home,ivb);
75
}
else
{
76
return
new
(home)
77
ValSelCommit
<
ValSelFunction<IntView>
,
ValCommitFunction<IntView>
>(home,ivb);
78
}
79
case
IntValBranch::SEL_NEAR_MIN
:
80
case
IntValBranch::SEL_NEAR_MAX
:
81
case
IntValBranch::SEL_NEAR_INC
:
82
case
IntValBranch::SEL_NEAR_DEC
:
83
{
84
IntSharedArray
v
(ivb.
values
());
85
if
(n !=
v
.size())
86
throw
ArgumentSizeMismatch
(
"Int::branch"
);
87
for
(
int
i
=n;
i
--; )
88
Limits::check
(
v
[
i
],
"Int::branch"
);
89
switch
(ivb.
select
()) {
90
case
IntValBranch::SEL_NEAR_MIN
:
91
return
new
(home)
92
ValSelCommit
<
ValSelNearMinMax<IntView,true>
,
93
ValCommitEq<IntView>
>(home,ivb);
94
case
IntValBranch::SEL_NEAR_MAX
:
95
return
new
(home)
96
ValSelCommit
<
ValSelNearMinMax<IntView,false>
,
97
ValCommitEq<IntView>
>(home,ivb);
98
case
IntValBranch::SEL_NEAR_INC
:
99
return
new
(home)
100
ValSelCommit
<
ValSelNearIncDec<IntView,true>
,
101
ValCommitEq<IntView>
>(home,ivb);
102
case
IntValBranch::SEL_NEAR_DEC
:
103
return
new
(home)
104
ValSelCommit
<
ValSelNearIncDec<IntView,false>
,
105
ValCommitEq<IntView>
>(home,ivb);
106
default
:
GECODE_NEVER
;
107
}
108
}
109
default
:
110
throw
UnknownBranching
(
"Int::branch"
);
111
}
112
}
113
114
ValSelCommitBase<IntView,int>
*
115
valselcommitint
(
Space
& home,
const
IntAssign
& ia) {
116
switch
(ia.
select
()) {
117
case
IntAssign::SEL_MIN
:
118
return
new
(home)
119
ValSelCommit
<
ValSelMin<IntView>
,
ValCommitEq<IntView>
>(home,ia);
120
case
IntAssign::SEL_MED
:
121
return
new
(home)
122
ValSelCommit
<
ValSelMed<IntView>
,
ValCommitEq<IntView>
>(home,ia);
123
case
IntAssign::SEL_MAX
:
124
return
new
(home)
125
ValSelCommit
<
ValSelMax<IntView>
,
ValCommitEq<IntView>
>(home,ia);
126
case
IntAssign::SEL_RND
:
127
return
new
(home)
128
ValSelCommit
<
ValSelRnd<IntView>
,
ValCommitEq<IntView>
>(home,ia);
129
case
IntAssign::SEL_VAL_COMMIT
:
130
if
(ia.
commit
() == NULL) {
131
return
new
(home)
132
ValSelCommit
<
ValSelFunction<IntView>
,
ValCommitEq<IntView>
>(home,ia);
133
}
else
{
134
return
new
(home)
135
ValSelCommit
<
ValSelFunction<IntView>
,
ValCommitFunction<IntView>
>(home,ia);
136
}
137
default
:
138
throw
UnknownBranching
(
"Int::assign"
);
139
}
140
}
141
142
ValSelCommitBase<BoolView,int>
*
143
valselcommitbool
(
Space
& home,
int
n
,
const
IntValBranch
& ivb) {
144
switch
(ivb.
select
()) {
145
case
IntValBranch::SEL_MIN
:
146
case
IntValBranch::SEL_MED
:
147
case
IntValBranch::SEL_SPLIT_MIN
:
148
case
IntValBranch::SEL_RANGE_MIN
:
149
case
IntValBranch::SEL_VALUES_MIN
:
150
return
new
(home)
151
ValSelCommit
<
ValSelMin<BoolView>
,
ValCommitEq<BoolView>
>(home,ivb);
152
case
IntValBranch::SEL_MAX
:
153
case
IntValBranch::SEL_SPLIT_MAX
:
154
case
IntValBranch::SEL_RANGE_MAX
:
155
case
IntValBranch::SEL_VALUES_MAX
:
156
return
new
(home)
157
ValSelCommit
<
ValSelMax<BoolView>
,
ValCommitEq<BoolView>
>(home,ivb);
158
case
IntValBranch::SEL_RND
:
159
return
new
(home)
160
ValSelCommit
<
ValSelRnd<BoolView>
,
ValCommitEq<BoolView>
>(home,ivb);
161
case
IntValBranch::SEL_VAL_COMMIT
:
162
if
(ivb.
commit
() == NULL) {
163
return
new
(home)
164
ValSelCommit
<
ValSelFunction<BoolView>
,
ValCommitEq<BoolView>
>(home,ivb);
165
}
else
{
166
return
new
(home)
167
ValSelCommit
<
ValSelFunction<BoolView>
,
ValCommitFunction<BoolView>
>(home,ivb);
168
}
169
case
IntValBranch::SEL_NEAR_MIN
:
170
case
IntValBranch::SEL_NEAR_MAX
:
171
case
IntValBranch::SEL_NEAR_INC
:
172
case
IntValBranch::SEL_NEAR_DEC
:
173
{
174
IntSharedArray
v
(ivb.
values
());
175
if
(n !=
v
.size())
176
throw
ArgumentSizeMismatch
(
"Int::branch"
);
177
for
(
int
i
=n;
i
--; )
178
if
((
v
[
i
] < 0) || (
v
[
i
] > 1))
179
throw
OutOfLimits
(
"Int::branch"
);
180
switch
(ivb.
select
()) {
181
case
IntValBranch::SEL_NEAR_MIN
:
182
return
new
(home)
183
ValSelCommit
<
ValSelNearMinMax<BoolView,true>
,
184
ValCommitEq<BoolView>
>(home,ivb);
185
case
IntValBranch::SEL_NEAR_MAX
:
186
return
new
(home)
187
ValSelCommit
<
ValSelNearMinMax<BoolView,false>
,
188
ValCommitEq<BoolView>
>(home,ivb);
189
case
IntValBranch::SEL_NEAR_INC
:
190
return
new
(home)
191
ValSelCommit
<
ValSelNearIncDec<BoolView,true>
,
192
ValCommitEq<BoolView>
>(home,ivb);
193
case
IntValBranch::SEL_NEAR_DEC
:
194
return
new
(home)
195
ValSelCommit
<
ValSelNearIncDec<BoolView,false>
,
196
ValCommitEq<BoolView>
>(home,ivb);
197
default
:
GECODE_NEVER
;
198
}
199
}
200
default
:
201
throw
UnknownBranching
(
"Int::branch"
);
202
}
203
}
204
205
ValSelCommitBase<BoolView,int>
*
206
valselcommitbool
(
Space
& home,
const
IntAssign
& ia) {
207
switch
(ia.
select
()) {
208
case
IntAssign::SEL_MIN
:
209
return
new
(home)
210
ValSelCommit
<
ValSelMin<BoolView>
,
ValCommitEq<BoolView>
>(home,ia);
211
case
IntAssign::SEL_MED
:
212
return
new
(home)
213
ValSelCommit
<
ValSelMed<BoolView>
,
ValCommitEq<BoolView>
>(home,ia);
214
case
IntAssign::SEL_MAX
:
215
return
new
(home)
216
ValSelCommit
<
ValSelMax<BoolView>
,
ValCommitEq<BoolView>
>(home,ia);
217
case
IntAssign::SEL_RND
:
218
return
new
(home)
219
ValSelCommit
<
ValSelRnd<BoolView>
,
ValCommitEq<BoolView>
>(home,ia);
220
case
IntAssign::SEL_VAL_COMMIT
:
221
if
(ia.
commit
() == NULL) {
222
return
new
(home)
223
ValSelCommit
<
ValSelFunction<BoolView>
,
ValCommitEq<BoolView>
>(home,ia);
224
}
else
{
225
return
new
(home)
226
ValSelCommit
<
ValSelFunction<BoolView>
,
ValCommitFunction<BoolView>
>(home,ia);
227
}
228
default
:
229
throw
UnknownBranching
(
"Bool::assign"
);
230
}
231
}
232
233
}}}
234
235
236
// STATISTICS: int-branch
237