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();
  }
  @Test
  public void test_RunTutorial() {
    Config config = this.utils.loadConfig("test/scenarios/pt-tutorial/config.xml");
    config.planCalcScore().setWriteExperiencedPlans(true);
    config.controler().setLastIteration(0);
    config.plans().setInputFile("test/scenarios/pt-tutorial/population2.xml");
    Controler controler = new Controler(config);
    controler
        .getConfig()
        .controler()
        .setOverwriteFileSetting(
            OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles);
    controler.getConfig().controler().setCreateGraphs(false);
    controler.run();

    MutableScenario s = (MutableScenario) controler.getScenario();
    Assert.assertNotNull(s.getTransitSchedule());
    Assert.assertEquals(4, s.getTransitSchedule().getFacilities().size());
    Assert.assertEquals(1, s.getTransitSchedule().getTransitLines().size());
  }
  public static void runEventsProcessing(Properties properties) {
    boolean isTransit = false;
    MutableScenario scenario =
        (MutableScenario)
            ScenarioUtils.createScenario(
                ConfigUtils.loadConfig(properties.get("configFile").toString()));
    scenario.getConfig().transit().setUseTransit(true);
    if (!properties.get("transitScheduleFile").toString().equals("")) {
      new TransitScheduleReader(scenario)
          .readFile(properties.get("transitScheduleFile").toString());
      isTransit = true;
    }
    new MatsimNetworkReader(scenario).readFile(properties.get("networkFile").toString());

    EventsManager eventsManager = EventsUtils.createEventsManager();
    EventsToTravelDiaries test;
    // if(linkTrafficComponent.isSelected()){
    // test = new EventsToPlanElements(
    // scenario.getTransitSchedule(), scenario.getNetwork(),
    // scenario.getConfig(),new File(postgresPropertiesComponent.getText())
    // ,tableSuffixComponent.getText());
    // }else{
    if (isTransit) {
      test =
          new EventsToTravelDiaries(
              scenario.getTransitSchedule(), scenario.getNetwork(), scenario.getConfig());

    } else {
      test = new EventsToTravelDiaries(scenario);
    }
    // }
    eventsManager.addHandler(test);
    new MatsimEventsReader(eventsManager).readFile(properties.get("eventsFile").toString());

    try {

      test.writeSimulationResultsToTabSeparated(
          properties.get("outputPath").toString(), properties.get("tableSuffix").toString());

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    System.out.println("Number of stuck vehicles/passengers: " + test.getStuck());
  }