main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 9 2020 05:34:08 for Gecode by
doxygen
1.8.18
gecode
kernel
gpi.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, 2009
8
*
9
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
#include <cmath>
35
36
namespace
Gecode
{
namespace
Kernel {
37
39
class
GPI
{
40
public
:
42
class
Info
{
43
public
:
45
unsigned
int
pid
;
47
unsigned
int
gid
;
49
double
afc
;
51
void
init
(
unsigned
int
pid
,
unsigned
int
gid
);
52
};
53
private
:
55
class
Block :
public
HeapAllocated
{
56
public
:
58
static
const
int
n_info = 8192;
60
Info
info[n_info];
62
Block* next;
64
int
free;
66
Block(
void
);
68
void
rescale
(
void
);
69
};
71
Block* b;
73
double
invd;
75
unsigned
int
npid;
77
bool
us;
79
Block fst;
81
GECODE_KERNEL_EXPORT
static
Support::Mutex
m;
82
public
:
84
GPI
(
void
);
86
void
decay
(
double
d
);
88
double
decay
(
void
)
const
;
90
void
fail
(Info&
c
);
92
Info*
allocate
(
unsigned
int
p
,
unsigned
int
gid);
94
Info*
allocate
(
unsigned
int
gid);
96
unsigned
int
pid
(
void
)
const
;
98
bool
unshare
(
void
);
100
~GPI
(
void
);
101
};
102
103
104
forceinline
void
105
GPI::Info::init
(
unsigned
int
pid0,
unsigned
int
gid0) {
106
pid
=pid0;
gid
=gid0;
afc
=1.0;
107
}
108
109
110
forceinline
111
GPI::Block::Block(
void
)
112
: next(NULL), free(n_info) {}
113
114
forceinline
void
115
GPI::Block::rescale
(
void
) {
116
for
(
int
i
=free;
i
< n_info;
i
++)
117
info[
i
].
afc
*=
Kernel::Config::rescale
;
118
}
119
120
121
forceinline
122
GPI::GPI
(
void
)
123
: b(&fst), invd(1.0), npid(0U), us(false) {}
124
125
forceinline
void
126
GPI::fail
(
Info
&
c
) {
127
m.
acquire
();
128
c
.afc = invd * (
c
.afc + 1.0);
129
if
(
c
.afc >
Kernel::Config::rescale_limit
)
130
for
(Block*
i
= b;
i
!= NULL;
i
=
i
->next)
131
i
->rescale();
132
m.
release
();
133
}
134
135
forceinline
double
136
GPI::decay
(
void
)
const
{
137
double
d
;
138
const_cast<
GPI
&
>
(*this).m.
acquire
();
139
d
= 1.0 / invd;
140
const_cast<
GPI
&
>
(*this).m.
release
();
141
return
d
;
142
}
143
144
forceinline
unsigned
int
145
GPI::pid
(
void
)
const
{
146
unsigned
int
p
;
147
const_cast<
GPI
&
>
(*this).m.
acquire
();
148
p
= npid;
149
const_cast<
GPI
&
>
(*this).m.
release
();
150
return
p
;
151
}
152
153
forceinline
bool
154
GPI::unshare
(
void
) {
155
bool
u
;
156
m.
acquire
();
157
u
= us; us =
true
;
158
m.
release
();
159
return
u
;
160
}
161
162
forceinline
void
163
GPI::decay
(
double
d
) {
164
m.
acquire
();
165
invd = 1.0 /
d
;
166
m.
release
();
167
}
168
169
forceinline
GPI::Info
*
170
GPI::allocate
(
unsigned
int
p
,
unsigned
int
gid) {
171
Info
*
c
;
172
m.
acquire
();
173
if
(b->free == 0) {
174
Block*
n
=
new
Block;
175
n
->next = b; b =
n
;
176
}
177
c
= &b->info[--b->free];
178
m.
release
();
179
c
->init(
p
,gid);
180
return
c
;
181
}
182
183
forceinline
GPI::Info
*
184
GPI::allocate
(
unsigned
int
gid) {
185
Info
*
c
;
186
m.
acquire
();
187
if
(b->free == 0) {
188
Block*
n
=
new
Block;
189
n
->next = b; b =
n
;
190
}
191
c
= &b->info[--b->free];
192
c
->init(npid++,gid);
193
m.
release
();
194
return
c
;
195
}
196
197
forceinline
198
GPI::~GPI
(
void
) {
199
Block*
n
= b;
200
while
(
n
!= &fst) {
201
Block*
d
=
n
;
202
n
=
n
->next;
203
delete
d
;
204
}
205
}
206
207
}}
208
209
// STATISTICS: kernel-prop
Gecode::Kernel::GPI::allocate
Info * allocate(unsigned int p, unsigned int gid)
Allocate info for existing propagator with pid p.
Definition:
gpi.hpp:170
Gecode::Support::Mutex::acquire
void acquire(void)
Acquire the mutex and possibly block.
Definition:
none.hpp:42
Gecode::Kernel::GPI::fail
void fail(Info &c)
Increment failure count.
Definition:
gpi.hpp:126
Gecode::Kernel::GPI::Info::pid
unsigned int pid
Propagator identifier.
Definition:
gpi.hpp:45
Gecode::Kernel::GPI
Global propagator information.
Definition:
gpi.hpp:39
Gecode::Kernel::GPI::unshare
bool unshare(void)
Provide access to unshare info and set to true.
Definition:
gpi.hpp:154
Gecode::Kernel::GPI::pid
unsigned int pid(void) const
Return next free propagator id.
Definition:
gpi.hpp:145
Gecode::Kernel::GPI::decay
double decay(void) const
Return decay factor.
Definition:
gpi.hpp:136
Gecode::Kernel::GPI::GPI
GPI(void)
Initialize.
Definition:
gpi.hpp:122
Gecode
Gecode toplevel namespace
u
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Gecode::Kernel::GPI::Info::gid
unsigned int gid
Group identifier.
Definition:
gpi.hpp:47
GECODE_KERNEL_EXPORT
#define GECODE_KERNEL_EXPORT
Definition:
kernel.hh:70
Gecode::HeapAllocated
Base class for heap allocated objects.
Definition:
heap.hpp:340
Gecode::Kernel::GPI::Info::init
void init(unsigned int pid, unsigned int gid)
Initialize.
Definition:
gpi.hpp:105
Test::afc
AFC afc
Definition:
afc.cpp:135
Gecode::Kernel::GPI::Info::afc
double afc
The afc value.
Definition:
gpi.hpp:49
Test::Int::Distinct::d
Gecode::IntSet d(v, 7)
Gecode::Kernel::GPI::Info
Class for storing propagator information.
Definition:
gpi.hpp:42
forceinline
#define forceinline
Definition:
config.hpp:185
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::Support::Mutex::release
void release(void)
Release the mutex.
Definition:
none.hpp:48
Gecode::Support::Mutex
A mutex for mutual exclausion among several threads.
Definition:
thread.hpp:96
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::Kernel::GPI::~GPI
~GPI(void)
Delete.
Definition:
gpi.hpp:198
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:232
Gecode::Kernel::Config::rescale
const double rescale
Rescale factor for action and afc values.
Definition:
kernel.hh:99
Gecode::Kernel::Config::rescale_limit
const double rescale_limit
Rescale action and afc values when larger than this.
Definition:
kernel.hh:101