protected double longerStopTimeIfWeAreAheadOfSchedule(final double now, final double stopTime) { if ((this.nextStop.isAwaitDepartureTime()) && (this.nextStop.getDepartureOffset() != Time.UNDEFINED_TIME)) { double earliestDepTime = getActivityEndTime() + this.nextStop.getDepartureOffset(); if (now + stopTime < earliestDepTime) { return earliestDepTime - now; } } return stopTime; }
public double getNextDepartureTime(final TransitRoute route, final TransitRouteStop stop, final double depTime) { double earliestDepartureTimeAtTerminus = depTime - stop.getDepartureOffset(); bestDepartureTime += stop.getDepartureOffset();
public double getVehArrivalTime(final Link link, final double now){ if ((link == this.previousWaitLink) && (now == this.previousWaitTime)) { return this.cachedVehArrivalTime; } this.previousWaitLink = link; this.previousWaitTime = now; //first find out vehicle arrival time to fromStop according to transit schedule TransitRouterNetworkLink wrapped = (TransitRouterNetworkLink) link; if (wrapped.getRoute() == null) { throw new RuntimeException("should not happen") ; } TransitRouteStop fromStop = wrapped.fromNode.stop; double nextDepartureTime = preparedTransitSchedule.getNextDepartureTime(wrapped.getRoute(), fromStop, now); double fromStopArrivalOffset = (fromStop.getArrivalOffset() != Time.UNDEFINED_TIME) ? fromStop.getArrivalOffset() : fromStop.getDepartureOffset(); double vehWaitAtStopTime = fromStop.getDepartureOffset() - fromStopArrivalOffset; //time in which the veh stops at station double vehArrivalTime = nextDepartureTime - vehWaitAtStopTime; cachedVehArrivalTime = vehArrivalTime ; return vehArrivalTime ; }
private void processEventVehicleArrives(final TransitStopFacility stop, final double now) { if (this.currentStop == null) { this.currentStop = this.nextStop; double delay = now - this.getDeparture().getDepartureTime(); if (! ( Double.isNaN(this.currentStop.getArrivalOffset()) && Double.isInfinite(this.currentStop.getArrivalOffset())) ){ delay = delay - this.currentStop.getArrivalOffset(); } else if (! (Double.isNaN(this.currentStop.getDepartureOffset()) && Double.isInfinite(this.currentStop.getDepartureOffset()))) { delay = delay - this.currentStop.getDepartureOffset(); } else { log.warn("Could not calculate delay!"); } eventsManager.processEvent(new VehicleArrivesAtFacilityEvent(now, this.vehicle.getVehicle().getId(), stop.getId(), delay)); } }
private void writeRouteProfile(final List<TransitRouteStop> stops) throws UncheckedIOException { this.writeStartTag(Constants.ROUTE_PROFILE, null); // optimization: only create one List for multiple departures List<Tuple<String, String>> attributes = new ArrayList<>(4); for (TransitRouteStop stop : stops) { attributes.clear(); attributes.add(createTuple(Constants.REF_ID, stop.getStopFacility().getId().toString())); if (stop.getArrivalOffset() != Time.UNDEFINED_TIME) { attributes.add(createTimeTuple(Constants.ARRIVAL_OFFSET, stop.getArrivalOffset())); } if (stop.getDepartureOffset() != Time.UNDEFINED_TIME) { attributes.add(createTimeTuple(Constants.DEPARTURE_OFFSET, stop.getDepartureOffset())); } attributes.add(createTuple(Constants.AWAIT_DEPARTURE, String.valueOf(stop.isAwaitDepartureTime()))); this.writeStartTag(Constants.STOP, attributes, true); } this.writeEndTag(Constants.ROUTE_PROFILE); }
private void writeRouteProfile(final List<TransitRouteStop> stops) throws UncheckedIOException { this.writeStartTag(Constants.ROUTE_PROFILE, null); // optimization: only create one List for multiple departures List<Tuple<String, String>> attributes = new ArrayList<Tuple<String, String>>(4); for (TransitRouteStop stop : stops) { attributes.clear(); attributes.add(this.createTuple(Constants.REF_ID, stop.getStopFacility().getId().toString())); if (stop.getArrivalOffset() != Time.UNDEFINED_TIME) { attributes.add(this.createTimeTuple(Constants.ARRIVAL_OFFSET, stop.getArrivalOffset())); } if (stop.getDepartureOffset() != Time.UNDEFINED_TIME) { attributes.add(this.createTimeTuple(Constants.DEPARTURE_OFFSET, stop.getDepartureOffset())); } attributes.add(this.createTuple(Constants.AWAIT_DEPARTURE, String.valueOf(stop.isAwaitDepartureTime()))); this.writeStartTag(Constants.STOP, attributes, true); } this.writeEndTag(Constants.ROUTE_PROFILE); }
private double getDepartureOffsetFromRoute(TransitRoute transitRoute, Id<TransitStopFacility> accessStopId) { for (TransitRouteStop routeStop : transitRoute.getStops()) { if (accessStopId.equals(routeStop.getStopFacility().getId())) { return routeStop.getDepartureOffset(); } } log.error("Stop " + accessStopId + " not found in route " + transitRoute.getId()); // returning what??? return -1.0; }
public StopStopTimeCalculatorTuple(final TransitSchedule transitSchedule, final int timeSlot, final int totalTime) { this.timeSlot = timeSlot; Map<Tuple<Id<TransitStopFacility>, Id<TransitStopFacility>>, Integer> numObservations = new HashMap<Tuple<Id<TransitStopFacility>, Id<TransitStopFacility>>, Integer>(); for(TransitLine line:transitSchedule.getTransitLines().values()) for(TransitRoute route:line.getRoutes().values()) { for(int s=0; s<route.getStops().size()-1; s++) { Tuple<Id<TransitStopFacility>, Id<TransitStopFacility>> key = new Tuple<Id<TransitStopFacility>, Id<TransitStopFacility>>(route.getStops().get(s).getStopFacility().getId(), route.getStops().get(s+1).getStopFacility().getId()); StopStopTimeData data = stopStopTimes.get(key); if(data==null) stopStopTimes.put(key, new StopStopTimeDataArray((int) (totalTime/timeSlot)+1)); Double sTime = scheduledStopStopTimes.get(key); Integer num = numObservations.get(key); if(sTime==null) { sTime = 0.0; scheduledStopStopTimes.put(key, sTime); num = 0; numObservations.put(key, num); } scheduledStopStopTimes.put(key, (num*sTime+route.getStops().get(s+1).getArrivalOffset()-route.getStops().get(s).getDepartureOffset())/++num); numObservations.put(key, num); } for(Departure departure:route.getDepartures().values()) vehicleIds.add(departure.getVehicleId()); } System.out.println(stopStopTimes.size()); } public static void main(String[] args) {
facilityOffsets.add(stop.getDepartureOffset());
SORTED_DEPARTURES: for (double departure : sortedDepartures) { double arrivalTime = departure + (stop.getArrivalOffset() != Time.UNDEFINED_TIME ? stop.getArrivalOffset() : stop.getDepartureOffset()); if (arrivalTime >= endTime) { cacheWaitTimes[i] = arrivalTime - endTime; cacheWaitTimes[i] = sortedDepartures[0] + 24 * 3600 + (stop.getArrivalOffset() != Time.UNDEFINED_TIME ? stop.getArrivalOffset() : stop.getDepartureOffset()) - endTime;
int headway = (int) (transitRoute.getStops().get(transitRoute.getStops().size() - 1).getDepartureOffset() + this.driverRestTime) / numberOfVehicles; for (int i = 0; i < numberOfVehicles; i++) { for (double j = startTime + i * headway; j < endTime; ) { departure.setVehicleId(Id.create(transitRoute.getId().toString() + "-" + i, Vehicle.class)); transitRoute.addDeparture(departure); j += transitRoute.getStops().get(transitRoute.getStops().size() - 1).getDepartureOffset() + this.driverRestTime; n++;
double arrivalOffset = (toStop.getArrivalOffset() != Time.UNDEFINED_TIME) ? toStop.getArrivalOffset() : toStop.getDepartureOffset(); double time2 = (bestDepartureTime - time) + (arrivalOffset - fromStop.getDepartureOffset()); if (time2 < 0) {
SORTED_DEPARTURES: for(double departure:sortedDepartures) { double arrivalTime = departure+(stop.getArrivalOffset()!=Time.UNDEFINED_TIME?stop.getArrivalOffset():stop.getDepartureOffset()); if(arrivalTime>=endTime) { cacheWaitTimes[i] = arrivalTime-endTime; cacheWaitTimes[i] = sortedDepartures[0]+24*3600+(stop.getArrivalOffset()!=Time.UNDEFINED_TIME?stop.getArrivalOffset():stop.getDepartureOffset())-endTime;
if (stop.getDepartureOffset() == Time.UNDEFINED_TIME) { result.addError("Transit line " + line.getId() + ", route " + route.getId() + ": The first stop does not contain any departure offset."); if (stop.getDepartureOffset() == Time.UNDEFINED_TIME) { result.addError("Transit line " + line.getId() + ", route " + route.getId() + ": Stop " + i + " does not contain any departure offset.");
private TransitLine createTransitLine(Id<TransitLine> lineId, double startTime, double endTime, int numberOfVehicles, ArrayList<TransitStopFacility> stopsToBeServed, Id<TransitRoute> routeId){ // initialize TransitLine line = this.scheduleWithStopsOnly.getFactory().createTransitLine(lineId); routeId = Id.create(lineId + "-" + routeId, TransitRoute.class); TransitRoute transitRoute = createRoute(routeId, stopsToBeServed); // register route line.addRoute(transitRoute); // add departures int n = 0; /* After finishing one tour, vehicles wait the driver rest time and then start the next tour immediately. * So, headway is a function of the number of vehicles and the time spent on one tour of the TransitRoute. */ int headway = (int) (transitRoute.getStops().get(transitRoute.getStops().size() - 1).getDepartureOffset() + this.driverRestTime) / numberOfVehicles; for (int i = 0; i < numberOfVehicles; i++) { for (double j = startTime + i * headway; j <= endTime; ) { Departure departure = this.scheduleWithStopsOnly.getFactory().createDeparture(Id.create(n, Departure.class), j); departure.setVehicleId(Id.create(transitRoute.getId().toString() + "-" + i, Vehicle.class)); transitRoute.addDeparture(departure); j += transitRoute.getStops().get(transitRoute.getStops().size() - 1).getDepartureOffset() + this.driverRestTime; n++; } } // log.info("added " + n + " departures"); return line; }
private TransitLine createTransitLine(Id<TransitLine> pLineId, double startTime, double endTime, int numberOfVehicles, ArrayList<TransitStopFacility> stopsToBeServed, Id<TransitRoute> routeId){ // initialize TransitLine line = this.scheduleWithStopsOnly.getFactory().createTransitLine(pLineId); routeId = Id.create(pLineId + "-" + routeId, TransitRoute.class); TransitRoute transitRoute = createRoute(routeId, stopsToBeServed); // register route line.addRoute(transitRoute); // add departures int n = 0; /* After finishing one tour, vehicles wait the driver rest time and then start the next tour immediately. * So, headway is a function of the number of vehicles and the time spent on one tour of the TransitRoute. */ int headway = (int) (transitRoute.getStops().get(transitRoute.getStops().size() - 1).getDepartureOffset() + this.driverRestTime) / numberOfVehicles; for (int i = 0; i < numberOfVehicles; i++) { for (double j = startTime + i * headway; j <= endTime; ) { Departure departure = this.scheduleWithStopsOnly.getFactory().createDeparture(Id.create(n, Departure.class), j); departure.setVehicleId(Id.create(transitRoute.getId().toString() + "-" + i, Vehicle.class)); transitRoute.addDeparture(departure); j += transitRoute.getStops().get(transitRoute.getStops().size() - 1).getDepartureOffset() + this.driverRestTime; n++; } } // log.info("added " + n + " departures"); return line; }
private void depart(final double now) { double delay = now - this.getDeparture().getDepartureTime(); if (this.isBadDouble(this.getDeparture().getDepartureTime())){ //this is the case if the next stop is null delay = 0; } if (! this.isBadDouble(this.currentStop.getDepartureOffset())){ delay = delay - this.currentStop.getDepartureOffset(); } else if (! this.isBadDouble(this.currentStop.getArrivalOffset()) ){ delay = delay - this.currentStop.getArrivalOffset(); } else { log.warn("Could not calculate delay!"); } eventsManager.processEvent(new VehicleDepartsAtFacilityEvent(now, this.vehicle.getVehicle().getId(), this.currentStop.getStopFacility().getId(), delay)); this.nextStop = (stopIterator.hasNext() ? stopIterator.next() : null); if(this.nextStop == null) { assertVehicleIsEmpty(); } this.currentStop = null; }
public static ValidationResult validateAllStopsExist(final TransitSchedule schedule) { ValidationResult result = new ValidationResult(); for (TransitLine line : schedule.getTransitLines().values()) { for (TransitRoute route : line.getRoutes().values()) { for (TransitRouteStop stop : route.getStops()) { if (stop.getStopFacility() == null) { result.addIssue(new ValidationResult.ValidationIssue(ValidationResult.Severity.ERROR, "Transit line " + line.getId() + ", route " + route.getId() + " contains a stop (dep-offset=" + stop.getDepartureOffset() + ") without stop-facility. Most likely, a wrong id was specified in the file.", ValidationResult.Type.HAS_MISSING_STOP_FACILITY, Collections.singletonList(route.getId()))); } else if (schedule.getFacilities().get(stop.getStopFacility().getId()) == null) { result.addIssue(new ValidationResult.ValidationIssue(ValidationResult.Severity.ERROR, "Transit line " + line.getId() + ", route " + route.getId() + " contains a stop (stop-facility " + stop.getStopFacility().getId() + ") that is not contained in the list of all stop facilities.", ValidationResult.Type.HAS_MISSING_STOP_FACILITY, Collections.singletonList(route.getId()))); } } } } return result; }
public void testInitialization() { TransitStopFacility stopFacility = new TransitStopFacilityImpl(Id.create(1, TransitStopFacility.class), new Coord((double) 2, (double) 3), false); double arrivalDelay = 4; double departureDelay = 5; TransitRouteStop routeStop = createTransitRouteStop(stopFacility, arrivalDelay, departureDelay); assertEquals(stopFacility, routeStop.getStopFacility()); assertEquals(arrivalDelay, routeStop.getArrivalOffset(), EPSILON); assertEquals(departureDelay, routeStop.getDepartureOffset(), EPSILON); }
@Test public void testCreateTransitRouteStop() { TransitScheduleFactory builder = createTransitScheduleBuilder(); TransitStopFacility stopFacility = new TransitStopFacilityImpl(Id.create(5, TransitStopFacility.class), new Coord((double) 6, (double) 6), false); double arrivalOffset = 23; double departureOffset = 42; TransitRouteStop stop = builder.createTransitRouteStop(stopFacility, 23, 42); Assert.assertEquals(stopFacility, stop.getStopFacility()); Assert.assertEquals(arrivalOffset, stop.getArrivalOffset(), MatsimTestUtils.EPSILON); Assert.assertEquals(departureOffset, stop.getDepartureOffset(), MatsimTestUtils.EPSILON); }