private final void createVehicleLinkSpeedAttributes() { for (TransitLine transitLine : scenario.getTransitSchedule().getTransitLines().values()) { for (TransitRoute transitRoute : transitLine.getRoutes().values()) { Set<Id> vehIds = new HashSet<Id>(); for (Departure departure : transitRoute.getDepartures().values()) { vehIds.add(departure.getVehicleId()); } Iterator<TransitRouteStop> iterator = transitRoute.getStops().iterator(); double departure = iterator.next().getDepartureOffset(); while (iterator.hasNext()) { TransitRouteStop routeStop = iterator.next(); double arrival = routeStop.getArrivalOffset(); Link link = scenario.getNetwork().getLinks().get(routeStop.getStopFacility().getLinkId()); double speed = link.getLength() / (arrival - departure); if (speed >= 200.0) { System.out.println( "line=" + transitLine.getId() + ";route=" + transitRoute.getId() + "stop=" + routeStop.getStopFacility().getId() + ": lLenth=" + link.getLength() + ";arr=" + arrival + ";dep=" + departure + ""); } for (Id vehId : vehIds) { this.vehicleAttributes.putAttribute(vehId.toString(), link.getId().toString(), speed); } departure = routeStop.getDepartureOffset(); } } } }
private void writeVehicles(String vehiclesOutFile) { VehiclesFactory vehFactory = this.veh.getFactory(); VehicleType vehType = vehFactory.createVehicleType(Id.create("defaultTransitVehicleType", VehicleType.class)); VehicleCapacity capacity = new VehicleCapacityImpl(); capacity.setSeats(Integer.valueOf(8)); capacity.setStandingRoom(Integer.valueOf(0)); vehType.setCapacity(capacity); this.veh.addVehicleType(vehType); for (TransitLine line : this.tS.getTransitLines().values()) { for (TransitRoute route : line.getRoutes().values()) { for (Departure departure : route.getDepartures().values()) { Vehicle vehicle = vehFactory.createVehicle(departure.getVehicleId(), vehType); this.veh.addVehicle(vehicle); } } } VehicleWriterV1 writer = new VehicleWriterV1(this.veh); writer.writeFile(vehiclesOutFile); }
public TransitRouteData(Network network, TransitRoute transitRoute) { this.transportMode = transitRoute.getTransportMode(); this.firstDeparture = Double.MAX_VALUE; this.lastDeparture = -Double.MAX_VALUE; this.vehIds = new TreeSet<String>(); this.numberOfDepartures = 0; for (Departure departure : transitRoute.getDepartures().values()) { this.firstDeparture = Math.min(this.firstDeparture, departure.getDepartureTime()); this.lastDeparture = Math.max(this.lastDeparture, departure.getDepartureTime()); this.vehIds.add(departure.getVehicleId().toString()); this.numberOfDepartures++; } this.firstStop = transitRoute.getStops().get(0).getStopFacility(); this.lastStop = transitRoute.getStops().get(transitRoute.getStops().size() - 1).getStopFacility(); if (this.firstStop == this.lastStop) { // get the stop location of stop with the largest distance between first and last stop TransitStopFacility currentViaStop = null; double currentViaDistance = Double.NEGATIVE_INFINITY; for (TransitRouteStop stop : transitRoute.getStops()) { double distanceFirstPotentialVia = CoordUtils.calcDistance(this.firstStop.getCoord(), stop.getStopFacility().getCoord()); double distanceLastProtenialVia = CoordUtils.calcDistance(this.lastStop.getCoord(), stop.getStopFacility().getCoord()); double newDistance = Math.sqrt( Math.pow(distanceFirstPotentialVia, 2) + Math.pow(distanceLastProtenialVia, 2)); if (newDistance > currentViaDistance) { // this one is farther away - keep it currentViaStop = stop.getStopFacility(); currentViaDistance = newDistance; } } this.viaStop = currentViaStop; } else { // get the stop in the middle of the line this.viaStop = transitRoute.getStops().get((int) (transitRoute.getStops().size() / 2)).getStopFacility(); } // calculate the length of the route double distance = 0.0; double freeSpeedTravelTime = 0.0; for (Id<Link> linkId : transitRoute.getRoute().getLinkIds()) { Link link = network.getLinks().get(linkId); distance += link.getLength(); freeSpeedTravelTime += link.getLength() / link.getFreespeed(); } // add last link but not the first link Link link = network.getLinks().get(transitRoute.getRoute().getEndLinkId()); distance += link.getLength(); freeSpeedTravelTime += link.getLength() / link.getFreespeed(); this.distance = distance; this.freeSpeedTravelTime = freeSpeedTravelTime; this.travelTime = transitRoute.getStops().get(transitRoute.getStops().size() - 1).getArrivalOffset(); this.avgSpeed = this.distance / this.travelTime; }
public void createGraph(final String filename, final TransitRoute route) { HashMap<Id, Integer> stopIndex = new HashMap<Id, Integer>(); int idx = 0; for (TransitRouteStop stop : route.getStops()) { stopIndex.put(stop.getStopFacility().getId(), idx); idx++; } HashSet<Id> vehicles = new HashSet<Id>(); for (Departure dep : route.getDepartures().values()) { vehicles.add(dep.getVehicleId()); } XYSeriesCollection dataset = new XYSeriesCollection(); int numSeries = 0; double earliestTime = Double.POSITIVE_INFINITY; double latestTime = Double.NEGATIVE_INFINITY; for (Map.Entry<Id, List<Tuple<Id, Double>>> entry : this.positions.entrySet()) { if (vehicles.contains(entry.getKey())) { XYSeries series = new XYSeries("t", false, true); for (Tuple<Id, Double> pos : entry.getValue()) { Integer stopIdx = stopIndex.get(pos.getFirst()); if (stopIdx != null) { double time = pos.getSecond().doubleValue(); series.add(stopIdx.intValue(), time); if (time < earliestTime) { earliestTime = time; } if (time > latestTime) { latestTime = time; } } } dataset.addSeries(series); numSeries++; } } JFreeChart c = ChartFactory.createXYLineChart( "Route-Time Diagram, Route = " + route.getId(), "stops", "time", dataset, PlotOrientation.VERTICAL, false, // legend? false, // tooltips? false // URLs? ); c.setBackgroundPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f)); XYPlot p = (XYPlot) c.getPlot(); p.getRangeAxis().setInverted(true); p.getRangeAxis().setRange(earliestTime, latestTime); XYItemRenderer renderer = p.getRenderer(); for (int i = 0; i < numSeries; i++) { renderer.setSeriesPaint(i, Color.black); } try { ChartUtilities.saveChartAsPNG(new File(filename), c, 1024, 768, null, true, 9); } catch (IOException e) { e.printStackTrace(); } }