SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // A household contains the people and cars of the city: roughly represents 00011 // families with their address, cars, adults and possibly children 00012 /****************************************************************************/ 00013 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00014 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00015 // activitygen module 00016 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/) 00017 /****************************************************************************/ 00018 // 00019 // This file is part of SUMO. 00020 // SUMO is free software: you can redistribute it and/or modify 00021 // it under the terms of the GNU General Public License as published by 00022 // the Free Software Foundation, either version 3 of the License, or 00023 // (at your option) any later version. 00024 // 00025 /****************************************************************************/ 00026 00027 00028 // =========================================================================== 00029 // included modules 00030 // =========================================================================== 00031 #ifdef _MSC_VER 00032 #include <windows_config.h> 00033 #else 00034 #include <config.h> 00035 #endif 00036 00037 #include <utils/common/RandHelper.h> 00038 #include "AGHousehold.h" 00039 #include "AGCar.h" 00040 00041 00042 // =========================================================================== 00043 // method definitions 00044 // =========================================================================== 00045 void 00046 AGHousehold::generatePeople() { 00047 AGDataAndStatistics* ds = &(myCity->statData); 00048 //the first adult 00049 AGAdult pers(ds->getRandomPopDistributed(ds->limitAgeChildren, ds->limitEndAge)); 00050 adults.push_back(pers); 00051 00052 //the second adult 00053 if (decisionProba(ds->secondPersProb)) { 00054 if (pers.getAge() < ds->limitAgeRetirement) { 00055 AGAdult pers2(ds->getRandomPopDistributed(ds->limitAgeChildren, ds->limitAgeRetirement)); 00056 adults.push_back(pers2); 00057 } else { 00058 AGAdult pers2(ds->getRandomPopDistributed(ds->limitAgeRetirement, ds->limitEndAge)); 00059 adults.push_back(pers2); 00060 } 00061 } 00062 00063 //Children 00064 if (pers.getAge() < ds->limitAgeRetirement) { 00065 int numChild = ds->getPoissonsNumberOfChildren(ds->meanNbrChildren); 00066 while (numChild > 0) { 00067 AGChild chl(ds->getRandomPopDistributed(0, ds->limitAgeChildren)); 00068 children.push_back(chl); 00069 --numChild; 00070 } 00071 } 00072 } 00073 00074 void 00075 AGHousehold::generateCars(SUMOReal rate) { 00076 int peopleInNeed = static_cast<int>(adults.size()) - static_cast<int>(cars.size()); 00077 while (peopleInNeed > 0) { 00078 if (decisionProba(rate)) { 00079 addACar(); 00080 } 00081 --peopleInNeed; 00082 } 00083 } 00084 00085 void 00086 AGHousehold::addACar() { 00087 int numCar = static_cast<int>(cars.size() + 1); 00088 cars.push_back(AGCar(idHH, numCar)); 00089 } 00090 00091 int 00092 AGHousehold::getCarNbr() { 00093 return static_cast<int>(cars.size()); 00094 } 00095 00096 int 00097 AGHousehold::getPeopleNbr() { 00098 return static_cast<int>(adults.size() + children.size()); 00099 } 00100 00101 int 00102 AGHousehold::getAdultNbr() { 00103 return static_cast<int>(adults.size()); 00104 } 00105 00106 bool 00107 AGHousehold::isCloseFromPubTransport(std::list<AGPosition> *pubTransport) { 00108 SUMOReal distToPT = location.minDistanceTo(*pubTransport); 00109 if (distToPT > myCity->statData.maxFootDistance) { 00110 return false; 00111 } 00112 return true; 00113 } 00114 00115 bool 00116 AGHousehold::isCloseFromPubTransport(std::map<int, AGPosition> *pubTransport) { 00117 SUMOReal distToPT = location.minDistanceTo(*pubTransport); 00118 if (distToPT > myCity->statData.maxFootDistance) { 00119 return false; 00120 } 00121 return true; 00122 } 00123 00124 void 00125 AGHousehold::regenerate() { 00126 //only allocation of work or school to people will change 00127 std::list<AGChild>::iterator itC; 00128 std::list<AGAdult>::iterator itA; 00129 for (itC = children.begin() ; itC != children.end() ; ++itC) { 00130 if (itC->haveASchool()) { 00131 if (itC->leaveSchool()) { 00132 itC->alocateASchool(&(myCity->schools), getPosition()); 00133 } 00134 } else { 00135 itC->alocateASchool(&(myCity->schools), getPosition()); 00136 } 00137 } 00138 for (itA = adults.begin() ; itA != adults.end() ; ++itA) { 00139 if (itA->isWorking()) { 00140 itA->resignFromWorkPosition(); 00141 } 00142 00143 if (myCity->statData.workPositions > 0) { 00144 itA->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions)); 00145 00146 } else { 00147 std::cout << "Not enough work positions in AGHousehold::regenerate. Should not happen!" << std::endl; 00148 } 00149 } 00150 } 00151 00152 bool 00153 AGHousehold::allocateChildrenSchool() { 00154 std::list<AGChild>::iterator it; 00155 bool oneRemainsAtHome = false; 00156 00157 for (it = children.begin() ; it != children.end() ; ++it) { 00158 if (!it->alocateASchool(&(myCity->schools), location)) { 00159 oneRemainsAtHome = true; 00160 } 00161 } 00162 return !oneRemainsAtHome; 00163 } 00164 00165 bool 00166 AGHousehold::allocateAdultsWork() { 00167 std::list<AGAdult>::iterator it; 00168 for (it = adults.begin() ; it != adults.end() ; ++it) { 00169 if (myCity->statData.workPositions <= 0) { 00170 std::cout << "Not enough free work positions in AGHousehold::allocateAdultsWork. Should not happen." << std::endl; 00171 return false; 00172 00173 } else { 00174 it->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions)); 00175 } 00176 } 00177 return true; 00178 } 00179 00180 bool 00181 AGHousehold::decisionProba(SUMOReal p) { 00182 return (RandHelper::rand() < p); 00183 } 00184 00185 AGPosition 00186 AGHousehold::getPosition() { 00187 return location; 00188 } 00189 00190 AGCity* 00191 AGHousehold::getTheCity() { 00192 return myCity; 00193 } 00194 00195 bool 00196 AGHousehold::retiredHouseholders() { 00197 return (adults.front().getAge() >= myCity->statData.limitAgeRetirement); 00198 } 00199 00200 /****************************************************************************/