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__SYNTAX__HISTOGRAM_HPP_
16 #define OPENSCENARIO_INTERPRETER__SYNTAX__HISTOGRAM_HPP_
17 
20 #include <random>
21 
23 {
24 inline namespace syntax
25 {
26 /*
27  Histogram (OpenSCENARIO XML 1.3.1)
28 
29  Histogram which can be applied to a single parameter.
30 
31  <xsd:complexType name="Histogram">
32  <xsd:sequence>
33  <xsd:element name="Bin" type="HistogramBin" maxOccurs="unbounded"/>
34  </xsd:sequence>
35  </xsd:complexType>
36 */
37 struct Histogram : public ComplexType, private Scope
38 {
42  const std::list<HistogramBin> bins;
43 
44  struct BinAdaptor
45  {
46  explicit BinAdaptor(const std::list<HistogramBin> & bins)
47  {
48  intervals.emplace_back(bins.front().range.lower_limit.data);
49  for (const auto & bin : bins) {
50  intervals.emplace_back(bin.range.lower_limit.data);
51  densities.emplace_back(bin.weight.data);
52  }
53  intervals.emplace_back(bins.back().range.upper_limit.data);
54  }
55  std::vector<double> intervals, densities;
57 
58  std::piecewise_constant_distribution<Double::value_type> distribute;
59 
60  std::mt19937 random_engine;
61 
62  explicit Histogram(const pugi::xml_node &, Scope & scope);
63 
64  auto evaluate() -> Object;
65 };
66 } // namespace syntax
67 } // namespace openscenario_interpreter
68 #endif // OPENSCENARIO_INTERPRETER__SYNTAX__HISTOGRAM_HPP_
Definition: scope.hpp:154
Definition: hypot.hpp:22
Pointer< Expression > Object
Definition: object.hpp:26
BinAdaptor(const std::list< HistogramBin > &bins)
Definition: histogram.hpp:46
std::vector< double > densities
Definition: histogram.hpp:55
std::vector< double > intervals
Definition: histogram.hpp:55
Definition: histogram.hpp:38
const std::list< HistogramBin > bins
Definition: histogram.hpp:42
struct openscenario_interpreter::syntax::Histogram::BinAdaptor bin_adaptor
std::piecewise_constant_distribution< Double::value_type > distribute
Definition: histogram.hpp:58
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:60