SMACC
Loading...
Searching...
No Matches
smacc_event_generator_library
eg_random_generator
src
eg_random_generator
eg_random_generator.cpp
Go to the documentation of this file.
1
#include <
eg_random_generator/eg_random_generator.h
>
2
3
namespace
smacc
4
{
5
namespace
state_reactors
6
{
7
EgRandomGenerator::EgRandomGenerator
(
RandomGenerateReactorMode
mode,
double
evAMin,
double
evAMax,
double
evBMin,
double
evBMax,
double
evCMin,
double
evCMax)
8
:
9
mode_(mode),
10
evAMin_(evAMin),
11
evAMax_(evAMax),
12
evBMin_(evBMin),
13
evBMax_(evBMax),
14
evCMin_(evCMin),
15
evCMax_(evCMax)
16
{
17
18
auto
values = {evAMin, evAMax, evBMin, evBMax, evCMin, evCMax};
19
20
this->
minValue
= std::numeric_limits<double>::max();
21
this->
maxValue
= std::numeric_limits<double>::min();
22
for
(
auto
&v : values)
23
{
24
if
(v <
minValue
)
25
{
26
minValue
= v;
27
}
28
29
if
(v >
maxValue
)
30
{
31
maxValue
= v;
32
}
33
}
34
}
35
36
void
EgRandomGenerator::postRandomEvents
()
37
{
38
int
range = this->
maxValue
- this->
minValue
;
39
int
result = (rand() % range) +
minValue
;
40
41
if
(result >=
evAMin_
&& result <=
evAMax_
)
42
{
43
this->
postEventA
();
44
}
45
46
if
(result >=
evBMin_
&& result <=
evBMax_
)
47
{
48
this->
postEventB
();
49
}
50
51
if
(result >=
evCMin_
&& result <=
evCMax_
)
52
{
53
this->
postEventC
();
54
}
55
}
56
57
void
EgRandomGenerator::onEntry
()
58
{
59
if
(
mode_
==
RandomGenerateReactorMode::ONE_SHOT
)
60
{
61
this->
postRandomEvents
();
62
}
63
}
64
65
void
EgRandomGenerator::update
()
66
{
67
if
(
mode_
==
RandomGenerateReactorMode::ON_UPDATE
)
68
{
69
this->
postRandomEvents
();
70
}
71
}
72
}
// namespace state_reactors
73
}
// namespace smacc
smacc::state_reactors::EgRandomGenerator::EgRandomGenerator
EgRandomGenerator(RandomGenerateReactorMode mode, double evAMin=1, double evAMax=4, double evBMin=5, double evBMax=8, double evCMin=9, double evCMax=12)
Definition:
eg_random_generator.cpp:7
smacc::state_reactors::EgRandomGenerator::minValue
double minValue
Definition:
eg_random_generator.h:69
smacc::state_reactors::EgRandomGenerator::update
virtual void update() override
Definition:
eg_random_generator.cpp:65
smacc::state_reactors::EgRandomGenerator::evBMin_
double evBMin_
Definition:
eg_random_generator.h:64
smacc::state_reactors::EgRandomGenerator::evCMax_
double evCMax_
Definition:
eg_random_generator.h:67
smacc::state_reactors::EgRandomGenerator::evCMin_
double evCMin_
Definition:
eg_random_generator.h:66
smacc::state_reactors::EgRandomGenerator::evAMax_
double evAMax_
Definition:
eg_random_generator.h:63
smacc::state_reactors::EgRandomGenerator::evBMax_
double evBMax_
Definition:
eg_random_generator.h:65
smacc::state_reactors::EgRandomGenerator::mode_
RandomGenerateReactorMode mode_
Definition:
eg_random_generator.h:55
smacc::state_reactors::EgRandomGenerator::postRandomEvents
void postRandomEvents()
Definition:
eg_random_generator.cpp:36
smacc::state_reactors::EgRandomGenerator::postEventA
std::function< void()> postEventA
Definition:
eg_random_generator.h:58
smacc::state_reactors::EgRandomGenerator::postEventB
std::function< void()> postEventB
Definition:
eg_random_generator.h:59
smacc::state_reactors::EgRandomGenerator::postEventC
std::function< void()> postEventC
Definition:
eg_random_generator.h:60
smacc::state_reactors::EgRandomGenerator::maxValue
double maxValue
Definition:
eg_random_generator.h:70
smacc::state_reactors::EgRandomGenerator::evAMin_
double evAMin_
Definition:
eg_random_generator.h:62
smacc::state_reactors::EgRandomGenerator::onEntry
virtual void onEntry() override
Definition:
eg_random_generator.cpp:57
eg_random_generator.h
smacc::state_reactors::RandomGenerateReactorMode
RandomGenerateReactorMode
Definition:
eg_random_generator.h:29
smacc::state_reactors::RandomGenerateReactorMode::ON_UPDATE
@ ON_UPDATE
smacc::state_reactors::RandomGenerateReactorMode::ONE_SHOT
@ ONE_SHOT
smacc
Definition:
callback_counter_semaphore.h:17
Generated by
1.9.5