scenario_simulator_v2 C++ API
histogram.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
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 
15 #ifndef OPENSCENARIO_INTERPRETER__HISTOGRAM_HPP_
16 #define OPENSCENARIO_INTERPRETER__HISTOGRAM_HPP_
17 
20 #include <random>
21 
23 {
24 inline namespace syntax
25 {
26 /* ---- Histogram 1.2 ----------------------------------------------------------
27  *
28  * <xsd:complexType name="Histogram">
29  * <xsd:sequence>
30  * <xsd:element name="Bin" type="HistogramBin" maxOccurs="unbounded"/>
31  * </xsd:sequence>
32  * </xsd:complexType>
33  *
34  * -------------------------------------------------------------------------- */
35 
36 struct Histogram : public ComplexType, private Scope
37 {
41  const std::list<HistogramBin> bins;
42 
43  struct BinAdaptor
44  {
45  explicit BinAdaptor(const std::list<HistogramBin> & bins)
46  {
47  intervals.emplace_back(bins.front().range.lower_limit.data);
48  for (const auto & bin : bins) {
49  intervals.emplace_back(bin.range.lower_limit.data);
50  densities.emplace_back(bin.weight.data);
51  }
52  intervals.emplace_back(bins.back().range.upper_limit.data);
53  }
54  std::vector<double> intervals, densities;
56 
57  std::piecewise_constant_distribution<Double::value_type> distribute;
58 
59  std::mt19937 random_engine;
60 
61  explicit Histogram(const pugi::xml_node &, Scope & scope);
62 
63  auto evaluate() -> Object;
64 };
65 } // namespace syntax
66 } // namespace openscenario_interpreter
67 #endif // OPENSCENARIO_INTERPRETER__HISTOGRAM_HPP_
Definition: scope.hpp:154
Definition: escape_sequence.hpp:22
Pointer< Expression > Object
Definition: object.hpp:26
BinAdaptor(const std::list< HistogramBin > &bins)
Definition: histogram.hpp:45
std::vector< double > densities
Definition: histogram.hpp:54
std::vector< double > intervals
Definition: histogram.hpp:54
Definition: histogram.hpp:37
const std::list< HistogramBin > bins
Definition: histogram.hpp:41
struct openscenario_interpreter::syntax::Histogram::BinAdaptor bin_adaptor
std::piecewise_constant_distribution< Double::value_type > distribute
Definition: histogram.hpp:57
Histogram(const pugi::xml_node &, Scope &scope)
Definition: histogram.cpp:22
auto evaluate() -> Object
Definition: histogram.cpp:32
std::mt19937 random_engine
Definition: histogram.hpp:59