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.org/sumo
3 // Copyright (C) 2001-2018 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
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 // SPDX-License-Identifier: EPL-2.0
11 /****************************************************************************/
20 // A household contains the people and cars of the city: roughly represents
21 // families with their address, cars, adults and possibly children
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
31 #include "AGHousehold.h"
32 #include "AGCar.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 void
39 AGHousehold::generatePeople(int numAdults, int numChilds, bool firstRetired) {
41  //the first adult
43  if (firstRetired) {
45  }
46  myAdults.push_back(pers);
47  //further adults
48  while (static_cast<int>(myAdults.size()) < numAdults) {
49  if (firstRetired) {
51  myAdults.push_back(pers2);
52  } else {
54  myAdults.push_back(pers2);
55  }
56  }
57  //Children
58  while (static_cast<int>(myChildren.size()) < numChilds) {
60  myChildren.push_back(chl);
61  }
62 }
63 
64 void
66  int peopleInNeed = static_cast<int>(myAdults.size()) - static_cast<int>(myCars.size());
67  while (peopleInNeed > 0) {
68  if (RandHelper::rand() < rate) {
69  addACar();
70  }
71  --peopleInNeed;
72  }
73 }
74 
75 void
77  int numCar = static_cast<int>(myCars.size() + 1);
78  myCars.push_back(AGCar(myId, numCar));
79 }
80 
81 int
83  return static_cast<int>(myCars.size());
84 }
85 
86 int
88  return static_cast<int>(myAdults.size() + myChildren.size());
89 }
90 
91 int
93  return static_cast<int>(myAdults.size());
94 }
95 
96 const std::list<AGAdult>&
98  return myAdults;
99 }
100 
101 const std::list<AGChild>&
103  return myChildren;
104 }
105 
106 const std::list<AGCar>&
108  return myCars;
109 }
110 
111 bool
112 AGHousehold::isCloseFromPubTransport(std::list<AGPosition>* pubTransport) {
113  double distToPT = myLocation.minDistanceTo(*pubTransport);
114  if (distToPT > myCity->statData.maxFootDistance) {
115  return false;
116  }
117  return true;
118 }
119 
120 bool
121 AGHousehold::isCloseFromPubTransport(std::map<int, AGPosition>* pubTransport) {
122  double distToPT = myLocation.minDistanceTo(*pubTransport);
123  if (distToPT > myCity->statData.maxFootDistance) {
124  return false;
125  }
126  return true;
127 }
128 
129 void
131  //only allocation of work or school to people will change
132  std::list<AGChild>::iterator itC;
133  std::list<AGAdult>::iterator itA;
134  for (itC = myChildren.begin(); itC != myChildren.end(); ++itC) {
135  if (itC->haveASchool()) {
136  if (itC->leaveSchool()) {
137  itC->allocateASchool(&(myCity->schools), getPosition());
138  }
139  } else {
140  itC->allocateASchool(&(myCity->schools), getPosition());
141  }
142  }
143  for (itA = myAdults.begin(); itA != myAdults.end(); ++itA) {
144  if (itA->isWorking()) {
145  itA->resignFromWorkPosition();
146  }
147 
148  if (myCity->statData.workPositions > 0) {
149  itA->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions));
150 
151  } else {
152  std::cout << "Not enough work positions in AGHousehold::regenerate. Should not happen!" << std::endl;
153  }
154  }
155 }
156 
157 bool
159  std::list<AGChild>::iterator it;
160  bool oneRemainsAtHome = false;
161 
162  for (it = myChildren.begin(); it != myChildren.end(); ++it) {
163  if (!it->allocateASchool(&(myCity->schools), myLocation)) {
164  oneRemainsAtHome = true;
165  }
166  }
167  return !oneRemainsAtHome;
168 }
169 
170 bool
172  std::list<AGAdult>::iterator it;
173  for (it = myAdults.begin(); it != myAdults.end(); ++it) {
174  if (myCity->statData.workPositions <= 0) {
175  std::cout << "Not enough free work positions in AGHousehold::allocateAdultsWork. Should not happen." << std::endl;
176  return false;
177 
178  } else {
179  it->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions));
180  }
181  }
182  return true;
183 }
184 
187  return myLocation;
188 }
189 
190 AGCity*
192  return myCity;
193 }
194 
195 bool
197  return (myAdults.front().getAge() >= myCity->statData.limitAgeRetirement);
198 }
199 
200 /****************************************************************************/
Definition: AGCar.h:39
const std::list< AGAdult > & getAdults() const
Definition: AGHousehold.cpp:97
void generateCars(double rate)
Definition: AGHousehold.cpp:65
int getAdultNbr()
Definition: AGHousehold.cpp:92
bool allocateChildrenSchool()
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:61
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:56
AGCity * myCity
Definition: AGHousehold.h:117
AGDataAndStatistics & statData
Definition: AGCity.h:81
void addACar()
Definition: AGHousehold.cpp:76
int getRandomPopDistributed(int n, int m)
An adult person who can have a job.
Definition: AGAdult.h:51
void regenerate()
void generatePeople(int numAdults, int numChilds, bool firstRetired)
Definition: AGHousehold.cpp:39
int getCarNbr()
Definition: AGHousehold.cpp:82
double minDistanceTo(const std::list< AGPosition > &positions) const
Computes the distance to the closest position in a list.
Definition: AGPosition.cpp:69
Definition: AGCity.h:53
const std::list< AGChild > & getChildren() const
std::list< AGSchool > schools
Definition: AGCity.h:84
std::list< AGAdult > myAdults
Definition: AGHousehold.h:122
AGPosition getPosition()
bool isCloseFromPubTransport(std::list< AGPosition > *pubTransport)
bool retiredHouseholders()
int getPeopleNbr()
Definition: AGHousehold.cpp:87
AGCity * getTheCity()
AGPosition myLocation
Definition: AGHousehold.h:118
std::list< AGCar > myCars
Definition: AGHousehold.h:124
bool allocateAdultsWork()
std::list< AGChild > myChildren
Definition: AGHousehold.h:123
std::vector< AGWorkPosition > workPositions
Definition: AGCity.h:83
const std::list< AGCar > & getCars() const