Example #1
0
  public OsmSink(
      CoordinateTransformation ct, Map<String, String> osmToMatsimType, Set<String> keys) {
    this.ct = ct;
    this.typeMap = osmToMatsimType;
    this.nodeMap = new HashMap<>();
    this.wayMap = new HashMap<>();
    this.relationMap = new HashMap<>();
    this.keys = keys;

    this.facilities = FacilitiesUtils.createActivityFacilities("Facilities");
    this.attributes = new ObjectAttributes();
  }
Example #2
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);
  }
Example #3
0
  public ActivityFacilities filterFacilitiesWithPopulation(
      final ActivityFacilities origFacilities) {
    ActivityFacilities filteredFacilities = FacilitiesUtils.createActivityFacilities();

    for (Person person : filteredAgents.values()) {
      if (person.getSelectedPlan() != null) {
        for (PlanElement pe : person.getSelectedPlan().getPlanElements()) {
          if (pe instanceof ActivityImpl) {
            ActivityImpl act = (ActivityImpl) pe;
            if (act.getFacilityId() != null
                && !filteredFacilities.getFacilities().containsKey(act.getFacilityId())) {
              filteredFacilities.addActivityFacility(
                  origFacilities.getFacilities().get(act.getFacilityId()));
            }
          }
        }
      }
    }

    return filteredFacilities;
  }
  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);
    }
    //		}
  }