SUMO - Simulation of Urban MObility

AGHousehold.cpp

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