Eclipse SUMO - Simulation of Urban MObility
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 // ===========================================================================
39 void
40 AGHousehold::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 
65 void
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
78  int numCar = static_cast<int>(myCars.size() + 1);
79  myCars.push_back(AGCar(myId, numCar));
80 }
81 
82 int
84  return static_cast<int>(myCars.size());
85 }
86 
87 int
89  return static_cast<int>(myAdults.size() + myChildren.size());
90 }
91 
92 int
94  return static_cast<int>(myAdults.size());
95 }
96 
97 const std::list<AGAdult>&
99  return myAdults;
100 }
101 
102 const std::list<AGChild>&
104  return myChildren;
105 }
106 
107 const std::list<AGCar>&
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
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
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
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 
188  return myLocation;
189 }
190 
191 AGCity*
193  return myCity;
194 }
195 
196 bool
198  return (myAdults.front().getAge() >= myCity->statData.limitAgeRetirement);
199 }
200 
201 
202 /****************************************************************************/
An adult person who can have a job.
Definition: AGAdult.h:48
Definition: AGCar.h:36
Definition: AGCity.h:50
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)
Definition: AGHousehold.cpp:66
AGPosition getPosition()
AGCity * myCity
Definition: AGHousehold.h:114
const std::list< AGCar > & getCars() const
AGCity * getTheCity()
std::list< AGAdult > myAdults
Definition: AGHousehold.h:119
void generatePeople(int numAdults, int numChilds, bool firstRetired)
Definition: AGHousehold.cpp:40
void regenerate()
bool isCloseFromPubTransport(std::list< AGPosition > *pubTransport)
std::list< AGChild > myChildren
Definition: AGHousehold.h:120
bool allocateAdultsWork()
int getCarNbr()
Definition: AGHousehold.cpp:83
std::list< AGCar > myCars
Definition: AGHousehold.h:121
int getPeopleNbr()
Definition: AGHousehold.cpp:88
AGPosition myLocation
Definition: AGHousehold.h:115
int getAdultNbr()
Definition: AGHousehold.cpp:93
bool retiredHouseholders()
const std::list< AGChild > & getChildren() const
bool allocateChildrenSchool()
const std::list< AGAdult > & getAdults() const
Definition: AGHousehold.cpp:98
void addACar()
Definition: AGHousehold.cpp:77
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.
Definition: AGPosition.cpp:67
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.cpp:94