Пример #1
0
  /**
   * Used this routine for MeisterEtAl_Heureka_2008 paper, plot of number of deps, arrs by activity
   * type to visualize the time distribution from microcensus.
   */
  public static void analyseInitialTimes(Config config) {

    MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config);
    // initialize scenario with events from a given events file
    // - network
    logger.info("Reading network xml file...");
    new MatsimNetworkReader(scenario).readFile(scenario.getConfig().network().getInputFile());
    logger.info("Reading network xml file...done.");
    // - population
    PersonAlgorithm pa = new PersonAnalyseTimesByActivityType(TIME_BIN_SIZE);
    ArrayList<PersonAlgorithm> plansAlgos = new ArrayList<PersonAlgorithm>();
    plansAlgos.add(pa);

    PopulationImpl matsimAgentPopulation = (PopulationImpl) scenario.getPopulation();
    matsimAgentPopulation.setIsStreaming(true);
    PopulationReader plansReader = new MatsimPopulationReader(scenario);
    plansReader.readFile(scenario.getConfig().plans().getInputFile());
    matsimAgentPopulation.printPlansCount();
    int[][] numDeps = ((PersonAnalyseTimesByActivityType) pa).getNumDeps();
    MyRuns.writeAnArray(numDeps, "output/deptimes.txt");
    int[][] numArrs = ((PersonAnalyseTimesByActivityType) pa).getNumArrs();
    MyRuns.writeAnArray(numArrs, "output/arrtimes.txt");
    int[][] numTraveling = ((PersonAnalyseTimesByActivityType) pa).getNumTraveling();
    MyRuns.writeAnArray(numTraveling, "output/traveling.txt");
  }
Пример #2
0
  public static Population initMatsimAgentPopulation(
      final String inputFilename,
      final boolean isStreaming,
      final ArrayList<PersonAlgorithm> algos,
      MutableScenario scenario) {

    PopulationImpl population = (PopulationImpl) scenario.getPopulation();

    System.out.println("  reading plans xml file... ");
    population.setIsStreaming(isStreaming);

    if (isStreaming) {
      // add plans algos for streaming
      if (algos != null) {
        for (PersonAlgorithm algo : algos) {
          population.addAlgorithm(algo);
        }
      }
    }
    PopulationReader plansReader = new MatsimPopulationReader(scenario);
    plansReader.readFile(inputFilename);
    population.printPlansCount();
    System.out.println("  done.");

    return population;
  }
Пример #3
0
  public void createDilutedPlans(
      final Coord center, final double radius, final String fromFile, final String toFile) {
    final Map<Id<Link>, Link> areaOfInterest = new HashMap<>();

    Network network = this.scenario.getNetwork();

    log.info("extracting aoi:");
    log.info("  center: " + center.getX() + " / " + center.getY());
    log.info("  radius: " + radius);
    for (Link link : network.getLinks().values()) {
      final Node from = link.getFromNode();
      final Node to = link.getToNode();
      if ((CoordUtils.calcDistance(from.getCoord(), center) <= radius)
          || (CoordUtils.calcDistance(to.getCoord(), center) <= radius)) {
        System.out.println("    link " + link.getId().toString());
        areaOfInterest.put(link.getId(), link);
      }
    }
    log.info("  # links in aoi: " + areaOfInterest.size());

    log.info("creating diluted dpopulation:");
    log.info("  input-file:  " + fromFile);
    log.info("  output-file: " + toFile);
    PopulationImpl pop =
        (PopulationImpl)
            ((MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()))
                .getPopulation();
    pop.setIsStreaming(true);

    PopulationWriter writer = new PopulationWriter(pop, this.scenario.getNetwork());
    writer.startStreaming(toFile);

    final PersonIntersectAreaFilter filter =
        new PersonIntersectAreaFilter(writer, areaOfInterest, network);
    filter.setAlternativeAOI(center, radius);
    pop.addAlgorithm(filter);

    new MatsimPopulationReader(new PseudoScenario(this.scenario, pop)).readFile(fromFile);

    writer.closeStreaming();

    pop.printPlansCount();
    log.info("persons in output: " + filter.getCount());
  }
Пример #4
0
  public void createSamplePopulation(
      final String fromFile, final String toFile, final double percentage) {
    PopulationImpl pop =
        (PopulationImpl)
            ((MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()))
                .getPopulation();
    pop.setIsStreaming(true);
    final PopulationWriter plansWriter =
        new PopulationWriter(pop, this.scenario.getNetwork(), percentage);
    plansWriter.startStreaming(toFile);
    pop.addAlgorithm(plansWriter);
    PopulationReader plansReader =
        new MatsimPopulationReader(new PseudoScenario(this.scenario, pop));

    log.info("extracting sample from population:");
    log.info("  input-file:  " + fromFile);
    log.info("  output-file: " + toFile);
    log.info("  sample-size: " + percentage);
    plansReader.readFile(fromFile);
    pop.printPlansCount();
    plansWriter.closeStreaming();
  }