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