SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.sourceforge.net/
14 // Copyright (C) 2001-2012 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
48  //the first adult
50  adults.push_back(pers);
51 
52  //the second adult
53  if (decisionProba(ds->secondPersProb)) {
54  if (pers.getAge() < ds->limitAgeRetirement) {
56  adults.push_back(pers2);
57  } else {
59  adults.push_back(pers2);
60  }
61  }
62 
63  //Children
64  if (pers.getAge() < ds->limitAgeRetirement) {
65  int numChild = ds->getPoissonsNumberOfChildren(ds->meanNbrChildren);
66  while (numChild > 0) {
68  children.push_back(chl);
69  --numChild;
70  }
71  }
72 }
73 
74 void
76  int peopleInNeed = static_cast<int>(adults.size()) - static_cast<int>(cars.size());
77  while (peopleInNeed > 0) {
78  if (decisionProba(rate)) {
79  addACar();
80  }
81  --peopleInNeed;
82  }
83 }
84 
85 void
87  int numCar = static_cast<int>(cars.size() + 1);
88  cars.push_back(AGCar(idHH, numCar));
89 }
90 
91 int
93  return static_cast<int>(cars.size());
94 }
95 
96 int
98  return static_cast<int>(adults.size() + children.size());
99 }
100 
101 int
103  return static_cast<int>(adults.size());
104 }
105 
106 bool
107 AGHousehold::isCloseFromPubTransport(std::list<AGPosition> *pubTransport) {
108  SUMOReal distToPT = location.minDistanceTo(*pubTransport);
109  if (distToPT > myCity->statData.maxFootDistance) {
110  return false;
111  }
112  return true;
113 }
114 
115 bool
116 AGHousehold::isCloseFromPubTransport(std::map<int, AGPosition> *pubTransport) {
117  SUMOReal distToPT = location.minDistanceTo(*pubTransport);
118  if (distToPT > myCity->statData.maxFootDistance) {
119  return false;
120  }
121  return true;
122 }
123 
124 void
126  //only allocation of work or school to people will change
127  std::list<AGChild>::iterator itC;
128  std::list<AGAdult>::iterator itA;
129  for (itC = children.begin() ; itC != children.end() ; ++itC) {
130  if (itC->haveASchool()) {
131  if (itC->leaveSchool()) {
132  itC->alocateASchool(&(myCity->schools), getPosition());
133  }
134  } else {
135  itC->alocateASchool(&(myCity->schools), getPosition());
136  }
137  }
138  for (itA = adults.begin() ; itA != adults.end() ; ++itA) {
139  if (itA->isWorking()) {
140  itA->resignFromWorkPosition();
141  }
142 
143  if (myCity->statData.workPositions > 0) {
144  itA->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions));
145 
146  } else {
147  std::cout << "Not enough work positions in AGHousehold::regenerate. Should not happen!" << std::endl;
148  }
149  }
150 }
151 
152 bool
154  std::list<AGChild>::iterator it;
155  bool oneRemainsAtHome = false;
156 
157  for (it = children.begin() ; it != children.end() ; ++it) {
158  if (!it->alocateASchool(&(myCity->schools), location)) {
159  oneRemainsAtHome = true;
160  }
161  }
162  return !oneRemainsAtHome;
163 }
164 
165 bool
167  std::list<AGAdult>::iterator it;
168  for (it = adults.begin() ; it != adults.end() ; ++it) {
169  if (myCity->statData.workPositions <= 0) {
170  std::cout << "Not enough free work positions in AGHousehold::allocateAdultsWork. Should not happen." << std::endl;
171  return false;
172 
173  } else {
174  it->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions));
175  }
176  }
177  return true;
178 }
179 
180 bool
182  return (RandHelper::rand() < p);
183 }
184 
187  return location;
188 }
189 
190 AGCity*
192  return myCity;
193 }
194 
195 bool
197  return (adults.front().getAge() >= myCity->statData.limitAgeRetirement);
198 }
199 
200 /****************************************************************************/