Пример #1
0
  /*
   * Reads the population from the plans file.
   */
  @Deprecated // use centralized infrastructure
  public static Scenario readScenario(
      String plansFile, String networkFile, String facilititiesPath) {
    ScenarioImpl sc = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());

    sc.getConfig().setParam("plans", "inputPlansFile", plansFile);
    sc.getConfig().setParam("network", "inputNetworkFile", networkFile);
    sc.getConfig().setParam("facilities", "inputFacilitiesFile", facilititiesPath);

    ScenarioUtils.loadScenario(sc);

    return sc;
  }
  /**
   * Preparing hot start: Copying recent matsim plans file to a specified location (Matsim config).
   * Matsim will check this location for plans file on run and activates hot start if the plans file
   * is there
   */
  public static void prepareHotStart(ScenarioImpl scenario) {

    M4UControlerConfigModuleV3 module =
        ConfigurationUtils.getMATSim4UrbaSimControlerConfigModule(scenario);
    UrbanSimParameterConfigModuleV3 uspModule =
        M4UConfigUtils.getUrbanSimParameterConfigAndPossiblyConvert(scenario.getConfig());

    String hotStartFile = module.getHotStartPlansFileLocation().trim();
    if (exists(hotStartFile)) {

      String plansFile =
          uspModule.getMATSim4OpusOutput() + InternalConstants.GENERATED_PLANS_FILE_NAME;
      try {
        log.info("Preparing hot start for next MATSim run ...");
        FileCopy.fileCopy(new File(plansFile), new File(hotStartFile));
      } catch (Exception e) {
        log.error("Error while copying plans file, i. e. hot start will not work!");
        e.printStackTrace();
      }

      log.info("Hot start preparation successful!");
    } else {
      log.info("can not prepare hotStart. hotstart-file does not exist: " + hotStartFile);
    }
  }
Пример #3
0
  public static void runEventsProcessing(Properties properties) {
    boolean isTransit = false;
    ScenarioImpl scenario =
        (ScenarioImpl)
            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());
  }
Пример #4
0
  /*
   * Reads the network from the network file.
   */
  @Deprecated // use centralized infrastructure
  public static Network readNetwork(String networkFile) {
    ScenarioImpl sc = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());

    sc.getConfig().setParam("network", "inputNetworkFile", networkFile);

    ScenarioUtils.loadScenario(sc);

    return sc.getNetwork();
  }
Пример #5
0
  /**
   * TODO: write test.
   *
   * @param persons
   * @param outputPlansFileName
   * @param network
   */
  public static void writePersons(
      Collection<? extends Person> persons,
      String outputPlansFileName,
      Network network,
      ScenarioImpl scenario) {
    PopulationWriter popWriter =
        new PopulationWriter(
            PopulationUtils.createPopulation(scenario.getConfig(), scenario.getNetwork()), network);
    popWriter.writeStartPlans(outputPlansFileName);

    for (Person person : persons) {
      popWriter.writePerson(person);
    }

    popWriter.writeEndPlans();
  }
Пример #6
0
  public static void main(String[] args) {
    String netfile = null;
    String outputFileLs = null;
    String outputFileP = null;

    if (args.length == 0) {
      netfile =
          "d:\\Berlin\\berlin-fggeoinfo\\30_Run_20_percent\\20101005_run777_778\\network_modified_20100806_added_BBI_AS_cl.xml.gz";
      //		String netfile = "./test/scenarios/berlin/network.xml.gz";
      EventsCompareConfig.eventsFileOne = "E:/run778/output/ITERS/it.900/run778.900.events.txt";
      EventsCompareConfig.eventsFileTwo = "E:/run777/output/ITERS/it.900/run777.900.events.txt";

      outputFileLs = "e:\\temp\\networkLs_abs.shp";
      outputFileP = "e:\\temp\\networkP_abs.shp";
    } else if (args.length == 3) {
      netfile = args[0];
      outputFileLs = args[1];
      outputFileP = args[2];
    } else {
      log.error("Arguments cannot be interpreted.  Aborting ...");
      System.exit(-1);
    }

    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    scenario.getConfig().global().setCoordinateSystem("DHDN_GK4");

    log.info("loading network from " + netfile);
    final Network network = scenario.getNetwork();
    new MatsimNetworkReader(scenario).readFile(netfile);
    log.info("done.");

    FeatureGeneratorBuilderImpl builder = new FeatureGeneratorBuilderImpl(network, "DHDN_GK4");
    //		builder.setFeatureGeneratorPrototype(CountVehOnLinksStringBasedFeatureGenerator.class);
    builder.setFeatureGeneratorPrototype(CountVehOnLinksStringBasedFeatureGenerator.class);
    builder.setWidthCoefficient(0.5);
    builder.setWidthCalculatorPrototype(LanesBasedWidthCalculator.class);
    new Links2ESRIShape(network, outputFileLs, builder).write();

    CoordinateReferenceSystem crs = MGC.getCRS("DHDN_GK4");
    builder.setWidthCoefficient(0.01);
    //		builder.setFeatureGeneratorPrototype(CountVehOnLinksPolygonBasedFeatureGenerator.class);
    builder.setFeatureGeneratorPrototype(CountVehOnLinksPolygonBasedFeatureGenerator.class);
    builder.setWidthCalculatorPrototype(CapacityBasedWidthCalculator.class);
    builder.setCoordinateReferenceSystem(crs);
    new Links2ESRIShape(network, outputFileP, builder).write();
  }
Пример #7
0
 /**
  * @param args 0 - Transit schedule file 1 - Last iteration 2 - Iterations interval with events 3
  *     - Output folder 4 - Distance bins file 5 - Distribution result folder
  * @throws java.io.IOException
  */
 public static void main(String[] args) throws IOException {
   ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());
   scenario.getConfig().transit().setUseTransit(true);
   new TransitScheduleReader(scenario).readFile(args[0]);
   int lastIteration = new Integer(args[1]);
   int iterationsInterval = new Integer(args[2]);
   for (int i = 0; i <= lastIteration; i += iterationsInterval) {
     EventsManager eventsManager = EventsUtils.createEventsManager();
     TimeDistributionStage timeDistribution =
         new TimeDistributionStage(scenario.getTransitSchedule(), new HashSet<Id>());
     eventsManager.addHandler(timeDistribution);
     new MatsimEventsReader(eventsManager)
         .readFile(args[3] + "/ITERS/it." + i + "/" + i + ".events.xml.gz");
     timeDistribution.printDistribution(
         timeDistribution.getDistribution(
             args[4], new String[] {"car", "bus", "mrt", "lrt", "transit_walk", "walk", "other"}),
         args[5] + "/timeDistribution." + i + ".csv");
   }
 }
  /** Saving UrbanSim and MATSim results for current run in a backup directory ... */
  private static void saveRunOutputs(ScenarioImpl scenario) {
    log.info("Saving UrbanSim and MATSim outputs ...");

    M4UControlerConfigModuleV3 m4ucModule =
        M4UConfigUtils.getMATSim4UrbaSimControlerConfigAndPossiblyConvert(scenario.getConfig());
    UrbanSimParameterConfigModuleV3 uspModule =
        M4UConfigUtils.getUrbanSimParameterConfigAndPossiblyConvert(scenario.getConfig());
    AccessibilityConfigGroup acm =
        ConfigUtils.addOrGetModule(
            scenario.getConfig(),
            AccessibilityConfigGroup.GROUP_NAME,
            AccessibilityConfigGroup.class);
    int currentYear = uspModule.getYear();

    String saveDirectory = "run" + currentYear;
    String savePath = Paths.checkPathEnding(uspModule.getMATSim4OpusBackup() + saveDirectory);
    // copy all files from matsim4opus/tmp to matsim4opus/backup
    // FileCopy.copyTree(InternalConstants.MATSIM_4_OPUS_TEMP, savePath);
    File saveDir = new File(savePath);
    if (!saveDir.exists())
      if (!saveDir.mkdirs()) log.error("Creating the backup directory " + savePath + " failed!");

    // backup files from matsim output
    try {
      // backup plans files
      FileCopy.fileCopy(
          new File(uspModule.getMATSim4OpusOutput() + InternalConstants.GENERATED_PLANS_FILE_NAME),
          new File(savePath + InternalConstants.GENERATED_PLANS_FILE_NAME));
      // backup matsim config file
      FileCopy.fileCopy(
          new File(uspModule.getMATSim4OpusOutput() + OUTPUT_CONFIG_FILE_NAME),
          new File(savePath + OUTPUT_CONFIG_FILE_NAME));
      // backup score stats
      FileCopy.fileCopy(
          new File(uspModule.getMATSim4OpusOutput() + OUTPUT_SCORESTATS_TXT),
          new File(savePath + OUTPUT_SCORESTATS_TXT));
      FileCopy.fileCopy(
          new File(uspModule.getMATSim4OpusOutput() + OUTPUT_SCORESTATS_PNG),
          new File(savePath + OUTPUT_SCORESTATS_PNG));
      FileCopy.fileCopy(
          new File(uspModule.getMATSim4OpusOutput() + OUTPUT_TRAVELDISTANCESTATS_TXT),
          new File(savePath + OUTPUT_TRAVELDISTANCESTATS_TXT));
      FileCopy.fileCopy(
          new File(uspModule.getMATSim4OpusOutput() + OUTPUT_TRAVELDISTANCESTATS_PNG),
          new File(savePath + OUTPUT_TRAVELDISTANCESTATS_PNG));
      FileCopy.fileCopy(
          new File(uspModule.getMATSim4OpusOutput() + OUTPUT_STOPWATCH),
          new File(savePath + OUTPUT_STOPWATCH));
      // backup last iteration
      int iteration =
          ((ControlerConfigGroup) scenario.getConfig().getModule(ControlerConfigGroup.GROUP_NAME))
              .getLastIteration();
      FileCopy.copyTree(
          uspModule.getMATSim4OpusOutput() + "ITERS/it." + iteration,
          savePath + "ITERS/it." + iteration);

      // backup zone csv file (feedback for UrbanSim)
      if (new File(uspModule.getMATSim4OpusTemp() + UrbanSimZoneCSVWriterV2.FILE_NAME).exists())
        FileCopy.fileCopy(
            new File(uspModule.getMATSim4OpusTemp() + UrbanSimZoneCSVWriterV2.FILE_NAME),
            new File(savePath + UrbanSimZoneCSVWriterV2.FILE_NAME));
      // backup parcel csv file (feedback for UrbanSim)
      if (new File(uspModule.getMATSim4OpusTemp() + UrbanSimParcelCSVWriter.FILE_NAME).exists())
        FileCopy.fileCopy(
            new File(uspModule.getMATSim4OpusTemp() + UrbanSimParcelCSVWriter.FILE_NAME),
            new File(savePath + UrbanSimParcelCSVWriter.FILE_NAME));
      // backup person csv file (feedback for UrbanSim)
      if (new File(uspModule.getMATSim4OpusTemp() + UrbanSimPersonCSVWriter.FILE_NAME).exists())
        FileCopy.fileCopy(
            new File(uspModule.getMATSim4OpusTemp() + UrbanSimPersonCSVWriter.FILE_NAME),
            new File(savePath + UrbanSimPersonCSVWriter.FILE_NAME));
      // backup travel_data csv file (feedback for UrbanSim)
      if (new File(uspModule.getMATSim4OpusTemp() + Zone2ZoneImpedancesControlerListener.FILE_NAME)
          .exists())
        FileCopy.fileCopy(
            new File(
                uspModule.getMATSim4OpusTemp() + Zone2ZoneImpedancesControlerListener.FILE_NAME),
            new File(savePath + Zone2ZoneImpedancesControlerListener.FILE_NAME));

      // backup plotting files free speed
      String fileName =
          Labels.FREESPEED_FILENAME
              + (double) acm.getCellSizeCellBasedAccessibility()
              + InternalConstants.FILE_TYPE_TXT;
      if (new File(uspModule.getMATSim4OpusTemp() + fileName).exists())
        FileCopy.fileCopy(
            new File(uspModule.getMATSim4OpusTemp() + fileName), new File(savePath + fileName));
      // backup plotting files for car
      fileName =
          Labels.CAR_FILENAME
              + (double) acm.getCellSizeCellBasedAccessibility()
              + InternalConstants.FILE_TYPE_TXT;
      if (new File(uspModule.getMATSim4OpusTemp() + fileName).exists())
        FileCopy.fileCopy(
            new File(uspModule.getMATSim4OpusTemp() + fileName), new File(savePath + fileName));
      // backup plotting files for bike
      fileName =
          Labels.BIKE_FILENAME
              + (double) acm.getCellSizeCellBasedAccessibility()
              + InternalConstants.FILE_TYPE_TXT;
      if (new File(uspModule.getMATSim4OpusTemp() + fileName).exists())
        FileCopy.fileCopy(
            new File(uspModule.getMATSim4OpusTemp() + fileName), new File(savePath + fileName));
      // backup plotting files for walk
      fileName =
          Labels.WALK_FILENAME
              + (double) acm.getCellSizeCellBasedAccessibility()
              + InternalConstants.FILE_TYPE_TXT;
      if (new File(uspModule.getMATSim4OpusTemp() + fileName).exists())
        FileCopy.fileCopy(
            new File(uspModule.getMATSim4OpusTemp() + fileName), new File(savePath + fileName));
    } catch (Exception e) {
      e.printStackTrace();
    }
    log.info("Saving UrbanSim and MATSim outputs done!");
  }