main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:27 for Gecode by
doxygen
1.8.4
gecode
int
branch
view-values.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: 2012-09-18 18:07:37 +0200 (Tue, 18 Sep 2012) $ by $Author: schulte $
11
* $Revision: 13101 $
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
PosValuesChoice::PosValuesChoice
(
const
Brancher
&
b
,
const
Pos
&
p
,
IntView
x
)
43
:
PosChoice
(b,x.
size
(),p),
n
(0) {
44
for
(
ViewRanges<IntView>
r
(x);
r
(); ++
r
)
45
n++;
46
pm =
heap
.
alloc
<PosMin>(n+1);
47
unsigned
int
w=0;
48
int
i
=0;
49
for
(
ViewRanges<IntView>
r
(x);
r
(); ++
r
) {
50
pm[
i
].min =
r
.min();
51
pm[
i
].pos = w;
52
w +=
r
.width(); i++;
53
}
54
pm[
i
].pos = w;
55
}
56
57
PosValuesChoice::PosValuesChoice
(
const
Brancher
&
b
,
unsigned
int
a
,
Pos
p
,
58
Archive
& e)
59
:
PosChoice
(b,a,p) {
60
e >> n;
61
pm =
heap
.
alloc
<PosMin>(n+1);
62
for
(
unsigned
int
i
=0;
i
<n+1;
i
++) {
63
e >> pm[
i
].pos;
64
e >> pm[
i
].min;
65
}
66
}
67
68
size_t
69
PosValuesChoice::size
(
void
)
const
{
70
return
sizeof
(
PosValuesChoice
)+(n+1)*
sizeof
(PosMin);
71
}
72
73
PosValuesChoice::~PosValuesChoice
(
void
) {
74
heap
.
free
<PosMin>(pm,n+1);
75
}
76
77
forceinline
void
78
PosValuesChoice::archive
(
Archive
& e)
const
{
79
PosChoice::archive
(e);
80
e << this->
alternatives
() << n;
81
for
(
unsigned
int
i
=0;
i
<n+1;
i
++) {
82
e << pm[
i
].pos;
83
e << pm[
i
].min;
84
}
85
}
86
87
}}}
88
89
// STATISTICS: int-branch