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