SMACC2
eg_random_generator.cpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
16
17namespace smacc2
18{
19namespace state_reactors
20{
22 RandomGenerateReactorMode mode, double evAMin, double evAMax, double evBMin, double evBMax,
23 double evCMin, double evCMax)
24: mode_(mode),
25 evAMin_(evAMin),
26 evAMax_(evAMax),
27 evBMin_(evBMin),
28 evBMax_(evBMax),
29 evCMin_(evCMin),
30 evCMax_(evCMax)
31{
32 auto values = {evAMin, evAMax, evBMin, evBMax, evCMin, evCMax};
33
34 this->minValue = std::numeric_limits<double>::max();
35 this->maxValue = std::numeric_limits<double>::min();
36 for (auto & v : values)
37 {
38 if (v < minValue)
39 {
40 minValue = v;
41 }
42
43 if (v > maxValue)
44 {
45 maxValue = v;
46 }
47 }
48}
49
51{
52 int range = this->maxValue - this->minValue;
53 int result = (rand() % range) + minValue;
54
55 if (result >= evAMin_ && result <= evAMax_)
56 {
57 this->postEventA();
58 }
59
60 if (result >= evBMin_ && result <= evBMax_)
61 {
62 this->postEventB();
63 }
64
65 if (result >= evCMin_ && result <= evCMax_)
66 {
67 this->postEventC();
68 }
69}
70
72{
74 {
75 this->postRandomEvents();
76 }
77}
78
80{
82 {
83 this->postRandomEvents();
84 }
85}
86} // namespace state_reactors
87} // namespace smacc2
EgRandomGenerator(RandomGenerateReactorMode mode, double evAMin=1, double evAMax=4, double evBMin=5, double evBMax=8, double evCMin=9, double evCMax=12)