Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/activitygen/city/AGHousehold.cpp
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
// 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 AGHousehold.cpp
17
/// @author Piotr Woznica
18
/// @author Daniel Krajzewicz
19
/// @author Michael Behrisch
20
/// @author Walter Bamberger
21
/// @date July 2010
22
///
23
// A household contains the people and cars of the city: roughly represents
24
// families with their address, cars, adults and possibly children
25
/****************************************************************************/
26
#include <config.h>
27
28
#include <utils/common/RandHelper.h>
29
#include "AGCar.h"
30
#include "AGChild.h"
31
#include "AGCity.h"
32
#include "AGDataAndStatistics.h"
33
#include "AGHousehold.h"
34
35
36
// ===========================================================================
37
// method definitions
38
// ===========================================================================
39
void
40
AGHousehold::generatePeople(int numAdults, int numChilds, bool firstRetired) {
41
AGDataAndStatistics* ds = &(myCity->statData);
42
//the first adult
43
AGAdult pers(ds->getRandomPopDistributed(ds->limitAgeChildren, ds->limitEndAge));
44
if (firstRetired) {
45
pers = AGAdult(ds->getRandomPopDistributed(ds->limitAgeRetirement, ds->limitEndAge));
46
}
47
myAdults.push_back(pers);
48
//further adults
49
while (static_cast<int>(myAdults.size()) < numAdults) {
50
if (firstRetired) {
51
AGAdult pers2(ds->getRandomPopDistributed(ds->limitAgeRetirement, ds->limitEndAge));
52
myAdults.push_back(pers2);
53
} else {
54
AGAdult pers2(ds->getRandomPopDistributed(ds->limitAgeChildren, ds->limitAgeRetirement));
55
myAdults.push_back(pers2);
56
}
57
}
58
//Children
59
while (static_cast<int>(myChildren.size()) < numChilds) {
60
AGChild chl(ds->getRandomPopDistributed(0, ds->limitAgeChildren));
61
myChildren.push_back(chl);
62
}
63
}
64
65
void
66
AGHousehold::generateCars(double rate) {
67
int peopleInNeed = static_cast<int>(myAdults.size()) - static_cast<int>(myCars.size());
68
while (peopleInNeed > 0) {
69
if (RandHelper::rand() < rate) {
70
addACar();
71
}
72
--peopleInNeed;
73
}
74
}
75
76
void
77
AGHousehold::addACar() {
78
int numCar = static_cast<int>(myCars.size() + 1);
79
myCars.push_back(AGCar(myId, numCar));
80
}
81
82
int
83
AGHousehold::getCarNbr() {
84
return static_cast<int>(myCars.size());
85
}
86
87
int
88
AGHousehold::getPeopleNbr() {
89
return static_cast<int>(myAdults.size() + myChildren.size());
90
}
91
92
int
93
AGHousehold::getAdultNbr() {
94
return static_cast<int>(myAdults.size());
95
}
96
97
const std::list<AGAdult>&
98
AGHousehold::getAdults() const {
99
return myAdults;
100
}
101
102
const std::list<AGChild>&
103
AGHousehold::getChildren() const {
104
return myChildren;
105
}
106
107
const std::list<AGCar>&
108
AGHousehold::getCars() const {
109
return myCars;
110
}
111
112
bool
113
AGHousehold::isCloseFromPubTransport(std::list<AGPosition>* pubTransport) {
114
double distToPT = myLocation.minDistanceTo(*pubTransport);
115
if (distToPT > myCity->statData.maxFootDistance) {
116
return false;
117
}
118
return true;
119
}
120
121
bool
122
AGHousehold::isCloseFromPubTransport(std::map<int, AGPosition>* pubTransport) {
123
double distToPT = myLocation.minDistanceTo(*pubTransport);
124
if (distToPT > myCity->statData.maxFootDistance) {
125
return false;
126
}
127
return true;
128
}
129
130
void
131
AGHousehold::regenerate() {
132
//only allocation of work or school to people will change
133
std::list<AGChild>::iterator itC;
134
std::list<AGAdult>::iterator itA;
135
for (itC = myChildren.begin(); itC != myChildren.end(); ++itC) {
136
if (itC->haveASchool()) {
137
if (itC->leaveSchool()) {
138
itC->allocateASchool(&(myCity->schools), getPosition());
139
}
140
} else {
141
itC->allocateASchool(&(myCity->schools), getPosition());
142
}
143
}
144
for (itA = myAdults.begin(); itA != myAdults.end(); ++itA) {
145
if (itA->isWorking()) {
146
itA->resignFromWorkPosition();
147
}
148
149
if (myCity->statData.workPositions > 0) {
150
itA->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions));
151
152
} else {
153
std::cout << "Not enough work positions in AGHousehold::regenerate. Should not happen!" << std::endl;
154
}
155
}
156
}
157
158
bool
159
AGHousehold::allocateChildrenSchool() {
160
std::list<AGChild>::iterator it;
161
bool oneRemainsAtHome = false;
162
163
for (it = myChildren.begin(); it != myChildren.end(); ++it) {
164
if (!it->allocateASchool(&(myCity->schools), myLocation)) {
165
oneRemainsAtHome = true;
166
}
167
}
168
return !oneRemainsAtHome;
169
}
170
171
bool
172
AGHousehold::allocateAdultsWork() {
173
std::list<AGAdult>::iterator it;
174
for (it = myAdults.begin(); it != myAdults.end(); ++it) {
175
if (myCity->statData.workPositions <= 0) {
176
std::cout << "Not enough free work positions in AGHousehold::allocateAdultsWork. Should not happen." << std::endl;
177
return false;
178
179
} else {
180
it->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions));
181
}
182
}
183
return true;
184
}
185
186
AGPosition
187
AGHousehold::getPosition() {
188
return myLocation;
189
}
190
191
AGCity*
192
AGHousehold::getTheCity() {
193
return myCity;
194
}
195
196
bool
197
AGHousehold::retiredHouseholders() {
198
return (myAdults.front().getAge() >= myCity->statData.limitAgeRetirement);
199
}
200
201
202
/****************************************************************************/
203
204