SUMO - Simulation of Urban MObility
AGHousehold.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A household contains the people and cars of the city: roughly represents
11 // families with their address, cars, adults and possibly children
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
15 // activitygen module
16 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
38 #include "AGHousehold.h"
39 #include "AGCar.h"
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 void
46 AGHousehold::generatePeople(int numAdults, int numChilds, bool firstRetired) {
48  //the first adult
50  if (firstRetired) {
52  }
53  myAdults.push_back(pers);
54  //further adults
55  while (static_cast<int>(myAdults.size()) < numAdults) {
56  if (firstRetired) {
58  myAdults.push_back(pers2);
59  } else {
61  myAdults.push_back(pers2);
62  }
63  }
64  //Children
65  while (static_cast<int>(myChildren.size()) < numChilds) {
67  myChildren.push_back(chl);
68  }
69 }
70 
71 void
73  int peopleInNeed = static_cast<int>(myAdults.size()) - static_cast<int>(myCars.size());
74  while (peopleInNeed > 0) {
75  if (RandHelper::rand() < rate) {
76  addACar();
77  }
78  --peopleInNeed;
79  }
80 }
81 
82 void
84  int numCar = static_cast<int>(myCars.size() + 1);
85  myCars.push_back(AGCar(myId, numCar));
86 }
87 
88 int
90  return static_cast<int>(myCars.size());
91 }
92 
93 unsigned int
95  return static_cast<unsigned int>(myAdults.size() + myChildren.size());
96 }
97 
98 unsigned int
100  return static_cast<unsigned int>(myAdults.size());
101 }
102 
103 const std::list<AGAdult>&
105  return myAdults;
106 }
107 
108 const std::list<AGChild>&
110  return myChildren;
111 }
112 
113 const std::list<AGCar>&
115  return myCars;
116 }
117 
118 bool
119 AGHousehold::isCloseFromPubTransport(std::list<AGPosition>* pubTransport) {
120  SUMOReal distToPT = myLocation.minDistanceTo(*pubTransport);
121  if (distToPT > myCity->statData.maxFootDistance) {
122  return false;
123  }
124  return true;
125 }
126 
127 bool
128 AGHousehold::isCloseFromPubTransport(std::map<int, AGPosition>* pubTransport) {
129  SUMOReal distToPT = myLocation.minDistanceTo(*pubTransport);
130  if (distToPT > myCity->statData.maxFootDistance) {
131  return false;
132  }
133  return true;
134 }
135 
136 void
138  //only allocation of work or school to people will change
139  std::list<AGChild>::iterator itC;
140  std::list<AGAdult>::iterator itA;
141  for (itC = myChildren.begin(); itC != myChildren.end(); ++itC) {
142  if (itC->haveASchool()) {
143  if (itC->leaveSchool()) {
144  itC->allocateASchool(&(myCity->schools), getPosition());
145  }
146  } else {
147  itC->allocateASchool(&(myCity->schools), getPosition());
148  }
149  }
150  for (itA = myAdults.begin(); itA != myAdults.end(); ++itA) {
151  if (itA->isWorking()) {
152  itA->resignFromWorkPosition();
153  }
154 
155  if (myCity->statData.workPositions > 0) {
156  itA->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions));
157 
158  } else {
159  std::cout << "Not enough work positions in AGHousehold::regenerate. Should not happen!" << std::endl;
160  }
161  }
162 }
163 
164 bool
166  std::list<AGChild>::iterator it;
167  bool oneRemainsAtHome = false;
168 
169  for (it = myChildren.begin(); it != myChildren.end(); ++it) {
170  if (!it->allocateASchool(&(myCity->schools), myLocation)) {
171  oneRemainsAtHome = true;
172  }
173  }
174  return !oneRemainsAtHome;
175 }
176 
177 bool
179  std::list<AGAdult>::iterator it;
180  for (it = myAdults.begin(); it != myAdults.end(); ++it) {
181  if (myCity->statData.workPositions <= 0) {
182  std::cout << "Not enough free work positions in AGHousehold::allocateAdultsWork. Should not happen." << std::endl;
183  return false;
184 
185  } else {
186  it->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions));
187  }
188  }
189  return true;
190 }
191 
194  return myLocation;
195 }
196 
197 AGCity*
199  return myCity;
200 }
201 
202 bool
204  return (myAdults.front().getAge() >= myCity->statData.limitAgeRetirement);
205 }
206 
207 /****************************************************************************/
Definition: AGCar.h:46
const std::list< AGCar > & getCars() const
bool allocateChildrenSchool()
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:63
static SUMOReal rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
AGCity * myCity
Definition: AGHousehold.h:124
AGDataAndStatistics & statData
Definition: AGCity.h:88
void addACar()
Definition: AGHousehold.cpp:83
int getRandomPopDistributed(int n, int m)
An adult person who can have a job.
Definition: AGAdult.h:58
void regenerate()
void generatePeople(int numAdults, int numChilds, bool firstRetired)
Definition: AGHousehold.cpp:46
int getCarNbr()
Definition: AGHousehold.cpp:89
Definition: AGCity.h:60
SUMOReal minDistanceTo(const std::list< AGPosition > &positions) const
Computes the distance to the closest position in a list.
Definition: AGPosition.cpp:76
std::list< AGSchool > schools
Definition: AGCity.h:91
const std::list< AGAdult > & getAdults() const
std::list< AGAdult > myAdults
Definition: AGHousehold.h:129
AGPosition getPosition()
bool isCloseFromPubTransport(std::list< AGPosition > *pubTransport)
bool retiredHouseholders()
unsigned int getPeopleNbr()
Definition: AGHousehold.cpp:94
AGCity * getTheCity()
unsigned int getAdultNbr()
Definition: AGHousehold.cpp:99
void generateCars(SUMOReal rate)
Definition: AGHousehold.cpp:72
AGPosition myLocation
Definition: AGHousehold.h:125
std::list< AGCar > myCars
Definition: AGHousehold.h:131
#define SUMOReal
Definition: config.h:214
bool allocateAdultsWork()
const std::list< AGChild > & getChildren() const
std::list< AGChild > myChildren
Definition: AGHousehold.h:130
std::vector< AGWorkPosition > workPositions
Definition: AGCity.h:90