Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/distribution/Distribution_Parameterized.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
#include <random>
26
27
#include "Distribution.h"
28
29
30
// ===========================================================================
31
// class definitions
32
// ===========================================================================
33
/**
34
* @class Distribution_Parameterized
35
* A description of distribution by the distribution's mean value and a
36
* standard deviation.
37
* Incomplete and unused yet. This class should be overridden by derived
38
* classes
39
*/
40
class Distribution_Parameterized : public Distribution {
41
42
public:
43
/// @brief Constructor for any temporary distribution parsed directly from the description
44
Distribution_Parameterized(const std::string& description);
45
46
/// @brief Constructor for standard normal distribution
47
Distribution_Parameterized(const std::string& id, double mean, double deviation);
48
49
/// @brief Constructor for normal distribution with cutoff
50
Distribution_Parameterized(const std::string& id, double mean, double deviation, double min, double max);
51
52
/// @brief Destructor
53
virtual ~Distribution_Parameterized();
54
55
/// @brief Overwrite by parsable distribution description
56
void parse(const std::string& description, const bool hardFail);
57
58
/** @brief Draw a sample of the distribution using the given RNG.
59
*
60
* A random sample is drawn according to the assigned probabilities.
61
*
62
* @param[in] which The random number generator to use; the static one will be used if nullptr is passed
63
* @return the drawn member
64
*/
65
double sample(SumoRNG* which = nullptr) const;
66
67
/// @brief Returns the maximum value of this distribution
68
double getMax() const;
69
70
/// @brief Returns the minimum value of this distribution
71
double getMin() const;
72
73
/// @brief Returns the nth parameter of this distribution
74
inline double getParameter(const int index) const {
75
return myParameter[index];
76
}
77
78
/// @brief Set a parameter of this distribution
79
void setParameter(const int index, const double value);
80
81
/// @brief check whether the distribution is valid
82
const std::string isValid() const;
83
84
/// @brief Returns the string representation of this distribution
85
std::string toStr(std::streamsize accuracy) const;
86
87
/// @brief validate input description
88
static bool isValidDescription(const std::string& description);
89
90
private:
91
/// @brief The distribution's parameters
92
std::vector<double> myParameter;
93
};
94
95