Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 : // activitygen module
5 : // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6 : // This program and the accompanying materials are made available under the
7 : // terms of the Eclipse Public License 2.0 which is available at
8 : // https://www.eclipse.org/legal/epl-2.0/
9 : // This Source Code may also be made available under the following Secondary
10 : // Licenses when the conditions for such availability set forth in the Eclipse
11 : // Public License 2.0 are satisfied: GNU General Public License, version 2
12 : // or later which is available at
13 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
14 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
15 : /****************************************************************************/
16 : /// @file AGDataAndStatistics.h
17 : /// @author Piotr Woznica
18 : /// @author Daniel Krajzewicz
19 : /// @author Jakob Erdmann
20 : /// @author Walter Bamberger
21 : /// @date July 2010
22 : ///
23 : // Contains various data, statistical values and functions from input used
24 : // by various objects
25 : /****************************************************************************/
26 : #pragma once
27 : #include <config.h>
28 :
29 : #include <iostream>
30 : #include <map>
31 : #include "AGSchool.h"
32 : #include "AGPosition.h"
33 :
34 :
35 : // ===========================================================================
36 : // class definitions
37 : // ===========================================================================
38 : class AGDataAndStatistics {
39 : public:
40 : /**
41 : * parameters
42 : */
43 : double speedTimePerKm; //number of seconds for one km
44 : double carPreference; //prob. to choose the car (compared to the bus)
45 :
46 : /**
47 : * from General element from XML file.
48 : */
49 : int inhabitants;
50 : int households;
51 : int limitAgeChildren;
52 : int limitAgeRetirement;
53 : int limitEndAge;
54 : double carRate;
55 : double unemployement;
56 : double laborDemand;
57 : double maxFootDistance;
58 : int incomingTraffic;
59 : int outgoingTraffic;
60 : double freeTimeActivityRate;
61 : double uniformRandomTrafficRate;
62 : double departureVariation;
63 :
64 : std::map<int, double> beginWorkHours; //<hour, probability> (number only used in term of PROPORTION: it should be normalized)
65 : std::map<int, double> endWorkHours; //<hour, probability> (number only used in term of PROPORTION: it should be normalized)
66 : std::map<int, AGPosition> busStations; //<id, position>
67 : //std::map<SchoolType, int> schoolCapacity;
68 : std::map<int, double> population; //<bracket's end age, number> (number only used in term of PROPORTION: it should be normalized)
69 : std::map<int, int> ageSpan; // <brachets begin age, endage>
70 : //std::map<int, double> childrenAccompagniment; //<bracket's end age, probability>
71 : /**
72 : * number of incoming or outgoing people through the given city gates
73 : * PROPORTION: it should be normalized
74 : */
75 : std::map<int, double> incoming;
76 : std::map<int, double> outgoing;
77 :
78 : /**
79 : * computed values used during processing
80 : */
81 : int workPositions;
82 : double factorInhabitants;
83 : double factorWorkPositions;
84 :
85 : /**
86 : * data used for household generation
87 : * has to be computed before.
88 : */
89 : //probability of picking an old-people household (compared to working and have children adults)
90 : double oldAgeHhProb;
91 : //probability of having a second adult (old in case of old householders) in the household.
92 : double secondPersProb;
93 : //this s the mean number of children pro household (not old). This value is used in the Poisson-lay for determining the number of children in each family
94 : double meanNbrChildren;
95 :
96 : /**
97 : * numbers not needed but interesting for statistics and TESTING
98 : */
99 : //int childrenNbr;
100 : //int oldPeopleNbr;
101 : int AdultNbr;
102 : int householdsNbr;
103 : //households far from public transports
104 : int hhFarFromPT;
105 :
106 : static AGDataAndStatistics& getDataAndStatistics();
107 :
108 : /**
109 : * function returning a random number between the two given numbers: [n;m[ (m cannot occur)
110 : * it returns 0 if m < n
111 : */
112 : int getRandom(int n, int m);
113 : /**
114 : * function returning a random age between the two numbers satisfying the previous constrains
115 : * this number is in relation to the distribution of the population through the brackets (population's list)
116 : * if the given numbers are both greater than limitEndAge, it returns 0
117 : * if m is greater than limitEndAge, m=limitEndAge
118 : * returns -1 if conditions are not satisfied
119 : */
120 : int getRandomPopDistributed(int n, int m);
121 : /**
122 : * function evaluating the POISSON's lay (probability lay)
123 : * it returns the number of children with a probability of POISSON in a household
124 : * is given the mean of the distribution
125 : *
126 : * TODO Consider reimplementation
127 : */
128 : int getPoissonsNumberOfChildren(double mean);
129 : /**
130 : * these functions return the number of people having more (or less) than the given age
131 : * (inclusive for getPeopleOlderThan; exclusive for getPeopleYoungerThan)
132 : * getPeopleOlderThan(n) + getPeopleYoungerThan(n) = inhabitants
133 : * these first two function are based on the third one.
134 : */
135 : int getPeopleOlderThan(int age);
136 : int getPeopleYoungerThan(int age);
137 : double getPropYoungerThan(int age);
138 : /**
139 : * function consolidating statistics:
140 : * normalizes the maps with probabilities
141 : * completes data which have to be computed before use
142 : */
143 : void consolidateStat();
144 : /**
145 : * function returning a random value corresponding to this distribution:
146 : * -mean is given
147 : * -max variation of the mean (|possible value - mean| <= maxVar
148 : * -the mean is the most probable
149 : * -the probability distribution function is a "scaled exponential" distribution
150 : * from mean-maxVar to mean and from mean to mean+maxVar
151 : */
152 : double getInverseExpRandomValue(double mean, double maxVar);
153 : /**
154 : * function returning a random city gate corresponding to
155 : * the distribution of the incoming/outgoing traffic
156 : * In fact, it returns the position of a city gate in the citygate vector.
157 : */
158 : int getRandomCityGateByIncoming();
159 : int getRandomCityGateByOutgoing();
160 :
161 : private:
162 10 : AGDataAndStatistics() {}
163 :
164 : /**
165 : * returns the POISSON's probability (exp(-m)*m^k/k!)
166 : * @arg: mean of the distribution
167 : * @arg: number of occurrences
168 : *
169 : * TODO Create a Poisson distribution class for this. Or is it in Boost?
170 : */
171 : double poisson(double mean, int occ);
172 : /**
173 : * recursive mathematical function returning the factorial of n: n!
174 : */
175 : int factorial(int n);
176 :
177 : //function normalizing the map's probabilities: Sum(floats) = 1
178 : void normalizeMapProb(std::map<int, double>* myMap);
179 : };
|