main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:25 for Gecode by
doxygen
1.8.4
gecode
set
branch
merit.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
* Contributing authors:
7
* Gabor Szokoli <szokoli@gecode.org>
8
* Guido Tack <tack@gecode.org>
9
*
10
* Copyright:
11
* Christian Schulte, 2012
12
* Gabor Szokoli, 2004
13
* Guido Tack, 2004
14
*
15
* Last modified:
16
* $Date: 2013-07-01 09:17:01 +0200 (Mon, 01 Jul 2013) $ by $Author: tack $
17
* $Revision: 13742 $
18
*
19
* This file is part of Gecode, the generic constraint
20
* development environment:
21
* http://www.gecode.org
22
*
23
* Permission is hereby granted, free of charge, to any person obtaining
24
* a copy of this software and associated documentation files (the
25
* "Software"), to deal in the Software without restriction, including
26
* without limitation the rights to use, copy, modify, merge, publish,
27
* distribute, sublicense, and/or sell copies of the Software, and to
28
* permit persons to whom the Software is furnished to do so, subject to
29
* the following conditions:
30
*
31
* The above copyright notice and this permission notice shall be
32
* included in all copies or substantial portions of the Software.
33
*
34
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
*
42
*/
43
44
namespace
Gecode {
namespace
Set {
namespace
Branch {
45
46
// Minimum merit
47
forceinline
48
MeritMin::MeritMin
(
Space
& home,
const
VarBranch
& vb)
49
:
MeritBase
<
SetView
,int>(home,vb) {}
50
forceinline
51
MeritMin::MeritMin
(
Space
& home,
bool
shared
,
MeritMin
& m)
52
:
MeritBase
<
SetView
,int>(home,shared,m) {}
53
forceinline
int
54
MeritMin::operator ()
(
const
Space
&,
SetView
x
,
int
) {
55
UnknownRanges<SetView>
u
(x);
56
return
u.
min
();
57
}
58
59
// Maximum merit
60
forceinline
61
MeritMax::MeritMax
(
Space
& home,
const
VarBranch
& vb)
62
:
MeritBase
<
SetView
,int>(home,vb) {}
63
forceinline
64
MeritMax::MeritMax
(
Space
& home,
bool
shared
,
MeritMax
& m)
65
:
MeritBase
<
SetView
,int>(home,shared,m) {}
66
forceinline
int
67
MeritMax::operator ()
(
const
Space
&,
SetView
x
,
int
) {
68
int
max
=
Limits::max
;
69
for
(
UnknownRanges<SetView>
u
(x);
u
(); ++
u
)
70
max =
u
.max();
71
return
max
;
72
}
73
74
// Size merit
75
forceinline
76
MeritSize::MeritSize
(
Space
& home,
const
VarBranch
& vb)
77
:
MeritBase
<
SetView
,unsigned int>(home,vb) {}
78
forceinline
79
MeritSize::MeritSize
(
Space
& home,
bool
shared
,
MeritSize
& m)
80
:
MeritBase
<
SetView
,unsigned int>(home,shared,m) {}
81
forceinline
unsigned
int
82
MeritSize::operator ()
(
const
Space
&,
SetView
x
,
int
) {
83
return
x.
unknownSize
();
84
}
85
86
// Size over degree merit
87
forceinline
88
MeritDegreeSize::MeritDegreeSize
(
Space
& home,
const
VarBranch
& vb)
89
:
MeritBase
<
SetView
,double>(home,vb) {}
90
forceinline
91
MeritDegreeSize::MeritDegreeSize
(
Space
& home,
bool
shared
,
92
MeritDegreeSize
& m)
93
:
MeritBase
<
SetView
,double>(home,shared,m) {}
94
forceinline
double
95
MeritDegreeSize::operator ()
(
const
Space
&,
SetView
x
,
int
) {
96
return
static_cast<
double
>
(x.
unknownSize
()) /
97
static_cast<double>(x.
degree
());
98
}
99
100
// Size over AFC merit
101
forceinline
102
MeritAFCSize::MeritAFCSize
(
Space
& home,
const
VarBranch
& vb)
103
:
MeritBase
<
SetView
,double>(home,vb),
afc
(vb.
afc
()) {}
104
forceinline
105
MeritAFCSize::MeritAFCSize
(
Space
& home,
bool
shared
,
MeritAFCSize
& m)
106
:
MeritBase
<
SetView
,double>(home,shared,m) {
107
afc
.
update
(home,shared,m.
afc
);
108
}
109
forceinline
double
110
MeritAFCSize::operator ()
(
const
Space
& home,
SetView
x
,
int
) {
111
return
static_cast<
double
>
(x.
unknownSize
()) / x.
afc
(home);
112
}
113
forceinline
bool
114
MeritAFCSize::notice
(
void
)
const
{
115
return
true
;
116
}
117
forceinline
void
118
MeritAFCSize::dispose
(
Space
&) {
119
afc
.
~AFC
();
120
}
121
122
// Size over activity merit
123
forceinline
124
MeritActivitySize::MeritActivitySize
(
Space
& home,
125
const
VarBranch
& vb)
126
:
MeritBase
<
SetView
,double>(home,vb), activity(vb.activity()) {}
127
forceinline
128
MeritActivitySize::MeritActivitySize
(
Space
& home,
bool
shared
,
129
MeritActivitySize
& m)
130
:
MeritBase
<
SetView
,double>(home,shared,m) {
131
activity
.
update
(home, shared, m.
activity
);
132
}
133
forceinline
double
134
MeritActivitySize::operator ()
(
const
Space
&,
SetView
x
,
int
i
) {
135
return
activity
[
i
] /
static_cast<
double
>
(x.
unknownSize
());
136
}
137
forceinline
bool
138
MeritActivitySize::notice
(
void
)
const
{
139
return
true
;
140
}
141
forceinline
void
142
MeritActivitySize::dispose
(
Space
&) {
143
activity
.
~Activity
();
144
}
145
146
}}}
147
148
// STATISTICS: set-branch