Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
AGHousehold.cpp
Go to the documentation of this file.
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/****************************************************************************/
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
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// ===========================================================================
39void
40AGHousehold::generatePeople(int numAdults, int numChilds, bool firstRetired) {
42 //the first adult
44 if (firstRetired) {
46 }
47 myAdults.push_back(pers);
48 //further adults
49 while (static_cast<int>(myAdults.size()) < numAdults) {
50 if (firstRetired) {
52 myAdults.push_back(pers2);
53 } else {
55 myAdults.push_back(pers2);
56 }
57 }
58 //Children
59 while (static_cast<int>(myChildren.size()) < numChilds) {
61 myChildren.push_back(chl);
62 }
63}
64
65void
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
76void
78 int numCar = static_cast<int>(myCars.size() + 1);
79 myCars.push_back(AGCar(myId, numCar));
80}
81
82int
84 return static_cast<int>(myCars.size());
85}
86
87int
89 return static_cast<int>(myAdults.size() + myChildren.size());
90}
91
92int
94 return static_cast<int>(myAdults.size());
95}
96
97const std::list<AGAdult>&
99 return myAdults;
100}
101
102const std::list<AGChild>&
104 return myChildren;
105}
106
107const std::list<AGCar>&
109 return myCars;
110}
111
112bool
113AGHousehold::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
121bool
122AGHousehold::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
130void
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
158bool
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
171bool
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
190
191AGCity*
193 return myCity;
194}
195
196bool
200
201
202/****************************************************************************/
An adult person who can have a job.
Definition AGAdult.h:48
Definition AGCar.h:36
std::list< AGSchool > schools
Definition AGCity.h:82
AGDataAndStatistics & statData
Definition AGCity.h:78
std::vector< AGWorkPosition > workPositions
Definition AGCity.h:81
int getRandomPopDistributed(int n, int m)
void generateCars(double rate)
AGPosition getPosition()
AGCity * myCity
const std::list< AGCar > & getCars() const
AGCity * getTheCity()
std::list< AGAdult > myAdults
void generatePeople(int numAdults, int numChilds, bool firstRetired)
void regenerate()
bool isCloseFromPubTransport(std::list< AGPosition > *pubTransport)
std::list< AGChild > myChildren
bool allocateAdultsWork()
std::list< AGCar > myCars
int getPeopleNbr()
AGPosition myLocation
int getAdultNbr()
bool retiredHouseholders()
const std::list< AGChild > & getChildren() const
bool allocateChildrenSchool()
const std::list< AGAdult > & getAdults() const
A location in the 2D plane freely positioned on a street.
Definition AGPosition.h:53
double minDistanceTo(const std::list< AGPosition > &positions) const
Computes the distance to the closest position in a list.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)