예제 #1
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);
      }
    }
  }
예제 #2
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));
      }
    }
  }
예제 #3
0
파일: OsmSink.java 프로젝트: krlmlr/matsim
  private void processFacilities(
      ActivityFacilitiesFactory aff, Map<Long, ? extends EntityContainer> nodeMap) {

    for (Long n : nodeMap.keySet()) {

      Entity entity = nodeMap.get(n).getEntity();
      Map<String, String> tags = new TagCollectionImpl(entity.getTags()).buildMap();

      for (String s : this.keys) {

        String tourism = tags.get(s);
        String matsimType = null;
        if (tourism != null) {
          matsimType = getActivityType(tourism);
        }
        if (matsimType != null) {

          String name = tags.get("name");

          if (name != null) {

            name.replace("ä", "ae");
            name.replace("ö", "oe");
            name.replace("ü", "ue");
          }
          Coord coord =
              OsmCoordUtils.getCoord(entity, this.ct, this.nodeMap, this.wayMap, this.relationMap);
          Id<ActivityFacility> id = Id.create(entity.getId(), ActivityFacility.class);
          ActivityFacility af;
          if (!this.facilities.getFacilities().containsKey(id)) {
            af = aff.createActivityFacility(id, coord);
            //					((ActivityFacilityImpl)af).setDesc(name);
            this.facilities.addActivityFacility(af);
          } else {
            af = (ActivityFacilityImpl) this.facilities.getFacilities().get(id);
          }

          ActivityOption ao = aff.createActivityOption(matsimType);
          af.addActivityOption(ao);
        }
      }
    }
  }
예제 #4
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);
    }
  }