Esempio n. 1
0
  public static void main(String[] args) {
    MutableScenario s = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    s.getConfig().transit().setUseTransit(true);
    s.getConfig().scenario().setUseVehicles(true);

    Vehicles v = s.getTransitVehicles();
    TransitSchedule ts = s.getTransitSchedule();
    PopulationImpl p = (PopulationImpl) s.getPopulation();

    new MatsimNetworkReader(s).readFile(NETWORK);
    new VehicleReaderV1(v).readFile(VEHICLES);
    new TransitScheduleReader(s).readFile(SCHEDULE);
    log.info("build transit router...");
    TransitRouterConfig tRConfig =
        new TransitRouterConfig(
            s.getConfig().planCalcScore(),
            s.getConfig().plansCalcRoute(),
            s.getConfig().transitRouter(),
            s.getConfig().vspExperimental());

    TransitRouterImpl router = new TransitRouterImpl(tRConfig, ts);

    PtRouter ptR = new PtRouter(router);

    p.setIsStreaming(true);
    p.addAlgorithm(ptR);

    log.info("start processing persons...");
    new MatsimPopulationReader(s).readFile(PLANS);

    ptR.close();
  }
Esempio n. 2
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");
  }
Esempio n. 3
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;
  }
Esempio n. 4
0
  public void analyzeModeChainFeasibility(Config config) {

    MutableScenario scenario =
        (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());

    // initialize scenario with events from a given events file
    // - network
    logger.info("Reading network xml file...");
    Network network = scenario.getNetwork();
    new MatsimNetworkReader(scenario).readFile(config.network().getInputFile());
    logger.info("Reading network xml file...done.");

    // - facilities
    logger.info("Reading facilities xml file...");
    ActivityFacilities facilities = scenario.getActivityFacilities();
    new MatsimFacilitiesReader(scenario).parse(config.facilities().getInputFile());
    logger.info("Reading facilities xml file...");

    // - population
    PersonAnalyzeModeChainFeasibility pa =
        new PersonAnalyzeModeChainFeasibility(facilities, network);
    ArrayList<PersonAlgorithm> plansAlgos = new ArrayList<PersonAlgorithm>();
    plansAlgos.add(pa);

    PopulationImpl matsimAgentPopulation = (PopulationImpl) scenario.getPopulation();
    matsimAgentPopulation.setIsStreaming(true);
    matsimAgentPopulation.addAlgorithm(pa);
    PopulationReader plansReader = new MatsimPopulationReader(scenario);
    plansReader.readFile(config.plans().getInputFile());

    logger.info("Number of selected plans which are infeasible: " + pa.getNumInfeasiblePlans());
  }
Esempio n. 5
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());
  }
Esempio n. 6
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();
  }