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.org/sumo
3 // Copyright (C) 2001-2019 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 "AGCar.h"
32 #include "AGChild.h"
33 #include "AGCity.h"
34 #include "AGDataAndStatistics.h"
35 #include "AGHousehold.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 void
42 AGHousehold::generatePeople(int numAdults, int numChilds, bool firstRetired) {
44  //the first adult
46  if (firstRetired) {
48  }
49  myAdults.push_back(pers);
50  //further adults
51  while (static_cast<int>(myAdults.size()) < numAdults) {
52  if (firstRetired) {
54  myAdults.push_back(pers2);
55  } else {
57  myAdults.push_back(pers2);
58  }
59  }
60  //Children
61  while (static_cast<int>(myChildren.size()) < numChilds) {
63  myChildren.push_back(chl);
64  }
65 }
66 
67 void
69  int peopleInNeed = static_cast<int>(myAdults.size()) - static_cast<int>(myCars.size());
70  while (peopleInNeed > 0) {
71  if (RandHelper::rand() < rate) {
72  addACar();
73  }
74  --peopleInNeed;
75  }
76 }
77 
78 void
80  int numCar = static_cast<int>(myCars.size() + 1);
81  myCars.push_back(AGCar(myId, numCar));
82 }
83 
84 int
86  return static_cast<int>(myCars.size());
87 }
88 
89 int
91  return static_cast<int>(myAdults.size() + myChildren.size());
92 }
93 
94 int
96  return static_cast<int>(myAdults.size());
97 }
98 
99 const std::list<AGAdult>&
101  return myAdults;
102 }
103 
104 const std::list<AGChild>&
106  return myChildren;
107 }
108 
109 const std::list<AGCar>&
111  return myCars;
112 }
113 
114 bool
115 AGHousehold::isCloseFromPubTransport(std::list<AGPosition>* pubTransport) {
116  double distToPT = myLocation.minDistanceTo(*pubTransport);
117  if (distToPT > myCity->statData.maxFootDistance) {
118  return false;
119  }
120  return true;
121 }
122 
123 bool
124 AGHousehold::isCloseFromPubTransport(std::map<int, AGPosition>* pubTransport) {
125  double distToPT = myLocation.minDistanceTo(*pubTransport);
126  if (distToPT > myCity->statData.maxFootDistance) {
127  return false;
128  }
129  return true;
130 }
131 
132 void
134  //only allocation of work or school to people will change
135  std::list<AGChild>::iterator itC;
136  std::list<AGAdult>::iterator itA;
137  for (itC = myChildren.begin(); itC != myChildren.end(); ++itC) {
138  if (itC->haveASchool()) {
139  if (itC->leaveSchool()) {
140  itC->allocateASchool(&(myCity->schools), getPosition());
141  }
142  } else {
143  itC->allocateASchool(&(myCity->schools), getPosition());
144  }
145  }
146  for (itA = myAdults.begin(); itA != myAdults.end(); ++itA) {
147  if (itA->isWorking()) {
148  itA->resignFromWorkPosition();
149  }
150 
151  if (myCity->statData.workPositions > 0) {
152  itA->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions));
153 
154  } else {
155  std::cout << "Not enough work positions in AGHousehold::regenerate. Should not happen!" << std::endl;
156  }
157  }
158 }
159 
160 bool
162  std::list<AGChild>::iterator it;
163  bool oneRemainsAtHome = false;
164 
165  for (it = myChildren.begin(); it != myChildren.end(); ++it) {
166  if (!it->allocateASchool(&(myCity->schools), myLocation)) {
167  oneRemainsAtHome = true;
168  }
169  }
170  return !oneRemainsAtHome;
171 }
172 
173 bool
175  std::list<AGAdult>::iterator it;
176  for (it = myAdults.begin(); it != myAdults.end(); ++it) {
177  if (myCity->statData.workPositions <= 0) {
178  std::cout << "Not enough free work positions in AGHousehold::allocateAdultsWork. Should not happen." << std::endl;
179  return false;
180 
181  } else {
182  it->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions));
183  }
184  }
185  return true;
186 }
187 
190  return myLocation;
191 }
192 
193 AGCity*
195  return myCity;
196 }
197 
198 bool
200  return (myAdults.front().getAge() >= myCity->statData.limitAgeRetirement);
201 }
202 
203 /****************************************************************************/
Definition: AGCar.h:39
const std::list< AGAdult > & getAdults() const
void generateCars(double rate)
Definition: AGHousehold.cpp:68
int getAdultNbr()
Definition: AGHousehold.cpp:95
bool allocateChildrenSchool()
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:60
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:79
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:42
int getCarNbr()
Definition: AGHousehold.cpp:85
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:90
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