void AGCity::generatePopulation() { std::vector<AGStreet>::iterator it; int people; nbrCars = 0; int idHouseholds = 0; for (it = streets.begin() ; it != streets.end() ; ++it) { people = it->getPopulation(); while (people > 0) { ++idHouseholds; households.push_back(AGHousehold(&*it, this, idHouseholds)); households.back().generatePeople(); //&statData //households.back().generateCars(statData.carRate); people -= households.back().getPeopleNbr(); } } //people from outside of the city generation: generateIncomingPopulation(); //TEST int nbrSingle = 0; int nbrCouple = 0; int nbrChild = 0; int nbrHH = 0; int workingP = 0; std::list<AGHousehold>::iterator itt; for (itt = households.begin() ; itt != households.end() ; ++itt) { if (itt->getAdultNbr() == 1) { nbrSingle++; if (itt->adults.front().isWorking()) { workingP++; } } if (itt->getAdultNbr() == 2) { nbrCouple += 2; if (itt->adults.front().isWorking()) { workingP++; } if (itt->adults.back().isWorking()) { workingP++; } } nbrChild += itt->getPeopleNbr() - itt->getAdultNbr(); nbrHH++; } //cout << "number hh: " << nbrHH << std::endl; //cout << "number single: " << nbrSingle << std::endl; //cout << "number couple: " << nbrCouple << std::endl; //cout << "number 3 or more: " << nbr3More << std::endl; //cout << "number adults: " << nbrSingle + nbrCouple + nbr3More << std::endl; //cout << "number children: " << nbrChild << std::endl; //cout << "number people: " << nbrSingle + nbrCouple + nbr3More + nbrChild << std::endl; //END TEST std::cout << "--> population: " << std::endl; std::cout << " |-> city households: " << nbrHH << std::endl; std::cout << " |-> city people: " << nbrSingle + nbrCouple + nbrChild << std::endl; std::cout << " |-> city single: " << nbrSingle << " / (in) couple: " << nbrCouple << std::endl; std::cout << " |-> city adults: " << nbrSingle + nbrCouple << std::endl; std::cout << " |-> estimation: " << statData.getPeopleOlderThan(statData.limitAgeChildren) << std::endl; std::cout << " |-> retired: " << statData.getPeopleOlderThan(statData.limitAgeRetirement) << std::endl; std::cout << " |-> city children: " << nbrChild << std::endl; std::cout << " |-> estimation: " << statData.getPeopleYoungerThan(statData.limitAgeChildren) << std::endl; }
void AGCity::generatePopulation() { std::vector<AGStreet>::iterator it; SUMOReal people = 0; nbrCars = 0; unsigned int idHouseholds = 0; std::vector<int> numAdults(statData.households); std::vector<int> numChilds(statData.households); int totalChildrenLeft = statData.inhabitants - statData.getPeopleOlderThan(statData.limitAgeChildren); const SUMOReal retiredProb = statData.getPeopleOlderThan(statData.limitAgeRetirement) / statData.getPeopleOlderThan(statData.limitAgeChildren); for (int i = 0; i < statData.households; i++) { numAdults[i] = 1; numChilds[i] = 0; if (RandHelper::rand() < retiredProb) { numAdults[i] = -numAdults[i]; } else if (totalChildrenLeft > 0) { numChilds[i] = statData.getPoissonsNumberOfChildren(statData.meanNbrChildren); totalChildrenLeft -= numChilds[i]; } } //compensate with adults for too many / missing children const int numSecondPers = statData.getPeopleOlderThan(statData.limitAgeChildren) - statData.households + totalChildrenLeft; for (int i = 0; i < numSecondPers; i++) { unsigned int index = i % numAdults.size(); if (numAdults[index] >= 0) { numAdults[index] += 1; } else { numAdults[index] -= 1; } } for (it = streets.begin(); it != streets.end(); ++it) { people += it->getPopulation(); while (people > 0 && idHouseholds < (unsigned int)numAdults.size()) { size_t i = RandHelper::rand(numAdults.size() - idHouseholds); ++idHouseholds; households.push_back(AGHousehold(&*it, this, idHouseholds)); households.back().generatePeople(abs(numAdults[i]), numChilds[i], numAdults[i] < 0); //&statData //households.back().generateCars(statData.carRate); people -= households.back().getPeopleNbr(); numAdults[i] = numAdults[numAdults.size() - idHouseholds]; numChilds[i] = numChilds[numAdults.size() - idHouseholds]; } } //people from outside of the city generation: generateIncomingPopulation(); //TEST int nbrSingle = 0; int nbrCouple = 0; int nbrChild = 0; int nbrHH = 0; int workingP = 0; std::list<AGHousehold>::iterator itt; for (itt = households.begin(); itt != households.end(); ++itt) { if (itt->getAdultNbr() == 1) { nbrSingle++; if (itt->getAdults().front().isWorking()) { workingP++; } } if (itt->getAdultNbr() == 2) { nbrCouple += 2; if (itt->getAdults().front().isWorking()) { workingP++; } if (itt->getAdults().back().isWorking()) { workingP++; } } nbrChild += itt->getPeopleNbr() - itt->getAdultNbr(); nbrHH++; } //cout << "number hh: " << nbrHH << std::endl; //cout << "number single: " << nbrSingle << std::endl; //cout << "number couple: " << nbrCouple << std::endl; //cout << "number 3 or more: " << nbr3More << std::endl; //cout << "number adults: " << nbrSingle + nbrCouple + nbr3More << std::endl; //cout << "number children: " << nbrChild << std::endl; //cout << "number people: " << nbrSingle + nbrCouple + nbr3More + nbrChild << std::endl; //END TEST std::cout << "--> population: " << std::endl; std::cout << " |-> city households: " << nbrHH << std::endl; std::cout << " |-> city people: " << nbrSingle + nbrCouple + nbrChild << std::endl; std::cout << " |-> city single: " << nbrSingle << " / (in) couple: " << nbrCouple << std::endl; std::cout << " |-> city adults: " << nbrSingle + nbrCouple << std::endl; std::cout << " |-> estimation: " << statData.getPeopleOlderThan(statData.limitAgeChildren) << std::endl; std::cout << " |-> retired: " << statData.getPeopleOlderThan(statData.limitAgeRetirement) << std::endl; std::cout << " |-> city children: " << nbrChild << std::endl; std::cout << " |-> estimation: " << statData.getPeopleYoungerThan(statData.limitAgeChildren) << std::endl; }