main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
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: 2017-03-08 11:58:56 +0100 (Wed, 08 Mar 2017) $ by $Author: schulte $
11
* $Revision: 15562 $
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
};
62
void
_seed(
unsigned
int
s);
63
public
:
65
GECODE_KERNEL_EXPORT
66
Rnd
(
void
);
68
GECODE_KERNEL_EXPORT
69
Rnd
(
const
Rnd
&
r
);
71
GECODE_KERNEL_EXPORT
72
Rnd
&
operator =
(
const
Rnd
&
r
);
74
GECODE_KERNEL_EXPORT
75
~Rnd
(
void
);
77
GECODE_KERNEL_EXPORT
78
Rnd
(
unsigned
int
s);
80
GECODE_KERNEL_EXPORT
81
void
seed
(
unsigned
int
s);
83
GECODE_KERNEL_EXPORT
84
void
time
(
void
);
86
GECODE_KERNEL_EXPORT
87
void
hw
(
void
);
89
unsigned
int
seed
(
void
)
const
;
91
unsigned
int
operator ()
(
unsigned
int
n
);
93
operator
bool(
void
)
const
;
94
};
95
96
forceinline
unsigned
int
97
Rnd::seed
(
void
)
const
{
98
const
IMP*
i
=
static_cast<
const
IMP*
>
(
object
());
99
return
i
->rg.seed();
100
}
101
forceinline
unsigned
int
102
Rnd::operator ()
(
unsigned
int
n
) {
103
IMP*
i
=
static_cast<
IMP*
>
(
object
());
104
return
i
->rg(
n
);
105
}
106
forceinline
107
Rnd::operator bool(
void
)
const
{
108
return
object() != NULL;
109
}
110
111
}
112
113
// STATISTICS: kernel-other
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Rnd::Rnd
Rnd(void)
Default constructor that does not initialize the generator.
Definition:
rnd.cpp:64
Gecode::Rnd::~Rnd
~Rnd(void)
Destructor.
Definition:
rnd.cpp:75
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::SharedHandle::object
SharedHandle::Object * object(void) const
Access to the shared object.
Definition:
core.hpp:3090
Gecode::Rnd::operator=
Rnd & operator=(const Rnd &r)
Assignment operator.
Definition:
rnd.cpp:71
Gecode::SharedHandle::Object
The shared object.
Definition:
core.hpp:88
Gecode::Rnd::seed
unsigned int seed(void) const
Return current seed.
Definition:
rnd.hpp:97
Gecode
Gecode toplevel namespace
Gecode::Rnd::operator()
unsigned int operator()(unsigned int n)
Return a random integer from the interval [0..n)
Definition:
rnd.hpp:102
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:784
Gecode::Support::LinearCongruentialGenerator
Template for linear congruential generators.
Definition:
random.hpp:50
Gecode::Rnd
Random number generator.
Definition:
rnd.hpp:46
GECODE_KERNEL_EXPORT
#define GECODE_KERNEL_EXPORT
Definition:
kernel.hh:74
Gecode::Rnd::hw
void hw(void)
Set current seed to hardware-based random number (initializes if needed)
Definition:
rnd.cpp:86
Gecode::SharedHandle
The shared handle.
Definition:
core.hpp:79
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::Rnd::time
void time(void)
Set current seed based on time (initializes if needed)
Definition:
rnd.cpp:82