Java Code Examples for org.matsim.api.core.v01.Id#create()
The following examples show how to use
org.matsim.api.core.v01.Id#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StopReader.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
private void createStops() throws IOException { log.info(" Read transit stops..."); BufferedReader readsLines = new BufferedReader(new InputStreamReader(new FileInputStream(pathToBFKOORD_GEOFile), "utf-8")); String newLine = readsLines.readLine(); while (newLine != null) { /* 1−7 INT32 Nummer der Haltestelle 9−18 FLOAT X-Koordinate 20−29 FLOAT Y-Koordinate 31−36 INT16 Z-Koordinate (Tunnel und andere Streckenelemente ohne eigentliche Haltestelle haben keine Z-Koordinate) 38ff CHAR Kommentarzeichen "%"gefolgt vom Klartext des Haltestellennamens (optional zur besseren Lesbarkeit) */ Id<TransitStopFacility> stopId = Id.create(newLine.substring(0, 7), TransitStopFacility.class); double xCoord = Double.parseDouble(newLine.substring(8, 18)); double yCoord = Double.parseDouble(newLine.substring(19, 29)); Coord coord = new Coord(xCoord, yCoord); if (this.transformation != null) { coord = this.transformation.transform(coord); } String stopName = newLine.substring(39, newLine.length()); createStop(stopId, coord, stopName); newLine = readsLines.readLine(); } readsLines.close(); log.info(" Read transit stops... done."); }
Example 2
Source File: GtfsConverter.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
protected void createTransfers(TransitSchedule schedule) { MinimalTransferTimes minimalTransferTimes = schedule.getMinimalTransferTimes(); for(Transfer transfer : feed.getTransfers()) { if(!transfer.getTransferType().equals(GtfsDefinitions.TransferType.TRANSFER_NOT_POSSIBLE)) { Id<TransitStopFacility> fromStop = Id.create(transfer.getFromStopId(), TransitStopFacility.class); Id<TransitStopFacility> toStop = Id.create(transfer.getToStopId(), TransitStopFacility.class); // Note: Timed transfer points (type 1) cannot be represented with minimalTransferTimes only double minTransferTime = 0; if(transfer.getTransferType().equals(GtfsDefinitions.TransferType.REQUIRES_MIN_TRANSFER_TIME)) { minTransferTime = transfer.getMinTransferTime(); } minimalTransferTimes.set(fromStop, toStop, minTransferTime); } } }
Example 3
Source File: ArtificialSharedScenarioCreator.java From amodeus with GNU General Public License v2.0 | 5 votes |
public ArtificialSharedScenarioCreator(Config config) { LinkTimePair divertableLinkTime = new LinkTimePair(linkDepotOut, 0.0); Id<DvrpVehicle> idAv1 = Id.create("av1", DvrpVehicle.class); vehicle1 = new DvrpVehicleImpl(ImmutableDvrpVehicleSpecification.newBuilder() // .id(idAv1) // .serviceBeginTime(0.0) // .serviceEndTime(Double.POSITIVE_INFINITY) // .capacity(3) // .startLinkId(linkDepotOut.getId()) // .build(), linkDepotOut); roboTaxi1 = new RoboTaxi(vehicle1, divertableLinkTime, linkDepotOut, RoboTaxiUsageType.SHARED); setFirstStayTask(vehicle1); Id<DvrpVehicle> idAv2 = Id.create("av2", DvrpVehicle.class); vehicle2 = new DvrpVehicleImpl(ImmutableDvrpVehicleSpecification.newBuilder() // .id(idAv2) // .serviceBeginTime(0.0) // .serviceEndTime(Double.POSITIVE_INFINITY) // .capacity(3) // .startLinkId(linkDepotOut.getId()) // .build(), linkDepotOut); roboTaxi2 = new RoboTaxi(vehicle2, divertableLinkTime, linkDepotOut, RoboTaxiUsageType.SHARED); setFirstStayTask(vehicle2); System.out.println("ArtificialScenario Created"); }
Example 4
Source File: GtfsConverterTest.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
@Test public void combineRoutes() { TransitSchedule test = ScheduleTools.createSchedule(); TransitScheduleFactory f = test.getFactory(); Id<TransitLine> lineId = Id.create("L", TransitLine.class); TransitLine line = f.createTransitLine(lineId); test.addTransitLine(line); Id<TransitStopFacility> stopId1 = Id.create("s1", TransitStopFacility.class); Id<TransitStopFacility> stopId2 = Id.create("s2", TransitStopFacility.class); Id<TransitStopFacility> stopId3 = Id.create("s3", TransitStopFacility.class); test.addStopFacility(f.createTransitStopFacility(stopId1, new Coord(1, 1), true)); test.addStopFacility(f.createTransitStopFacility(stopId2, new Coord(2, 2), true)); test.addStopFacility(f.createTransitStopFacility(stopId3, new Coord(3, 3), true)); List<TransitRouteStop> routeStops1 = new LinkedList<>(); List<TransitRouteStop> routeStops2 = new LinkedList<>(); List<TransitRouteStop> routeStops3 = new LinkedList<>(); int t = 0; for(TransitStopFacility stopFacility : test.getFacilities().values()) { routeStops1.add(f.createTransitRouteStop(stopFacility, t * 60, t * 60 + 30)); routeStops2.add(f.createTransitRouteStop(stopFacility, t * 40, t * 40 + 10)); routeStops3.add(f.createTransitRouteStop(stopFacility, t * 40, t * 40 + 10)); } TransitRoute route1 = f.createTransitRoute(Id.create("R1", TransitRoute.class), null, routeStops1, "bus"); route1.addDeparture(f.createDeparture(Id.create("dep1", Departure.class), 0.0)); TransitRoute route2 = f.createTransitRoute(Id.create("R2", TransitRoute.class), null, routeStops2, "bus"); route1.addDeparture(f.createDeparture(Id.create("dep2", Departure.class), 0.0)); TransitRoute route3 = f.createTransitRoute(Id.create("R3", TransitRoute.class), null, routeStops3, "bus"); route1.addDeparture(f.createDeparture(Id.create("dep3", Departure.class), 4200.0)); line.addRoute(route1); line.addRoute(route2); line.addRoute(route3); Assert.assertEquals(3, line.getRoutes().size()); // only routes with identical stop sequence (1, 2, 3) and departure sequence (2, 3) are combined. gtfsConverter.combineTransitRoutes(test); Assert.assertEquals(2, line.getRoutes().size()); }
Example 5
Source File: PseudoRouteStopImpl.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
/** * This constructor is only used to set dummy stops */ public PseudoRouteStopImpl(String id) { if(id.equals(PseudoGraphImpl.SOURCE)) { this.id = Id.create(PseudoGraphImpl.SOURCE, PseudoRouteStop.class); this.travelCostToSource = 0; } else { this.id = Id.create(PseudoGraphImpl.DESTINATION, PseudoRouteStop.class); } previous = null; this.linkId = null; // stop facility values this.coord = null; this.parentStopFacilityId = null; this.isBlockingLane = false; this.facilityName = null; this.stopAreaId = null; // route stop values this.departureOffset = 0.0; this.arrivalOffset = 0.0; this.awaitDepartureTime = false; // link value this.linkCandidate = null; }
Example 6
Source File: GtfsFeedImpl.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
/** * Loads shapes (if available) and puts them in {@link #shapes}. A shape is a sequence of points, i.e. a line. * <p/> * <br/><br/> * shapes.txt <i>[https://developers.google.com/transit/gtfs/reference]</i><br/> * Rules for drawing lines on a map to represent a transit organization's routes. */ protected void loadShapes() { // shapes are optional log.info("Looking for shapes.txt"); int l = 1; try { CSVReader reader = createCSVReader(root + GtfsDefinitions.Files.SHAPES.fileName); String[] header = reader.readNext(); Map<String, Integer> col = getIndices(header, GtfsDefinitions.Files.SHAPES.columns, GtfsDefinitions.Files.SHAPES.optionalColumns); String[] line = reader.readNext(); while(line != null) { l++; usesShapes = true; // shape file might exists but could be empty Id<RouteShape> shapeId = Id.create(line[col.get(GtfsDefinitions.SHAPE_ID)], RouteShape.class); RouteShape currentShape = shapes.get(shapeId); if(currentShape == null) { currentShape = new GtfsShape(line[col.get(GtfsDefinitions.SHAPE_ID)]); shapes.put(shapeId, currentShape); } Coord point = new Coord(Double.parseDouble(line[col.get(GtfsDefinitions.SHAPE_PT_LON)]), Double.parseDouble(line[col.get(GtfsDefinitions.SHAPE_PT_LAT)])); currentShape.addPoint(point, Integer.parseInt(line[col.get(GtfsDefinitions.SHAPE_PT_SEQUENCE)])); line = reader.readNext(); } reader.close(); log.info("... shapes.txt loaded"); } catch (IOException e) { log.info("... no shapes file found."); } catch (ArrayIndexOutOfBoundsException i) { throw new RuntimeException("Line " + l + " in shapes.txt is empty or malformed."); } }
Example 7
Source File: FPLANRoute.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
/** * @return the transit route stops of this route. Static schedule needs to be set. */ public List<TransitRouteStop> getTransitRouteStops() { if(schedule == null) { throw new RuntimeException("Schedule and stopFacilities not yet defined for FPLANRoute!"); } for(Object[] t : tmpStops) { Id<TransitStopFacility> stopFacilityId = Id.create((String) t[0], TransitStopFacility.class); int arrivalTime = (int) t[1]; int departureTime = (int) t[2]; double arrivalDelay = 0.0; if(arrivalTime > 0 && firstDepartureTime > 0) { arrivalDelay = arrivalTime + initialDelay - firstDepartureTime; } double departureDelay = 0.0; if(departureTime > 0 && firstDepartureTime > 0) { departureDelay = departureTime + initialDelay - firstDepartureTime; } else if(arrivalDelay > 0) { departureDelay = arrivalDelay + initialDelay; } TransitStopFacility stopFacility = schedule.getFacilities().get(stopFacilityId); if (stopFacility == null) { log.warn("StopFacility " + stopFacilityId + " not defined, not adding stop" + fahrtNummer); } else { TransitRouteStop routeStop = scheduleFactory.createTransitRouteStop(stopFacility, arrivalDelay, departureDelay); routeStop.setAwaitDepartureTime(true); // Only *T-Lines (currently not implemented) would have this as false... transitRouteStops.add(routeStop); } } return transitRouteStops; }
Example 8
Source File: OsmElement.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public Node(final long id, final Coord coord, Map<String, String> tags) { this.id = Id.create(id, Osm.Node.class); this.coord = coord; this.tags = tags; }
Example 9
Source File: OsmElement.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public Relation(long id, Map<String, String> tags) { this.id = Id.create(id, Osm.Relation.class); this.tags = tags; }
Example 10
Source File: GtfsShape.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public GtfsShape(String id) { this.id = Id.create(id, RouteShape.class); }
Example 11
Source File: OsmTransitScheduleConverter.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
protected Id<TransitLine> createLineId(Osm.Relation relation) { return Id.create(createStringId(relation), TransitLine.class); }
Example 12
Source File: ScheduleTools.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public static Id<TransitStopFacility> createParentStopFacilityId(String stopFacilityId) { String str = getParentStopFacilityId(stopFacilityId); return Id.create(str, TransitStopFacility.class); }
Example 13
Source File: ScheduleTools.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public static Id<TransitStopFacility> createParentStopFacilityId(TransitStopFacility stopFacility) { String str = getParentStopFacilityId(stopFacility.getId().toString()); return Id.create(str, TransitStopFacility.class); }
Example 14
Source File: GtfsConverter.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
protected Id<Departure> createDepartureId(TransitRoute route, int time) { String str = route.getId().toString() + "_" + Time.writeTime(time, "HH:mm:ss"); return Id.create(str, Departure.class); }
Example 15
Source File: ScheduleTools.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
/** * Merges mergeSchedule with an offset into baseSchedule. baseSchedule is modified. Can be used to generate schedule * that run longer than 24h for simulation purposes. * * @param mergeOffset offset in seconds added to the departures of mergeschedule * @param timeLimit departures are not added if they are after this timelimit (in seconds), starting from * 0.0 of the baseschedulel */ public static void mergeSchedules(TransitSchedule baseSchedule, TransitSchedule mergeSchedule, double mergeOffset, double timeLimit) { // merge stops for(TransitStopFacility tsf : mergeSchedule.getFacilities().values()) { if(!baseSchedule.getFacilities().containsKey(tsf.getId())) { baseSchedule.addStopFacility(tsf); } } // merge transit lines for(TransitLine mergeTransitLine : mergeSchedule.getTransitLines().values()) { TransitLine baseTransitLine = baseSchedule.getTransitLines().get(mergeTransitLine.getId()); if(baseTransitLine == null) { baseSchedule.addTransitLine(mergeTransitLine); } else { for(TransitRoute mergeTR : mergeTransitLine.getRoutes().values()) { TransitRoute baseTR = baseTransitLine.getRoutes().get(mergeTR.getId()); if(baseTR == null) { baseTransitLine.addRoute(mergeTR); } else { if(transitRouteStopSequenceIsEqual(baseTR, mergeTR)) { if(mergeOffset > 0) { for(Departure departure : mergeTR.getDepartures().values()) { if(departure.getDepartureTime() + mergeOffset < timeLimit) { Id<Departure> newDepartureId = Id.create(departure.getId() + "+" + mergeOffset / (3600) + "h", Departure.class); Departure newDeparture = baseSchedule.getFactory().createDeparture(newDepartureId, departure.getDepartureTime() + mergeOffset); baseTR.addDeparture(newDeparture); } } } } else { Id<TransitRoute> newTransitRouteId = Id.create(mergeTR.getId() + "_merged", TransitRoute.class); TransitRoute newTransitRoute = baseSchedule.getFactory().createTransitRoute(newTransitRouteId, mergeTR.getRoute(), mergeTR.getStops(), mergeTR.getTransportMode()); baseTransitLine.addRoute(newTransitRoute); } } } } } }
Example 16
Source File: AbstractPlausibilityWarning.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public AbstractPlausibilityWarning(Type type, TransitLine transitLine, TransitRoute transitRoute) { this.id = Id.create(idLong++, PlausibilityWarning.class); this.type = type; this.transitLine = transitLine; this.transitRoute = transitRoute; }
Example 17
Source File: HafasConverter.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
private static Id<TransitRoute> createRouteId(FPLANRoute route, int routeNr) { return Id.create(route.getFahrtNummer() + "_" + String.format("%03d", routeNr), TransitRoute.class); }
Example 18
Source File: GtfsFeedImpl.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
/** * Generates a trip with trip_id and adds it to the corresponding route (referenced by route_id) in {@link #routes}. * Adds the shape_id as well (if shapes are used). Each trip uses one service_id, the serviceIds statistics are increased accordingly * <p/> * <br/><br/> * trips.txt <i>[https://developers.google.com/transit/gtfs/reference]</i><br/> * Trips for each route. A trip is a sequence of two or more stops that occurs at specific time. * * @throws IOException */ protected void loadTrips() throws IOException { log.info("Loading trips.txt"); int l = 1; try { CSVReader reader = createCSVReader(root + GtfsDefinitions.Files.TRIPS.fileName); String[] header = reader.readNext(); Map<String, Integer> col = getIndices(header, GtfsDefinitions.Files.TRIPS.columns, GtfsDefinitions.Files.TRIPS.optionalColumns); String[] line = reader.readNext(); while(line != null) { l++; Trip newTrip; String routeId = line[col.get(GtfsDefinitions.ROUTE_ID)]; Route route = routes.get(routeId); String serviceId = line[col.get(GtfsDefinitions.SERVICE_ID)]; Service service = services.get(serviceId); if(service == null) { throw new IllegalStateException("Service " + serviceId + " not found"); } if(route == null) { if(!ignoredRoutes.contains(routeId)) { throw new IllegalStateException("Route " + routeId + " not found"); } else { ignoredTrips.add(line[col.get(GtfsDefinitions.TRIP_ID)]); } } else { if(usesShapes) { Id<RouteShape> shapeId = Id.create(line[col.get(GtfsDefinitions.SHAPE_ID)], RouteShape.class); // column might not be available newTrip = new TripImpl(line[col.get(GtfsDefinitions.TRIP_ID)], route, service, shapes.get(shapeId)); } else { newTrip = new TripImpl(line[col.get(GtfsDefinitions.TRIP_ID)], route, service); } // store Trip ((RouteImpl) route).addTrip(newTrip); ((ServiceImpl) service).addTrip(newTrip); trips.put(newTrip.getId(), newTrip); } line = reader.readNext(); } reader.close(); } catch (ArrayIndexOutOfBoundsException i) { throw new RuntimeException("Line " + l + " in trips.txt is empty or malformed."); } log.info("... trips.txt loaded"); }
Example 19
Source File: ArtificialScenarioCreator.java From amodeus with GNU General Public License v2.0 | 4 votes |
public ArtificialScenarioCreator(Config config) { network = (config == null) ? NetworkUtils.createNetwork() : NetworkUtils.createNetwork(config); Id<Node> nodeid1 = Id.createNodeId("node1"); Coord coord1 = new Coord(100, 100); node1 = NetworkUtils.createNode(nodeid1, coord1); network.addNode(node1); Id<Node> nodeid2 = Id.createNodeId("node2"); Coord coord2 = new Coord(100, 200); node2 = NetworkUtils.createNode(nodeid2, coord2); network.addNode(node2); Id<Node> nodeid3 = Id.createNodeId("node3"); Coord coord3 = new Coord(200, 200); node3 = NetworkUtils.createNode(nodeid3, coord3); network.addNode(node3); Id<Node> nodeid4 = Id.createNodeId("node4"); Coord coord4 = new Coord(200, 100); node4 = NetworkUtils.createNode(nodeid4, coord4); network.addNode(node4); Id<Node> depotId = Id.createNodeId("depot"); Coord depotCoord = new Coord(100, 0); depot = NetworkUtils.createNode(depotId, depotCoord); network.addNode(depot); Id<Link> idUp = Id.createLinkId("linkUp"); linkUp = NetworkUtils.createLink(idUp, node1, node2, network, length, freespeed, capacity, lanes); Id<Link> idRight = Id.createLinkId("linkRight"); linkRight = NetworkUtils.createLink(idRight, node2, node3, network, length, freespeed, capacity, lanes); Id<Link> idDown = Id.createLinkId("linkDown"); linkDown = NetworkUtils.createLink(idDown, node3, node4, network, length, freespeed, capacity, lanes); Id<Link> idLeft = Id.createLinkId("linkLeft"); linkLeft = NetworkUtils.createLink(idLeft, node4, node1, network, length, freespeed, capacity, lanes); Id<Link> iddepotIn = Id.createLinkId("linkDepotIn"); linkDepotIn = NetworkUtils.createLink(iddepotIn, node1, depot, network, length, freespeed, capacity, lanes); Id<Link> iddepotOut = Id.createLinkId("linkDepotOut"); linkDepotOut = NetworkUtils.createLink(iddepotOut, depot, node1, network, length, freespeed, capacity, lanes); network.addLink(linkUp); network.addLink(linkRight); network.addLink(linkDown); network.addLink(linkLeft); network.addLink(linkDepotIn); network.addLink(linkDepotOut); avRequest1 = new AmodeusRequest(Id.create("p1", Request.class), null, linkUp, linkDown, 0.0, AmodeusModeConfig.DEFAULT_MODE, null); avRequest2 = new AmodeusRequest(Id.create("p2", Request.class), null, linkRight, linkLeft, 0.0, AmodeusModeConfig.DEFAULT_MODE, null); avRequest3 = new AmodeusRequest(Id.create("p3", Request.class), null, linkRight, linkUp, 0.0, AmodeusModeConfig.DEFAULT_MODE, null); avRequest4 = new AmodeusRequest(Id.create("p4", Request.class), null, linkRight, linkDown, 0.0, AmodeusModeConfig.DEFAULT_MODE, null); avRequest5 = new AmodeusRequest(Id.create("p5", Request.class), null, linkUp, linkRight, 0.0, AmodeusModeConfig.DEFAULT_MODE, null); avRequest6 = new AmodeusRequest(Id.create("p6", Request.class), null, linkUp, linkLeft, 0.0, AmodeusModeConfig.DEFAULT_MODE, null); avRequest7 = new AmodeusRequest(Id.create("p7", Request.class), null, linkRight, linkLeft, 0.0, AmodeusModeConfig.DEFAULT_MODE, null); avRequestDepotOut = new AmodeusRequest(Id.create("depotRequestOut", Request.class), null, linkDepotOut, linkDepotOut, 0.0, AmodeusModeConfig.DEFAULT_MODE, null); avRequestDepotIn = new AmodeusRequest(Id.create("depotRequestIn", Request.class), null, linkDepotIn, linkDepotIn, 0.0, AmodeusModeConfig.DEFAULT_MODE, null); }
Example 20
Source File: AmodeusIdentifiers.java From amodeus with GNU General Public License v2.0 | 4 votes |
private static Id<DvrpVehicle> createVehicleId(String mode, String suffix) { return Id.create(String.format("amodeus:%s:%s", mode, suffix), DvrpVehicle.class); }