コード例 #1
0
  @Override
  public void readFacilities(ActivityFacilitiesImpl facilities) {
    log.fatal("does not work; see javadoc of class.  Aborting ..." + this);
    System.exit(-1);

    // (these are simply defined as those entities that have x/y coordinates in urbansim)
    try {
      BufferedReader reader =
          IOUtils.getBufferedReader(Matsim4Urbansim.PATH_TO_OPUS_MATSIM + "tmp/gridcells.tab");

      String header = reader.readLine();
      Map<String, Integer> idxFromKey = Utils.createIdxFromKey(header, null);

      String line = reader.readLine();
      while (line != null) {

        String[] parts = line.split("[\t]+");

        int idx_id = idxFromKey.get("grid_id:i4");
        Id<ActivityFacility> id = Id.create(parts[idx_id], ActivityFacility.class);

        int idx_x = idxFromKey.get("relative_x:i4");
        int idx_y = idxFromKey.get("relative_y:i4");
        Coord coord = new Coord(Double.parseDouble(parts[idx_x]), Double.parseDouble(parts[idx_y]));

        ActivityFacilityImpl facility = facilities.createAndAddFacility(id, coord);
        facility.setDesc("urbansim location");

        line = reader.readLine();
      }

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  void readPersonsFromHouseholds(
      Population population, ActivityFacilitiesImpl facilities, double fraction) {
    log.fatal("does not work; see javadoc of class.  Aborting ..." + this);
    System.exit(-1);
    try {
      BufferedReader reader =
          IOUtils.getBufferedReader(Matsim4Urbansim.PATH_TO_OPUS_MATSIM + "tmp/households.tab");

      String header = reader.readLine();
      Map<String, Integer> idxFromKey = Utils.createIdxFromKey(header, null);

      String line = reader.readLine();
      while (line != null) {
        String[] parts = line.split("[\t\n]+");

        if (Math.random() > fraction) {
          line = reader.readLine(); // next line
          continue;
        }

        int idx = idxFromKey.get("persons:i4");
        int nPersons = Integer.parseInt(parts[idx]);

        idx = idxFromKey.get("workers:i4");
        int nWorkers = Integer.parseInt(parts[idx]);

        idx = idxFromKey.get("household_id:i4");
        Id<HH> hhId = Id.create(parts[idx], HH.class);

        idx = idxFromKey.get("grid_id:i4");
        Id<Location> homeGridId = Id.create(parts[idx], Location.class);
        ActivityFacility homeLocation =
            facilities.getFacilities().get(Id.create(homeGridId, ActivityFacility.class));
        if (homeLocation == null) {
          log.warn("no home location; hhId: " + hhId.toString());
          line = reader.readLine(); // next line
          continue;
        }
        Coord homeCoord = homeLocation.getCoord();

        // generate persons only after it's clear that they have a home location:
        for (int ii = 0; ii < nPersons; ii++) {
          Id<Person> personId = Id.create(personCnt, Person.class);
          Person person = PersonImpl.createPerson(personId);
          personCnt++;
          if (personCnt > 10) {
            log.error("hack");
            return;
          }

          population.addPerson(person);

          PlanImpl plan = PersonUtils.createAndAddPlan(person, true);
          Utils.makeHomePlan(plan, homeCoord);

          if (ii < nWorkers) {
            PersonUtils.setEmployed(person, Boolean.TRUE);
          } else {
            PersonUtils.setEmployed(person, Boolean.FALSE);
          }
        }
        line = reader.readLine(); // next line
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      System.exit(-1);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }