public void buildPopulation() { if (householdMap.size() == 0 || personMap.size() == 0) { throw new RuntimeException("Either the househols or persons are of size ZERO!"); } LOG.info("Checking that each person has an associated household in the map..."); for (Id<Person> i : personMap.keySet()) { String s = i.toString().split("_")[0]; if (!householdMap.containsKey(Id.create(s, Household.class))) { LOG.warn("Could not find household " + s); } } LOG.info("Done checking person-household match."); this.households = new HouseholdsImpl(); HouseholdsFactory hhf = households.getFactory(); Population population = sc.getPopulation(); PopulationFactoryImpl pf = (PopulationFactoryImpl) population.getFactory(); for (Id<Person> pid : personMap.keySet()) { String[] sa = personMap.get(pid).split(","); String quarterType = sa[0]; int age = Integer.parseInt(sa[1]); String gender = sa[2].equalsIgnoreCase("Male") ? "m" : "f"; String relationship = sa[3]; String race = sa[4]; String school = sa[5]; boolean employment = sa[6].equalsIgnoreCase("Yes") ? true : false; String mainPlaceOfWork = sa[7]; String modeToMain = sa[8]; Double income = Double.parseDouble(sa[9]); Person person = pf.createPerson(pid); PersonUtils.setAge(person, age); PersonUtils.setSex(person, gender); PersonUtils.setEmployed(person, employment); personAttributes.putAttribute(pid.toString(), "quarterType", quarterType); personAttributes.putAttribute(pid.toString(), "relationship", relationship); personAttributes.putAttribute(pid.toString(), "race", race); personAttributes.putAttribute(pid.toString(), "school", school); personAttributes.putAttribute(pid.toString(), "mainPlaceOfWork", mainPlaceOfWork); personAttributes.putAttribute(pid.toString(), "modeToMain", modeToMain); personAttributes.putAttribute(pid.toString(), "income", income); population.addPerson(person); /* Add to household */ Id<Household> hid = Id.create(pid.toString().split("_")[0], Household.class); if (!this.households.getHouseholds().containsKey(hid)) { /* Household data */ String[] hsa = householdMap.get(hid).split(","); int hhSize = Integer.parseInt(hsa[0]); String dwellingType = hsa[1]; String hhPopulation = hsa[2]; String incomeString = hsa[3]; Income hhIncome = null; if (!incomeString.equalsIgnoreCase("Unknown")) { hhIncome = hhf.createIncome(Double.parseDouble(hsa[3]), IncomePeriod.year); } Household hh = hhf.createHousehold(hid); hh.setIncome(hhIncome); householdAttributes.putAttribute(hid.toString(), "dwellingType", dwellingType); householdAttributes.putAttribute(hid.toString(), "householdSize", hhSize); householdAttributes.putAttribute(hid.toString(), "population", hhPopulation); /* Geography data */ String[] gsa = geographyMap.get(hid).split(","); String municipalCode = gsa[0]; String municipalName = gsa[1]; String magisterialCode = gsa[2]; String magisterialName = gsa[3]; String districtCode = gsa[4]; String districtName = gsa[5]; String provinceCode = gsa[6]; String provinceName = gsa[7]; String eaType = gsa[8]; householdAttributes.putAttribute(hid.toString(), "municipalCode", municipalCode); householdAttributes.putAttribute( hid.toString(), "municipalName", correctCase(municipalName)); householdAttributes.putAttribute(hid.toString(), "magisterialCode", magisterialCode); householdAttributes.putAttribute( hid.toString(), "magisterialName", correctCase(magisterialName)); householdAttributes.putAttribute(hid.toString(), "districtCode", districtCode); householdAttributes.putAttribute(hid.toString(), "districtName", correctCase(districtName)); householdAttributes.putAttribute(hid.toString(), "provinceCode", provinceCode); householdAttributes.putAttribute(hid.toString(), "provinceName", correctCase(provinceName)); householdAttributes.putAttribute(hid.toString(), "eaType", eaType); this.households.getHouseholds().put(hid, hh); } this.households.getHouseholds().get(hid).getMemberIds().add(pid); } /* Validate: */ LOG.info("================================================================"); LOG.info("Validating the population and households"); LOG.info("----------------------------------------------------------------"); LOG.info("Person map: " + personMap.size()); LOG.info("Household map: " + householdMap.size()); LOG.info("----------------------------------------------------------------"); LOG.info("Population size: " + sc.getPopulation().getPersons().size()); LOG.info("Number of households: " + households.getHouseholds().size()); LOG.info("================================================================"); }