Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others. 4 : // activitygen module 5 : // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/) 6 : // This program and the accompanying materials are made available under the 7 : // terms of the Eclipse Public License 2.0 which is available at 8 : // https://www.eclipse.org/legal/epl-2.0/ 9 : // This Source Code may also be made available under the following Secondary 10 : // Licenses when the conditions for such availability set forth in the Eclipse 11 : // Public License 2.0 are satisfied: GNU General Public License, version 2 12 : // or later which is available at 13 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 14 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 15 : /****************************************************************************/ 16 : /// @file AGHousehold.cpp 17 : /// @author Piotr Woznica 18 : /// @author Daniel Krajzewicz 19 : /// @author Michael Behrisch 20 : /// @author Walter Bamberger 21 : /// @date July 2010 22 : /// 23 : // A household contains the people and cars of the city: roughly represents 24 : // families with their address, cars, adults and possibly children 25 : /****************************************************************************/ 26 : #include <config.h> 27 : 28 : #include <utils/common/RandHelper.h> 29 : #include "AGCar.h" 30 : #include "AGChild.h" 31 : #include "AGCity.h" 32 : #include "AGDataAndStatistics.h" 33 : #include "AGHousehold.h" 34 : 35 : 36 : // =========================================================================== 37 : // method definitions 38 : // =========================================================================== 39 : void 40 2005 : AGHousehold::generatePeople(int numAdults, int numChilds, bool firstRetired) { 41 2005 : AGDataAndStatistics* ds = &(myCity->statData); 42 : //the first adult 43 2005 : AGAdult pers(ds->getRandomPopDistributed(ds->limitAgeChildren, ds->limitEndAge)); 44 2005 : if (firstRetired) { 45 0 : pers = AGAdult(ds->getRandomPopDistributed(ds->limitAgeRetirement, ds->limitEndAge)); 46 : } 47 2005 : myAdults.push_back(pers); 48 : //further adults 49 3245 : while (static_cast<int>(myAdults.size()) < numAdults) { 50 1240 : if (firstRetired) { 51 0 : AGAdult pers2(ds->getRandomPopDistributed(ds->limitAgeRetirement, ds->limitEndAge)); 52 : myAdults.push_back(pers2); 53 : } else { 54 1240 : AGAdult pers2(ds->getRandomPopDistributed(ds->limitAgeChildren, ds->limitAgeRetirement)); 55 : myAdults.push_back(pers2); 56 : } 57 : } 58 : //Children 59 2765 : while (static_cast<int>(myChildren.size()) < numChilds) { 60 760 : AGChild chl(ds->getRandomPopDistributed(0, ds->limitAgeChildren)); 61 760 : myChildren.push_back(chl); 62 : } 63 2005 : } 64 : 65 : void 66 2005 : AGHousehold::generateCars(double rate) { 67 2005 : int peopleInNeed = static_cast<int>(myAdults.size()) - static_cast<int>(myCars.size()); 68 5001 : while (peopleInNeed > 0) { 69 2996 : if (RandHelper::rand() < rate) { 70 1596 : addACar(); 71 : } 72 2996 : --peopleInNeed; 73 : } 74 2005 : } 75 : 76 : void 77 1845 : AGHousehold::addACar() { 78 1845 : int numCar = static_cast<int>(myCars.size() + 1); 79 1845 : myCars.push_back(AGCar(myId, numCar)); 80 1845 : } 81 : 82 : int 83 12474 : AGHousehold::getCarNbr() { 84 12474 : return static_cast<int>(myCars.size()); 85 : } 86 : 87 : int 88 5082 : AGHousehold::getPeopleNbr() { 89 5082 : return static_cast<int>(myAdults.size() + myChildren.size()); 90 : } 91 : 92 : int 93 12538 : AGHousehold::getAdultNbr() { 94 12538 : return static_cast<int>(myAdults.size()); 95 : } 96 : 97 : const std::list<AGAdult>& 98 17749 : AGHousehold::getAdults() const { 99 17749 : return myAdults; 100 : } 101 : 102 : const std::list<AGChild>& 103 3582 : AGHousehold::getChildren() const { 104 3582 : return myChildren; 105 : } 106 : 107 : const std::list<AGCar>& 108 2220 : AGHousehold::getCars() const { 109 2220 : return myCars; 110 : } 111 : 112 : bool 113 0 : AGHousehold::isCloseFromPubTransport(std::list<AGPosition>* pubTransport) { 114 0 : double distToPT = myLocation.minDistanceTo(*pubTransport); 115 0 : if (distToPT > myCity->statData.maxFootDistance) { 116 0 : return false; 117 : } 118 : return true; 119 : } 120 : 121 : bool 122 2005 : AGHousehold::isCloseFromPubTransport(std::map<int, AGPosition>* pubTransport) { 123 2005 : double distToPT = myLocation.minDistanceTo(*pubTransport); 124 2005 : if (distToPT > myCity->statData.maxFootDistance) { 125 249 : return false; 126 : } 127 : return true; 128 : } 129 : 130 : void 131 0 : AGHousehold::regenerate() { 132 : //only allocation of work or school to people will change 133 : std::list<AGChild>::iterator itC; 134 : std::list<AGAdult>::iterator itA; 135 0 : for (itC = myChildren.begin(); itC != myChildren.end(); ++itC) { 136 0 : if (itC->haveASchool()) { 137 0 : if (itC->leaveSchool()) { 138 0 : itC->allocateASchool(&(myCity->schools), getPosition()); 139 : } 140 : } else { 141 0 : itC->allocateASchool(&(myCity->schools), getPosition()); 142 : } 143 : } 144 0 : for (itA = myAdults.begin(); itA != myAdults.end(); ++itA) { 145 0 : if (itA->isWorking()) { 146 0 : itA->resignFromWorkPosition(); 147 : } 148 : 149 0 : if (myCity->statData.workPositions > 0) { 150 0 : itA->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions)); 151 : 152 : } else { 153 : std::cout << "Not enough work positions in AGHousehold::regenerate. Should not happen!" << std::endl; 154 : } 155 : } 156 0 : } 157 : 158 : bool 159 2005 : AGHousehold::allocateChildrenSchool() { 160 : std::list<AGChild>::iterator it; 161 : bool oneRemainsAtHome = false; 162 : 163 2765 : for (it = myChildren.begin(); it != myChildren.end(); ++it) { 164 760 : if (!it->allocateASchool(&(myCity->schools), myLocation)) { 165 : oneRemainsAtHome = true; 166 : } 167 : } 168 2005 : return !oneRemainsAtHome; 169 : } 170 : 171 : bool 172 1425 : AGHousehold::allocateAdultsWork() { 173 : std::list<AGAdult>::iterator it; 174 3717 : for (it = myAdults.begin(); it != myAdults.end(); ++it) { 175 2292 : if (myCity->statData.workPositions <= 0) { 176 : std::cout << "Not enough free work positions in AGHousehold::allocateAdultsWork. Should not happen." << std::endl; 177 0 : return false; 178 : 179 : } else { 180 2292 : it->tryToWork(1 - myCity->statData.unemployement, &(myCity->workPositions)); 181 : } 182 : } 183 : return true; 184 : } 185 : 186 : AGPosition 187 13272 : AGHousehold::getPosition() { 188 13272 : return myLocation; 189 : } 190 : 191 : AGCity* 192 327 : AGHousehold::getTheCity() { 193 327 : return myCity; 194 : } 195 : 196 : bool 197 2005 : AGHousehold::retiredHouseholders() { 198 2005 : return (myAdults.front().getAge() >= myCity->statData.limitAgeRetirement); 199 : } 200 : 201 : 202 : /****************************************************************************/