Beispiel #1
0
 public void addHousehold(Household household) {
   if (this.households.get(household.getId()) == null) {
     this.households.put(household.getId(), household);
   } else {
     throw new RuntimeException("Household " + household.getId() + " already exists. Aborting...");
   }
 }
  public static void main(String[] args) {
    NewWorker w1, w2, w3, w4, w5;
    Student s1, s2;
    Household myFamily;
    s1 = new Student("Edward Teller", "Physics");
    s2 = new Student("Liz Powell", "Computer Science");

    w1 = new NewWorker("Robert William Hunter", "23/10/2005", 35000.00);
    w2 = new NewWorker("Mary Jane Hull", "06/09/2007");

    w2.setSalary(40000.00);

    myFamily = new Household(5);

    myFamily.insertNewHouseholdMember(s1);
    myFamily.insertNewHouseholdMember(s2);
    myFamily.insertNewHouseholdMember(w1);
    myFamily.insertNewHouseholdMember(w2);

    w1.setSpouse(w2);
    w2.setSpouse(w1);

    System.out.println("Total family income of Robert and Mary " + w1.getFamilyIncome());
    System.out.println("\nDescription of the family is\n" + myFamily.toString());
  }
Beispiel #3
0
 public Vehicles getVehiclesOfHHs() {
   this.vehiclesOfHHs = new Vehicles();
   for (Household hh : this.households.values()) {
     for (Vehicle veh : hh.getVehInHH().getVehicles().values()) {
       this.vehiclesOfHHs.addVehicle(veh);
     }
   }
   return this.vehiclesOfHHs;
 }
Beispiel #4
0
  private void generateAutoOwnership() {
    // select number of cars for every household

    JobDataManager jobData = new JobDataManager(rb);
    jobData.calculateJobDensityByZone();
    AutoOwnershipModel ao = new AutoOwnershipModel(rb); // calculate auto-ownership probabilities
    for (Household hh : Household.getHouseholdArray()) {
      int autos = ao.simulateAutoOwnership(hh);
      hh.setAutos(autos);
    }
  }
Beispiel #5
0
  private void definePersonRolesInHousehold(Household hh, int[] relShp) {
    // define roles as single, married or child

    Person[] pp = hh.getPersons();
    HashMap<Integer, Integer> coupleCounter = new HashMap<>();
    coupleCounter.put(1, 0);
    coupleCounter.put(2, 0);
    for (int i = 0; i < pp.length; i++) {
      //      Householder      husband/wife  unmarried Partner
      if (relShp[i] == 1 || relShp[i] == 2 || relShp[i] == 19) {
        int cnt = coupleCounter.get(pp[i].getGender()) + 1;
        coupleCounter.put(pp[i].getGender(), cnt);
      }
    }
    int numberOfCouples = Math.min(coupleCounter.get(1), coupleCounter.get(2));
    int[] marriedPersons = new int[] {numberOfCouples, numberOfCouples};
    if (numberOfCouples > 0) {
      pp[0].setRole(PersonRole.married);
      marriedPersons[pp[0].getGender() - 1] -= 1;
    } else pp[0].setRole(PersonRole.single);

    for (int i = 1; i < pp.length; i++) {
      if ((relShp[i] == 2 || relShp[i] == 19) && marriedPersons[pp[i].getGender() - 1] > 0) {
        pp[i].setRole(PersonRole.married);
        marriedPersons[pp[i].getGender() - 1] -= 1;
        //   natural child     adopted child        step child        grandchild       foster child
      } else if (relShp[i] == 3
          || relShp[i] == 4
          || relShp[i] == 5
          || relShp[i] == 8
          || relShp[i] == 20) pp[i].setRole(PersonRole.child);
      else pp[i].setRole(PersonRole.single);
    }
  }
Beispiel #6
0
  public void runSP() {
    // main method to run the synthetic population generator

    if (!ResourceUtil.getBooleanProperty(rb, PROPERTIES_RUN_SP)) return;

    logger.info("Generating synthetic populations of household/persons, dwellings and jobs");
    identifyUniquePUMAzones();
    readControlTotals();
    createJobs();
    processPums();
    generateAutoOwnership();
    //        summarizeData.summarizeAutoOwnershipByCounty();
    addVacantDwellings();
    if (ResourceUtil.getBooleanProperty(rb, PROPERTIES_VALIDATE_SYNTH_POP)) validateHHandDD();
    logger.info("  Total number of households created " + Household.getHouseholdCount());
    logger.info("  Total number of persons created    " + Person.getPersonCount());
    logger.info("  Total number of dwellings created  " + Dwelling.getDwellingCount());
    logger.info("  Total number of jobs created       " + Job.getJobCount());
    calculateVacancyRate();
    if (!jobErrorCounter.isEmpty()) {
      logger.warn(
          "  Could not find sufficient number of jobs in these PUMA zones (note that most of these "
              + "zones are outside the MSTM area):");
      Set<Integer> list = jobErrorCounter.keySet();
      for (Integer puma : list)
        logger.warn("  -> " + puma + " is missing " + jobErrorCounter.get(puma) + " jobs.");
    } else {
      logger.info("  Succeeded in assigning job to every worker.");
    }
    //        summarizeVacantJobsByRegion();
    //        summarizeByPersonRelationship();
    summarizeData.writeOutSyntheticPopulation(rb, SiloUtil.getBaseYear());
    //        writeSyntheticPopulation();
    logger.info("  Completed generation of synthetic population");
  }
Beispiel #7
0
  private void createHouseholds() {
    // create households
    households.clear();
    householdsField.clear();
    householdsField.setMBR(highSchoolZones.getMBR());

    Envelope bounds = highSchoolZones.getMBR();

    // this is needed because
    Geometry exemplar = ((MasonGeometry) highSchoolZones.getGeometries().get(0)).getGeometry();

    for (int i = 0; i < numHouseholds; i++) {
      Household h = new Household(this);
      households.add(h);
      Coordinate coord;
      do {
        coord = getRandomCoordinate(bounds);
      } while (!highSchoolZones.isCovered(coord));

      Point pt = GeometryFactory.createPointFromInternalCoord(coord, exemplar);
      h.location = pt;
      householdsField.addGeometry(new MasonGeometry(pt));
    }
  }
Beispiel #8
0
  public Households filterHouseholdsWithPopulation(
      final Households households, final ObjectAttributes householdAttributes) {
    Households filteredHouseholds = new HouseholdsImpl();

    for (Household household : households.getHouseholds().values()) {
      Set<Id<Person>> personIdsToRemove = new HashSet<>();
      for (Id<Person> personId : household.getMemberIds()) {
        if (!filteredAgents.keySet().contains(personId)) {
          personIdsToRemove.add(personId);
        }
      }
      for (Id<Person> personId : personIdsToRemove) {
        household.getMemberIds().remove(personId);
      }
      if (!household.getMemberIds().isEmpty()) {
        filteredHouseholds.getHouseholds().put(household.getId(), household);
      } else {
        householdAttributes.removeAllAttributes(household.getId().toString());
      }
    }

    return filteredHouseholds;
  }
Beispiel #9
0
  private void savePumsRecord(
      int pumaZone,
      int weight,
      int hhSize,
      int pumsDdType,
      int bedRooms,
      int autos,
      int rent,
      int mortgage,
      int quality,
      int yearBuilt,
      int[] gender,
      int[] age,
      Race[] race,
      int[] relShp,
      int[] occupation,
      int[] workPumaZone,
      int[] workState,
      int[] income) {
    // add record to PUMS record storage

    if (pumsDdType == 10 || pumsDdType == -999)
      return; // skip this record if PUMS dwelling type is 10 (Boat, RV, Van) or -999 (unknown)
    DwellingType ddType = translateDwellingType(pumsDdType);
    for (int count = 0; count < weight; count++) {
      int newDdId = RealEstateDataManager.getNextDwellingId();
      int newHhId;
      if (gender[0] == 0) newHhId = -1;
      else newHhId = HouseholdDataManager.getNextHouseholdId();
      int taz = locateDwelling(pumaZone);

      int price = getDwellingPrice(rent, mortgage);
      int selectedYear = selectYear(yearBuilt);
      new Dwelling(newDdId, taz, newHhId, ddType, bedRooms, quality, price, 0, selectedYear);
      if (gender[0] == 0) return; // this dwelling is empty, do not create household
      Household hh = new Household(newHhId, newDdId, taz, hhSize, autos);
      for (int s = 0; s < hhSize; s++) {
        int newPpId = HouseholdDataManager.getNextPersonId();

        int occ = translateOccupation(occupation[s]);
        int workplace = -1;
        if (occ == 1) {

          if (workPumaZone[s] == 0 || workState[s] == 0) {
            // no workplace PUMA provided by PUMS (person did not go to work during week interviewed
            // because of vacation, leave, etc.)
            workplace =
                selectWorkplaceByTripLengthFrequencyDistribution(
                    workPumaZone[s], workState[s], taz);
          } else {
            // workplace PUMA provided by PUMS
            // workplace = selectWorkplace(workPumaZone[s], workState[s]);
            // update: As the distribution of requested workplaces according to PUMS is very
            // different from the available MSTM employment data all jobs are chosen based on trip
            // length frequency distributions
            workplace =
                selectWorkplaceByTripLengthFrequencyDistribution(
                    workPumaZone[s], workState[s], taz);
          }
          if (workplace != -2) {
            Job.getJobFromId(workplace)
                .setWorkerID(newPpId); // -2 for jobs outside of the study area
          }
        }
        Person pp =
            new Person(newPpId, newHhId, age[s], gender[s], race[s], occ, workplace, income[s]);
        hh.addPersonForInitialSetup(pp);
      }
      hh.setType();
      hh.setHouseholdRace();
      definePersonRolesInHousehold(hh, relShp);
      // trace persons, households and dwellings
      for (Person pp : hh.getPersons())
        if (pp.getId() == SiloUtil.trackPp) {
          SiloUtil.trackWriter.println("Generated person with following attributes:");
          Person.getPersonFromId(pp.getId()).logAttributes(SiloUtil.trackWriter);
        }
      if (newHhId == SiloUtil.trackHh) {
        SiloUtil.trackWriter.println("Generated household with following attributes:");
        Household.getHouseholdFromId(newHhId).logAttributes(SiloUtil.trackWriter);
      }
      if (newDdId == SiloUtil.trackDd) {
        SiloUtil.trackWriter.println("Generated dwelling with following attributes:");
        Dwelling.getDwellingFromId(newDdId).logAttributes(SiloUtil.trackWriter);
      }
    }
  }