main page
modules
namespaces
classes
files
Gecode home
Generated on Sat May 25 2013 18:00:40 for Gecode by
doxygen
1.8.3.1
gecode
kernel
rnd.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, 2008
8
*
9
* Last modified:
10
* $Date: 2012-09-07 11:29:57 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
11
* $Revision: 13061 $
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 <ctime>
39
40
namespace
Gecode {
41
46
class
Rnd
:
public
SharedHandle
{
47
private
:
49
class
IMP :
public
SharedHandle::Object
{
50
public
:
52
Support::RandomGenerator
rg;
54
IMP(
unsigned
int
s);
56
virtual
~IMP(
void
);
58
GECODE_KERNEL_EXPORT
59
virtual
SharedHandle::Object
* copy(
void
)
const
;
60
};
61
public
:
63
Rnd
(
void
);
65
GECODE_KERNEL_EXPORT
Rnd
(
unsigned
int
s);
67
Rnd
(
const
Rnd&
r
);
69
GECODE_KERNEL_EXPORT
70
void
seed
(
unsigned
int
s);
72
void
time
(
void
);
74
void
hw
(
void
);
76
unsigned
int
seed
(
void
)
const
;
78
unsigned
int
operator ()
(
unsigned
int
n
);
80
bool
initialized
(
void
)
const
;
81
};
82
83
forceinline
84
Rnd::IMP::IMP(
unsigned
int
s)
85
: rg(s) {}
86
87
forceinline
88
Rnd::IMP::~IMP(
void
) {}
89
90
forceinline
91
Rnd::Rnd
(
void
) {}
92
forceinline
93
Rnd::Rnd
(
const
Rnd
&
r
)
94
:
SharedHandle
(r) {}
95
inline
void
96
Rnd::time
(
void
) {
97
seed
(static_cast<unsigned int>(::
time
(NULL)));
98
}
99
inline
void
100
Rnd::hw
(
void
) {
101
seed
(
Support::hwrnd
());
102
}
103
forceinline
unsigned
int
104
Rnd::seed
(
void
)
const
{
105
const
IMP*
i
=
static_cast<
const
IMP*
>
(
object
());
106
return
i->rg.seed();
107
}
108
forceinline
unsigned
int
109
Rnd::operator ()
(
unsigned
int
n
) {
110
IMP*
i
=
static_cast<
IMP*
>
(
object
());
111
return
i->rg(n);
112
}
113
forceinline
bool
114
Rnd::initialized
(
void
)
const
{
115
return
object
() != NULL;
116
}
117
118
}
119
120
// STATISTICS: kernel-other