Пример #1
0
  /** @param args */
  public static void main(String[] args) {
    String //
        // netFilename = "../matsim/test/scenarios/chessboard/network.xml", //
        // popFilename = "../matsim/test/scenarios/chessboard/plans.xml", //
        facilitiesFilename = "../matsim/test/scenarios/chessboard/facilities.xml", //
        facilitiesTxtFilename = "../matsimTests/locationChoice/chessboard/facilities.txt";

    ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());
    // new MatsimNetworkReader(scenario).readFile(netFilename);
    new MatsimFacilitiesReader((ScenarioImpl) scenario).readFile(facilitiesFilename);

    SimpleWriter writer = new SimpleWriter(facilitiesTxtFilename);
    writer.writeln("Id\tx\ty\tacts\tcapacities");

    ActivityFacilities facilities = scenario.getActivityFacilities();
    for (ActivityFacility facility : facilities.getFacilities().values()) {
      Coord coord = facility.getCoord();
      writer.write(facility.getId() + "\t" + coord.getX() + "\t" + coord.getY() + "\t");

      Map<String, ? extends ActivityOption> activityOptions = facility.getActivityOptions();
      // acts
      writer.write(activityOptions.keySet());
      // capacities
      for (ActivityOption activityOption : activityOptions.values()) {
        writer.write("\t" + activityOption.getCapacity());
      }
      writer.writeln();
      writer.flush();
    }

    writer.close();
  }
Пример #2
0
  // Create external Facilities that are used by transit traffic agents.
  private static void createExternalFacilities(Scenario scenario, Set<Id<Node>> externalNodes) {

    ActivityFacilities activityFacilities = scenario.getActivityFacilities();
    ActivityFacilitiesFactory factory = activityFacilities.getFactory();

    /*
     * We check for all OutLinks of all external nodes if they already host a facility. If not,
     * a new facility with a tta ActivityOption will be created and added.
     */
    for (Id<Node> id : externalNodes) {
      Node externalNode = scenario.getNetwork().getNodes().get(id);

      for (Link externalLink : externalNode.getOutLinks().values()) {
        ActivityFacility facility = activityFacilities.getFacilities().get(externalLink.getId());

        // if already a facility exists we have nothing left to do
        if (facility != null) continue;

        /*
         * No Facility exists at that link therefore we create and add a new one.
         */
        double fromX = externalLink.getFromNode().getCoord().getX();
        double fromY = externalLink.getFromNode().getCoord().getY();
        double toX = externalLink.getToNode().getCoord().getX();
        double toY = externalLink.getToNode().getCoord().getY();

        double dX = toX - fromX;
        double dY = toY - fromY;

        double length = Math.sqrt(Math.pow(dX, 2) + Math.pow(dY, 2));

        double centerX = externalLink.getCoord().getX();
        double centerY = externalLink.getCoord().getY();

        /*
         * Unit vector that directs with an angle of 90° away from the link.
         */
        double unitVectorX = dY / length;
        double unitVectorY = -dX / length;

        Coord coord = new Coord(centerX + unitVectorX, centerY + unitVectorY);

        facility =
            activityFacilities
                .getFactory()
                .createActivityFacility(
                    Id.create(externalLink.getId().toString(), ActivityFacility.class), coord);
        activityFacilities.addActivityFacility(facility);
        ((ActivityFacilityImpl) facility).setLinkId(externalLink.getId());

        ActivityOption activityOption = factory.createActivityOption(ttaActivityType);
        activityOption.addOpeningTime(new OpeningTimeImpl(0 * 3600, 24 * 3600));
        activityOption.setCapacity(capacity);
        facility.addActivityOption(activityOption);
      }
    }
  }
Пример #3
0
  public static void main(final String[] args) {
    final String pathToCSV = args[0];
    final String activityType = args[1];
    final String pathToOutputFacilities = args[2];

    final boolean publicFacilities = true;

    final ActivityFacilitiesFactoryImpl factory = new ActivityFacilitiesFactoryImpl();
    final ActivityFacilities facilities = FacilitiesUtils.createActivityFacilities();
    int idNumber = 0;

    CSVReader reader = new CSVReader(pathToCSV);
    reader.skipLine(); // skip header
    String[] newLine = reader.readLine(); // first line
    while (newLine != null) {

      // EMPFTE;METER_X;METER_Y;NOGA_CD_2008_6;KATEGORIE;NOGA_TAG;CAPACITY;OPEN_FROM;OPEN_TO;METER_X_GERUNDET;METER_Y_GERUNDET
      double xCoord = Double.parseDouble(newLine[1]);
      double yCoord = Double.parseDouble(newLine[2]);
      String desc = newLine[4] + " (" + newLine[5] + ")";
      double capacity = Double.parseDouble(newLine[6]);
      double openFrom = Double.parseDouble(newLine[7]);
      double openTill = Double.parseDouble(newLine[8]);

      // new facility
      ActivityFacilityImpl newFacility =
          (ActivityFacilityImpl)
              factory.createActivityFacility(
                  Id.create(String.format("%06d", ++idNumber), ActivityFacility.class),
                  new Coord(xCoord, yCoord));
      if (!publicFacilities) {
        newFacility.setDesc(desc);
      }
      // new activity
      ActivityOption newActivity = factory.createActivityOption(activityType);
      newActivity.setCapacity(capacity);
      newActivity.addOpeningTime(new OpeningTimeImpl(openFrom, openTill));
      newFacility.addActivityOption(newActivity);
      // add new facility and activity
      facilities.addActivityFacility(newFacility);

      newLine = reader.readLine(); // next line
    }

    // Write facilities
    FacilitiesWriter facilitiesWriter = new FacilitiesWriter(facilities);
    facilitiesWriter.write(pathToOutputFacilities);
    testFacilities(pathToOutputFacilities);
  }
Пример #4
0
  // Create Facilities inside the simulated area.
  private static void createInternalFacilities(
      Scenario scenario,
      Map<Integer, Emme2Zone> zonalAttributes,
      Map<Integer, SimpleFeature> zonalShapes) {

    // create indices for the zones
    Map<Integer, Integer> indices = new HashMap<Integer, Integer>();
    int index = 0;
    for (Integer taz : zonalShapes.keySet()) {
      indices.put(taz, index);
      index++;
    }

    NetworkImpl network = (NetworkImpl) scenario.getNetwork();

    ActivityFacilities activityFacilities = scenario.getActivityFacilities();
    ObjectAttributes facilitiesAttributes = activityFacilities.getFacilityAttributes();
    ActivityFacilitiesFactory factory = activityFacilities.getFactory();

    for (Entry<Integer, SimpleFeature> entry : zonalShapes.entrySet()) {
      int taz = entry.getKey();
      SimpleFeature feature = entry.getValue();
      Geometry geometry = (Geometry) feature.getDefaultGeometry();
      List<Coord> coordinates = getRandomCoordinatesInZone(facilitiesPerZone, geometry, random);

      int i = 0;
      for (Coord coord : coordinates) {
        Id<ActivityFacility> id = Id.create(taz + "_" + i, ActivityFacility.class);
        ActivityFacility facility = factory.createActivityFacility(id, coord);
        createAndAddActivityOptions(scenario, facility, zonalAttributes.get(taz));
        activityFacilities.addActivityFacility(facility);
        Link link = network.getNearestLinkExactly(coord);
        ((ActivityFacilityImpl) facility).setLinkId(link.getId());
        i++;

        // Also add a tta activity to all facilities.
        ActivityOption activityOption = factory.createActivityOption(ttaActivityType);
        activityOption.addOpeningTime(new OpeningTimeImpl(0 * 3600, 24 * 3600));
        activityOption.setCapacity(capacity);
        facility.addActivityOption(activityOption);

        facilitiesAttributes.putAttribute(id.toString(), TAZObjectAttributesName, taz);
        facilitiesAttributes.putAttribute(
            id.toString(), indexObjectAttributesName, indices.get(taz));
      }
    }
  }
  public static void main(String[] args) {
    // Input and output
    String networkFile =
        "../../matsimExamples/countries/za/nmbm/network/NMBM_Network_CleanV7.xml.gz";
    String facilitiesFile =
        "../../matsimExamples/countries/za/nmbm/facilities/20121010/facilities.xml.gz";
    String outputDirectory = "../../accessibility-sa/data/12/";
    //		String travelTimeMatrix = folderStructure +
    // "matsimExamples/countries/za/nmbm/minibus-pt/JTLU_14i_06/travelTimeMatrix.csv.gz";
    //		String travelDistanceMatrix = folderStructure +
    // "matsimExamples/countries/za/nmbm/minibus-pt/JTLU_14i_06/travelDistanceMatrix.csv.gz";
    //		String ptStops = folderStructure +
    // "matsimExamples/countries/za/nmbm/minibus-pt/JTLU_14i_06/measuringPointsAsStops.csv.gz";
    //		String minibusPtTravelTimeMatrix = folderStructure +
    // "matsimExamples/countries/za/nmbm/minibus-pt/JTLU_14i_07/travelTimeMatrix.csv";
    //		String minibusPtTravelDistanceMatrix = folderStructure +
    // "matsimExamples/countries/za/nmbm/minibus-pt/JTLU_14i_07/travelDistanceMatrix.csv";
    //		String measuringPointsAsPtStops = folderStructure +
    // "matsimExamples/countries/za/nmbm/minibus-pt/JTLU_14i_07/measuringPointsAsStops.csv";

    // Parameters
    boolean includeDensityLayer = true;
    String crs = TransformationFactory.WGS84_SA_Albers;
    Double lowerBound = 2.;
    Double upperBound = 5.5;
    Integer range = 9;
    int symbolSize = 1010;
    int populationThreshold = (int) (200 / (1000 / cellSize * 1000 / cellSize));

    final Config config = ConfigUtils.createConfig(new AccessibilityConfigGroup());
    config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists);
    config.controler().setOutputDirectory(outputDirectory);
    config.network().setInputFile(networkFile);
    config.facilities().setInputFile(facilitiesFile);

    config.controler().setLastIteration(0);

    final Scenario scenario = ScenarioUtils.loadScenario(config);

    String typeWEQ = "w-eq";
    List<String> activityTypes = new ArrayList<>();
    activityTypes.add(typeWEQ);

    final ActivityFacilities homes = FacilitiesUtils.createActivityFacilities("homes");
    final ActivityFacilities amenities = FacilitiesUtils.createActivityFacilities("amenities");
    for (ActivityFacility fac : scenario.getActivityFacilities().getFacilities().values()) {
      for (ActivityOption option : fac.getActivityOptions().values()) {
        // figure out all activity types
        if (!activityTypes.contains(option.getType())) {
          activityTypes.add(option.getType());
        }

        // add all facilites that are not home or work
        if (!option.getType().equals("h")
            && !option.getType().equals("w")
            && !option.getType().equals("minor")) {
          if (!amenities.getFacilities().containsKey(fac.getId())) {
            amenities.addActivityFacility(fac);
          }
        }

        // figure out where the homes are
        if (option.getType().equals("h")) {
          homes.addActivityFacility(fac);
        }
      }
    }

    // extends of the network are (as they can looked up by using the bounding box):
    // minX = 111083.9441831379, maxX = 171098.03695045778, minY = -3715412.097693177,	maxY =
    // -3668275.43481496

    //		double[] mapViewExtent = {100000,-3720000,180000,-3675000}; // choose map view a bit bigger
    double[] mapViewExtent = {
      115000, -3718000, 161000, -3679000
    }; // what actually needs to be drawn

    Controler controler = new Controler(scenario);
    controler.addOverridingModule(
        new AbstractModule() {
          @Override
          public void install() {
            addControlerListenerBinding()
                .toProvider(
                    new Provider<ControlerListener>() {
                      @Inject Scenario scenario;
                      @Inject Map<String, TravelTime> travelTimes;
                      @Inject Map<String, TravelDisutilityFactory> travelDisutilityFactories;

                      @Override
                      public ControlerListener get() {
                        GridBasedAccessibilityControlerListenerV3 listener =
                            new GridBasedAccessibilityControlerListenerV3(
                                amenities,
                                null,
                                config,
                                scenario,
                                travelTimes,
                                travelDisutilityFactories);
                        listener.setComputingAccessibilityForMode(
                            Modes4Accessibility.freeSpeed, true);
                        listener.addAdditionalFacilityData(homes);
                        listener.generateGridsAndMeasuringPointsByNetwork(cellSize);
                        listener.writeToSubdirectoryWithName("w-eq");
                        listener.setUrbansimMode(
                            false); // avoid writing some (eventually: all) files that related to
                                    // matsim4urbansim
                        return listener;
                      }
                    });
          }
        });
    controler.run();

    String workingDirectory = config.controler().getOutputDirectory();

    String osName = System.getProperty("os.name");

    //		for (String actType : activityTypes) {
    String actSpecificWorkingDirectory = workingDirectory + typeWEQ + "/";

    for (Modes4Accessibility mode : Modes4Accessibility.values()) {
      //				VisualizationUtilsDZ.createQGisOutput(typeWEQ, mode, mapViewExtent, workingDirectory,
      // crs, includeDensityLayer);
      VisualizationUtilsDZ.createQGisOutput(
          typeWEQ,
          mode,
          mapViewExtent,
          workingDirectory,
          crs,
          includeDensityLayer,
          lowerBound,
          upperBound,
          range,
          symbolSize,
          populationThreshold);
      VisualizationUtilsDZ.createSnapshot(actSpecificWorkingDirectory, mode, osName);
    }
    //		}
  }
Пример #6
0
  /*
   * Creates and adds the possible activities to the facility. The capacities
   * have to defined elsewhere...
   *
   * home	/	no (Activity)	/	0 .. 24
   * work	/	work	/	8 .. 18
   * education	/	study	/	8 .. 18
   * shopping	/	shopping	/	9 .. 19
   * leisure	/	other	6 .. 22
   *
   * Mapping from the zones file:
   *
   * Cultural Areas -> leisure, work
   * Education -> education_university, education_highschool, education_elementaryschool, work
   * Office -> work
   * Shopping -> leisure, work
   * Health Institutions -> work, leisure
   * Urban Cores -> ignore
   * Religions Character -> ignore
   * Transportation -> work, leisure (airport, big train stations, etc.)
   */
  private static void createAndAddActivityOptions(
      Scenario scenario, ActivityFacility facility, Emme2Zone zone) {

    boolean hasHome = false;
    boolean hasWork = false;
    boolean hasEducationUniversity = false;
    boolean hasEducationHighSchool = false;
    boolean hasEducationElementarySchool = false;
    boolean hasShopping = false;
    boolean hasLeisure = false;

    hasHome = zone.hasHome();
    hasWork = zone.hasWork();
    hasEducationUniversity = zone.hasEducationUniversity();
    hasEducationHighSchool = zone.hasEducationHighSchool();
    hasEducationElementarySchool = zone.hasEducationElementarySchool();
    hasShopping = zone.hasShopping();
    hasLeisure = zone.hasLeisure();
    //		if (zone.POPULATION > 0) { hasHome = true; }
    //		if (zone.CULTURAL > 0) { hasLeisure = true; hasWork = true; }
    //		if (zone.EDUCATION == 1) { hasEducationUniversity = true; hasWork = true; }
    //		if (zone.EDUCATION == 2) { hasEducationHighSchool = true; hasWork = true; }
    //		if (zone.EDUCATION == 3) { hasEducationElementarySchool = true; hasWork = true; }
    //		if (zone.OFFICE > 0) { hasWork = true; }
    //		if (zone.SHOPPING > 0) { hasShopping = true; hasWork = true; }
    //		if (zone.HEALTH > 0) { hasLeisure = true; hasWork = true; }
    //		if (zone.TRANSPORTA > 0) { hasLeisure = true; hasWork = true; }
    //		if (zone.EMPL_TOT > 0) { hasWork = true; }

    // "Other" activities - should be possible in every zone.
    //		hasLeisure = true;

    // "Shopping" activities - should be possible in every zone.
    //		hasShopping = true;

    ActivityOption activityOption;

    ActivityFacilitiesFactory factory = scenario.getActivityFacilities().getFactory();

    if (hasHome) {
      activityOption = factory.createActivityOption("home");
      facility.addActivityOption(activityOption);
      activityOption.addOpeningTime(new OpeningTimeImpl(0 * 3600, 24 * 3600));
      activityOption.setCapacity(capacity);
    }

    if (hasWork) {
      activityOption = factory.createActivityOption("work");
      facility.addActivityOption(activityOption);
      activityOption.addOpeningTime(new OpeningTimeImpl(8 * 3600, 18 * 3600));
      activityOption.setCapacity(capacity);
    }

    if (hasEducationUniversity) {
      activityOption = factory.createActivityOption("education_university");
      facility.addActivityOption(activityOption);
      activityOption.addOpeningTime(new OpeningTimeImpl(9 * 3600, 18 * 3600));
      activityOption.setCapacity(capacity);
    }

    if (hasEducationHighSchool) {
      activityOption = factory.createActivityOption("education_highschool");
      facility.addActivityOption(activityOption);
      activityOption.addOpeningTime(new OpeningTimeImpl(8 * 3600, 16 * 3600));
      activityOption.setCapacity(capacity);
    }

    if (hasEducationElementarySchool) {
      activityOption = factory.createActivityOption("education_elementaryschool");
      facility.addActivityOption(activityOption);
      activityOption.addOpeningTime(new OpeningTimeImpl(8 * 3600, 14 * 3600));
      activityOption.setCapacity(capacity);
    }

    if (hasShopping) {
      activityOption = factory.createActivityOption("shopping");
      facility.addActivityOption(activityOption);
      activityOption.addOpeningTime(new OpeningTimeImpl(9 * 3600, 19 * 3600));
      activityOption.setCapacity(capacity);
    }

    if (hasLeisure) {
      activityOption = factory.createActivityOption("leisure");
      facility.addActivityOption(activityOption);
      activityOption.addOpeningTime(new OpeningTimeImpl(6 * 3600, 22 * 3600));
      activityOption.setCapacity(capacity);
    }
  }