Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file Distribution_Parameterized.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @date Sept 2002
18 : ///
19 : // A distribution described by parameters such as the mean value and std-dev
20 : /****************************************************************************/
21 : #pragma once
22 : #include <config.h>
23 :
24 : #include <vector>
25 :
26 : #include "Distribution.h"
27 :
28 :
29 : // ===========================================================================
30 : // class definitions
31 : // ===========================================================================
32 : /**
33 : * @class Distribution_Parameterized
34 : * A description of distribution by the distribution's mean value and a
35 : * standard deviation.
36 : * Incomplete and unused yet. This class should be overridden by derived
37 : * classes
38 : */
39 383365 : class Distribution_Parameterized : public Distribution {
40 :
41 : public:
42 : /// @brief Dummy Constructor for a default distribution
43 : Distribution_Parameterized();
44 :
45 : /// @brief Constructor for any temporary distribution parsed directly from the description
46 : Distribution_Parameterized(const std::string& description);
47 :
48 : /// @brief Constructor for standard normal distribution
49 : Distribution_Parameterized(const std::string& id, double mean, double deviation);
50 :
51 : /// @brief Constructor for normal distribution with cutoff
52 : Distribution_Parameterized(const std::string& id, double mean, double deviation, double min, double max);
53 :
54 : /// @brief Destructor
55 : virtual ~Distribution_Parameterized();
56 :
57 : /// @brief Overwrite by parsable distribution description
58 : void parse(const std::string& description, const bool hardFail);
59 :
60 : /** @brief Draw a sample of the distribution using the given RNG.
61 : *
62 : * A random sample is drawn according to the assigned probabilities.
63 : *
64 : * @param[in] which The random number generator to use; the static one will be used if nullptr is passed
65 : * @return the drawn member
66 : */
67 : double sample(SumoRNG* which = nullptr) const;
68 :
69 : /// @brief Returns the maximum value of this distribution
70 : double getMax() const;
71 :
72 : /// @brief Returns the minimum value of this distribution
73 : double getMin() const;
74 :
75 : /// @brief Returns the nth parameter of this distribution
76 : inline double getParameter(const int index) const {
77 13425098 : return myParameter[index];
78 : }
79 :
80 : /// @brief Set a parameter of this distribution
81 : void setParameter(const int index, const double value);
82 :
83 : /// @brief check whether the distribution is valid
84 : const std::string isValid() const;
85 :
86 : bool isDummy() const {
87 : return myParameter.empty();
88 : }
89 :
90 149969 : bool isVariable() const {
91 149969 : return !myParameter.empty() && getMin() != getMax();
92 : }
93 :
94 : /// @brief Returns the string representation of this distribution
95 : std::string toStr(std::streamsize accuracy) const;
96 :
97 : /// @brief validate input description
98 : static bool isValidDescription(const std::string& description, std::string& error);
99 :
100 : private:
101 : /// @brief The distribution's parameters
102 : std::vector<double> myParameter;
103 : };
|