@Override public Trip findTrip(Leg prevLeg, double earliestDepartureTime_s) { ExperimentalTransitRoute route = (ExperimentalTransitRoute) prevLeg.getRoute(); Id accessStopId = route.getAccessStopId(); Id egressStopId = route.getEgressStopId(); Tuple<Double, Double> routeTravelTime = transitPerformance.getRouteTravelTime(route.getLineId(), route.getRouteId(), accessStopId, egressStopId, earliestDepartureTime_s); final double accessTime_s = earliestDepartureTime_s + routeTravelTime.getFirst(); final double egressTime_s = accessTime_s + routeTravelTime.getSecond(); return new Trip(null, accessTime_s, egressTime_s); } }
public void testSetRouteDescription_NonPtRoute() { ExperimentalTransitRoute route = new ExperimentalTransitRoute(null, null); route.setRouteDescription("23 42 7 21"); assertNull(route.getAccessStopId()); assertNull(route.getLineId()); assertNull(route.getEgressStopId()); assertEquals("23 42 7 21", route.getRouteDescription()); } }
if (baseTrip.size() > 1) { // at least one pt leg available ExperimentalTransitRoute tRoute = (ExperimentalTransitRoute) baseTrip.get(1).getRoute(); firstToFacility = this.transitSchedule.getFacilities().get(tRoute.getAccessStopId()); } else { firstToFacility = toFacility; if (leg.getRoute() instanceof ExperimentalTransitRoute) { ExperimentalTransitRoute tRoute = (ExperimentalTransitRoute) leg.getRoute(); tRoute.setTravelTime(leg.getTravelTime()); tRoute.setDistance(RouteUtils.calcDistance(tRoute, transitSchedule, network)); Activity act = PopulationUtils.createActivityFromCoordAndLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, this.transitSchedule.getFacilities().get(tRoute.getAccessStopId()).getCoord(), tRoute.getStartLinkId()); act.setMaximumDuration(0.0); trip.add(act); nextCoord = this.transitSchedule.getFacilities().get(tRoute.getEgressStopId()).getCoord(); } else { Facility lastFromFacility = this.transitSchedule.getFacilities().get(tRoute.getEgressStopId());
@Override public Trip findTrip(Leg prevLeg, double earliestDepartureTime_s) { ExperimentalTransitRoute route = (ExperimentalTransitRoute) prevLeg.getRoute(); TransitLine line = this.transitLines.get(route.getLineId()); TransitRoute transitRoute = line.getRoutes().get(route.getRouteId()); final double accessTime_s = earliestDepartureTime_s + this.waitTimes.getRouteStopWaitTime(route.getLineId(), transitRoute.getId(), route.getAccessStopId(), earliestDepartureTime_s); final double egressTime_s = accessTime_s + this.findTransitTravelTime(route, accessTime_s); return new Trip(null, accessTime_s, egressTime_s); }
@Override public final boolean getEnterTransitRoute(final TransitLine line, final TransitRoute transitRoute, final List<TransitRouteStop> stopsToCome, TransitVehicle transitVehicle) { ExperimentalTransitRoute route = (ExperimentalTransitRoute) basicAgentDelegate.getCurrentLeg().getRoute(); switch ( boardingAcceptance ) { case checkLineAndStop: return line.getId().equals(route.getLineId()) && containsId(stopsToCome, route.getEgressStopId()); case checkStopOnly: return containsId(stopsToCome, route.getEgressStopId()); default: throw new RuntimeException("not implemented"); } }
public void testInitializationLinks() { Link link1 = new FakeLink(Id.create(1, Link.class)); Link link2 = new FakeLink(Id.create(2, Link.class)); ExperimentalTransitRoute route = new ExperimentalTransitRoute(link1.getId(), link2.getId()); assertEquals(link1.getId(), route.getStartLinkId()); assertEquals(link2.getId(), route.getEndLinkId()); assertNull(route.getAccessStopId()); assertNull(route.getLineId()); assertNull(route.getEgressStopId()); }
@Override public void handleEvent(PersonStuckEvent event) { Double startWaitingTime = agentsWaitingData.get(event.getPersonId()); if(startWaitingTime!=null) { int legs = 0, currentLeg = agentsCurrentLeg.get(event.getPersonId()); PLAN_ELEMENTS: for(PlanElement planElement:population.getPersons().get(event.getPersonId()).getSelectedPlan().getPlanElements()) if(planElement instanceof Leg) { if(currentLeg==legs) { Route route = ((Leg)planElement).getRoute(); ExperimentalTransitRoute eRoute = (ExperimentalTransitRoute) new ExperimentalTransitRouteFactory().createRoute(route.getStartLinkId(), route.getEndLinkId()); eRoute.setStartLinkId(route.getStartLinkId()); eRoute.setEndLinkId(route.getEndLinkId()); eRoute.setRouteDescription(route.getRouteDescription()); WaitTimeData data = waitTimes.get(new Tuple<Id<TransitLine>, Id<TransitRoute>>(eRoute.getLineId(), eRoute.getRouteId())).get(eRoute.getAccessStopId()); if(data!=null) data.addWaitTime((int) (startWaitingTime/timeSlot), event.getTime()-startWaitingTime); agentsWaitingData.remove(event.getPersonId()); break PLAN_ELEMENTS; } else legs++; } } }
@Override public Route createRoute(final Id<Link> startLinkId, final Id<Link> endLinkId) { return new ExperimentalTransitRoute(startLinkId, endLinkId); }
/** * In rare cases, Dijkstra may choose to go along two walk links to get from one location to another. * Test, that still only one walk leg with the correct start and end points/links is returned. */ @Test public void testDoubleWalk() { WalkFixture f = new WalkFixture(); f.routerConfig.setMarginalUtilityOfTravelTimePt_utl_s(-1.0 / 3600.0 - 6.0/3600.0); f.routerConfig.setUtilityOfLineSwitch_utl(0.2); // must be relatively low in this example, otherwise it's cheaper to walk the whole distance... TransitRouter router = createTransitRouter(f.schedule, f.routerConfig, routerType); List<Leg> legs = router.calcRoute(new FakeFacility(f.coord1), new FakeFacility(f.coord7), 990, null); assertEquals(5, legs.size()); assertEquals(TransportMode.transit_walk, legs.get(0).getMode()); assertEquals(TransportMode.pt, legs.get(1).getMode()); assertEquals(f.stop1.getId(), ((ExperimentalTransitRoute) legs.get(1).getRoute()).getAccessStopId()); assertEquals(f.stop2.getId(), ((ExperimentalTransitRoute) legs.get(1).getRoute()).getEgressStopId()); assertEquals(f.stop1.getLinkId(), legs.get(1).getRoute().getStartLinkId()); assertEquals(f.stop2.getLinkId(), legs.get(1).getRoute().getEndLinkId()); assertEquals(TransportMode.transit_walk, legs.get(2).getMode()); assertEquals(TransportMode.pt, legs.get(3).getMode()); assertEquals(f.stop2.getLinkId(), legs.get(2).getRoute().getStartLinkId()); assertEquals(f.stop6.getLinkId(), legs.get(2).getRoute().getEndLinkId()); assertEquals(f.stop6.getId(), ((ExperimentalTransitRoute) legs.get(3).getRoute()).getAccessStopId()); assertEquals(f.stop7.getId(), ((ExperimentalTransitRoute) legs.get(3).getRoute()).getEgressStopId()); assertEquals(f.stop6.getLinkId(), legs.get(3).getRoute().getStartLinkId()); assertEquals(f.stop7.getLinkId(), legs.get(3).getRoute().getEndLinkId()); assertEquals(TransportMode.transit_walk, legs.get(4).getMode()); }
public void testLinks() { Link link1 = new FakeLink(Id.create(1, Link.class)); Link link2 = new FakeLink(Id.create(2, Link.class)); Link link3 = new FakeLink(Id.create(3, Link.class)); Link link4 = new FakeLink(Id.create(4, Link.class)); ExperimentalTransitRoute route = new ExperimentalTransitRoute(link1.getId(), link2.getId()); assertEquals(link1.getId(), route.getStartLinkId()); assertEquals(link2.getId(), route.getEndLinkId()); route.setStartLinkId(link3.getId()); route.setEndLinkId(link4.getId()); assertEquals(link3.getId(), route.getStartLinkId()); assertEquals(link4.getId(), route.getEndLinkId()); }
public void testTravelTime() { ExperimentalTransitRoute route = new ExperimentalTransitRoute(null, null); assertEquals(Time.UNDEFINED_TIME, route.getTravelTime(), MatsimTestCase.EPSILON); double traveltime = 987.65; route.setTravelTime(traveltime); assertEquals(traveltime, route.getTravelTime(), MatsimTestCase.EPSILON); }
@Override public final Id<TransitStopFacility> getDesiredDestinationStopId() { ExperimentalTransitRoute route = (ExperimentalTransitRoute) basicAgentDelegate.getCurrentLeg().getRoute(); return route.getEgressStopId(); } @Override
assert egressFacility!=null ; ExperimentalTransitRoute experimentalTransitRoute = new ExperimentalTransitRoute( accessFacility, line, route, egressFacility); experimentalTransitRoute.setTravelTime(travelTime); experimentalTransitRoute.setDistance(RouteUtils.calcDistance(experimentalTransitRoute, transitSchedule, network)); leg.setRoute(experimentalTransitRoute); } else {
private Leg createTransitLeg(RouteSegment routeSegment) { Leg leg = PopulationUtils.createLeg(TransportMode.pt); TransitStopFacility accessStop = routeSegment.getFromStop(); TransitStopFacility egressStop = routeSegment.getToStop(); ExperimentalTransitRoute ptRoute = new ExperimentalTransitRoute(accessStop, egressStop, routeSegment.getLineTaken(), routeSegment.getRouteTaken()); ptRoute.setTravelTime(routeSegment.travelTime); leg.setRoute(ptRoute); leg.setTravelTime(routeSegment.getTravelTime()); return leg; }
@Override public Id<TransitStopFacility> getDesiredAccessStopId() { Leg leg = getCurrentLeg(); if (!(leg.getRoute() instanceof ExperimentalTransitRoute)) { log.error("pt-leg has no TransitRoute. Removing agent from simulation. Agent " + getId().toString()); log.info("route: " + leg.getRoute().getClass().getCanonicalName() + " " + leg.getRoute().getRouteDescription()); return null; } else { ExperimentalTransitRoute route = (ExperimentalTransitRoute) leg.getRoute(); return route.getAccessStopId(); } }
assertEquals(TransportMode.transit_walk, legs.get(0).getMode()); assertEquals(TransportMode.pt, legs.get(1).getMode()); assertEquals(f.redLine.getId(), ((ExperimentalTransitRoute) legs.get(1).getRoute()).getLineId()); assertEquals(TransportMode.transit_walk, legs.get(2).getMode()); assertEquals(TransportMode.pt, legs.get(3).getMode()); assertEquals(f.blueLine.getId(), ((ExperimentalTransitRoute) legs.get(3).getRoute()).getLineId()); assertEquals(TransportMode.transit_walk, legs.get(4).getMode()); assertEquals(TransportMode.transit_walk, legs.get(0).getMode()); assertEquals(TransportMode.pt, legs.get(1).getMode()); assertEquals(f.blueLine.getId(), ((ExperimentalTransitRoute) legs.get(1).getRoute()).getLineId()); assertEquals(TransportMode.transit_walk, legs.get(2).getMode());
String planIdString = route.getRouteId().toString(); Id<PPlan> pId = Id.create(planIdString, PPlan.class);
public void testInitializationStops() { TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitStopFacility stop1 = builder.createTransitStopFacility(Id.create(1, TransitStopFacility.class), new Coord(5, 11), false); TransitStopFacility stop2 = builder.createTransitStopFacility(Id.create(2, TransitStopFacility.class), new Coord(18, 7), false); Link link1 = new FakeLink(Id.create(3, Link.class)); Link link2 = new FakeLink(Id.create(4, Link.class)); stop1.setLinkId(link1.getId()); stop2.setLinkId(link2.getId()); TransitLine line = builder.createTransitLine(Id.create(5, TransitLine.class)); TransitRoute tRoute = builder.createTransitRoute(Id.create(6, TransitRoute.class), null, Collections.<TransitRouteStop>emptyList(), "bus"); ExperimentalTransitRoute route = new ExperimentalTransitRoute(stop1, line, tRoute, stop2); assertEquals(stop1.getId(), route.getAccessStopId()); assertEquals(line.getId(), route.getLineId()); assertEquals(tRoute.getId(), route.getRouteId()); assertEquals(stop2.getId(), route.getEgressStopId()); assertEquals(link1.getId(), route.getStartLinkId()); assertEquals(link2.getId(), route.getEndLinkId()); }
@Override public void handleEvent(PersonEntersVehicleEvent event) { Double startWaitingTime = agentsWaitingData.get(event.getPersonId()); if(startWaitingTime!=null) { int legs = 0, currentLeg = agentsCurrentLeg.get(event.getPersonId()); PLAN_ELEMENTS: for(PlanElement planElement:population.getPersons().get(event.getPersonId()).getSelectedPlan().getPlanElements()) if(planElement instanceof Leg) { if(currentLeg==legs) { Route route = (((Leg)planElement).getRoute()); ExperimentalTransitRoute eRoute = (ExperimentalTransitRoute) new ExperimentalTransitRouteFactory().createRoute(route.getStartLinkId(), route.getEndLinkId()); eRoute.setStartLinkId(route.getStartLinkId()); eRoute.setEndLinkId(route.getEndLinkId()); eRoute.setRouteDescription(route.getRouteDescription()); WaitTimeData data = waitTimes.get(new Tuple<Id<TransitLine>, Id<TransitRoute>>(eRoute.getLineId(), eRoute.getRouteId())).get(eRoute.getAccessStopId()); data.addWaitTime((int) (startWaitingTime/timeSlot), event.getTime()-startWaitingTime); agentsWaitingData.remove(event.getPersonId()); break PLAN_ELEMENTS; } else legs++; } } }
private void createPopulation() { TransitSchedule schedule = this.scenario.getTransitSchedule(); Population population = this.scenario.getPopulation(); PopulationFactory pb = population.getFactory(); TransitStopFacility[] stops = schedule.getFacilities().values().toArray(new TransitStopFacility[schedule.getFacilities().size()]); TransitLine tLine = schedule.getTransitLines().get(Id.create(1, TransitLine.class)); TransitRoute tRoute = tLine.getRoutes().get(Id.create(1, TransitRoute.class)); TransitStopFacility lastStop = schedule.getFacilities().get(Id.create(stops.length - 1, TransitStopFacility.class)); for (int i = 0; i < stops.length; i++) { TransitStopFacility stop = stops[i]; if (stop == lastStop) { continue; } for (int j = 0; j < nOfAgentsPerStop; j++) { Person person = pb.createPerson(Id.create(Integer.toString(i * nOfAgentsPerStop + j), Person.class)); Plan plan = pb.createPlan(); Activity act1 = pb.createActivityFromLinkId("home", stop.getLinkId()); act1.setEndTime(departureTime + j * agentInterval); Leg leg = pb.createLeg(TransportMode.pt); leg.setRoute(new ExperimentalTransitRoute(stop, tLine, tRoute, lastStop)); Activity act2 = pb.createActivityFromLinkId("work", Id.create(nOfLinks - 1, Link.class)); population.addPerson(person); person.addPlan(plan); person.setSelectedPlan(plan); plan.addActivity(act1); plan.addLeg(leg); plan.addActivity(act2); } } }