public ExperimentalTransitRoute(final TransitStopFacility accessFacility, final TransitStopFacility egressFacility, final Id<TransitLine> lineId, final Id<TransitRoute> routeId) { this(accessFacility.getLinkId(), egressFacility.getLinkId()); this.accessStopId = accessFacility.getId(); this.lineId = lineId; this.routeId = routeId; this.egressStopId = egressFacility.getId(); }
private CreateStopsForAllCarLinks(Network net, PConfigGroup pConfigGroup, TransitSchedule realTransitSchedule) { this.net = net; this.pConfigGroup = pConfigGroup; this.linkId2StopFacilityMap = new LinkedHashMap<>(); Set<Id<TransitStopFacility>> stopsWithoutLinkIds = new TreeSet<>(); if (realTransitSchedule != null) { for (TransitStopFacility stopFacility : realTransitSchedule.getFacilities().values()) { if (stopFacility.getLinkId() != null) { if (this.linkId2StopFacilityMap.get(stopFacility.getLinkId()) != null) { log.error("There is more than one stop registered on link " + stopFacility.getLinkId() + ". " + this.linkId2StopFacilityMap.get(stopFacility.getLinkId()).getId() + " stays registered as paratransit stop. Will ignore stop " + stopFacility.getId()); } else { this.linkId2StopFacilityMap.put(stopFacility.getLinkId(), stopFacility); } } else { stopsWithoutLinkIds.add(stopFacility.getId()); } } } if (stopsWithoutLinkIds.size() > 0) { log.warn("There are " + stopsWithoutLinkIds.size() + " stop facilities without link id, namely: " + stopsWithoutLinkIds.toString()); } }
@Override public double handleTransitStop(TransitStopFacility stop, double now, List<PTPassengerAgent> leavingPassengers, List<PTPassengerAgent> enteringPassengers, PassengerAccessEgress accessEgress, MobsimVehicle vehicle) { int cntEgress = leavingPassengers.size(); int cntAccess = enteringPassengers.size(); double stopTime = 0; if ((cntAccess > 0) || (cntEgress > 0)) { stopTime = cntAccess * 4 + cntEgress * 2; if (this.lastHandledStop != stop) { stopTime += 15.0; // add fixed amount of time for door-operations and similar stuff } for (PTPassengerAgent passenger : leavingPassengers) { accessEgress.handlePassengerLeaving(passenger, vehicle, stop.getLinkId() , now); } for (PTPassengerAgent passenger : enteringPassengers) { accessEgress.handlePassengerEntering(passenger, vehicle, stop.getId(), now); } } this.lastHandledStop = stop; return stopTime; }
public ComplexCircleScheduleProvider(TransitSchedule scheduleWithStopsOnly, Network network, RandomStopProvider randomStopProvider, double vehicleMaximumVelocity, double planningSpeedFactor, double driverRestTime, final String transportMode) { this.net = network; this.scheduleWithStopsOnly = scheduleWithStopsOnly; FreespeedTravelTimeAndDisutility tC = new FreespeedTravelTimeAndDisutility(-6.0, 0.0, 0.0); // Here, it may make sense to use the variable cost parameters given in the config. Ihab/Daniel may'14 this.routingAlgo = new DijkstraFactory().createPathCalculator(this.net, tC, tC); @SuppressWarnings("serial") Set<String> modes = new HashSet<String>(){{ // this is the networkmode and explicitly not the transportmode add(TransportMode.car); }}; ((Dijkstra)this.routingAlgo).setModeRestriction(modes); // register all stops by their corresponding link id this.linkId2StopFacilityMap = new LinkedHashMap<>(); for (TransitStopFacility stop : this.scheduleWithStopsOnly.getFacilities().values()) { if (stop.getLinkId() == null) { log.warn("There is a potential paratransit stop without a corresponding link id. Shouldn't be possible. Check stop " + stop.getId()); } else { this.linkId2StopFacilityMap.put(stop.getLinkId(), stop); } } this.randomStopProvider = randomStopProvider; this.vehicleMaximumVelocity = vehicleMaximumVelocity; this.planningSpeedFactor = planningSpeedFactor; this.driverRestTime = driverRestTime; this.transportMode = transportMode; }
private void writeTransitStops() throws UncheckedIOException { this.writeStartTag(Constants.TRANSIT_STOPS, null); List<Tuple<String, String>> attributes = new ArrayList<Tuple<String, String>>(5); for (TransitStopFacility stop : this.schedule.getFacilities().values()) { attributes.clear(); attributes.add(this.createTuple(Constants.ID, stop.getId().toString())); final Coord coord = coordinateTransformation.transform( stop.getCoord() ); attributes.add(this.createTuple("x", coord.getX())); attributes.add(this.createTuple("y", coord.getY())); if (stop.getLinkId() != null) { attributes.add(this.createTuple("linkRefId", stop.getLinkId().toString())); } if (stop.getName() != null) { attributes.add(this.createTuple("name", stop.getName())); } attributes.add(this.createTuple("isBlocking", stop.getIsBlockingLane())); this.writeStartTag(Constants.STOP_FACILITY, attributes, true); } this.writeEndTag(Constants.TRANSIT_STOPS); }
public TransitRouterNetworkLink(final Id<Link> id, final TransitRouterNetworkNode fromNode, final TransitRouterNetworkNode toNode, final TransitRoute route, final TransitLine line, Network network) { this.id = id; this.fromNode = fromNode; this.toNode = toNode; this.route = route; this.line = line; if(route==null) this.length = CoordUtils.calcEuclideanDistance(this.toNode.stop.getStopFacility().getCoord(), this.fromNode.stop.getStopFacility().getCoord()); else { this.length = 0; for(Id<Link> linkId:route.getRoute().getSubRoute(fromNode.stop.getStopFacility().getLinkId(), toNode.stop.getStopFacility().getLinkId()).getLinkIds()) this.length += network.getLinks().get(linkId).getLength(); this.length += network.getLinks().get(toNode.stop.getStopFacility().getLinkId()).getLength(); } }
@Override public void writeConstData(ByteBuffer out) throws IOException { out.putInt(this.schedule.getFacilities().size()); for (TransitStopFacility facility : this.schedule.getFacilities().values()) { ByteBufferUtils.putString(out, facility.getId().toString()); if (facility.getLinkId() != null) { // yyyy would most probably make sense to have something that generates coordinates for facilities Link link = this.network.getLinks().get( facility.getLinkId() ) ; if ( link==null ) { log.warn( " link not found; linkId: " + facility.getLinkId() ) ; ByteBufferUtils.putString(out,""); Point2D.Double point = OTFServerQuadTree.transform(facility.getCoord()); out.putDouble(point.getX()); out.putDouble(point.getY()); } else { ByteBufferUtils.putString(out, facility.getLinkId().toString()); AgentSnapshotInfo ps = agentSnapshotInfoFactory.createAgentSnapshotInfo(Id.create(facility.getId(), Person.class), link, 0.9*link.getLength(), 0) ; Point2D.Double point = OTFServerQuadTree.transform(new Coord(ps.getEasting(), ps.getNorthing())); out.putDouble(point.getX()) ; out.putDouble(point.getY()) ; } } else { ByteBufferUtils.putString(out,""); Point2D.Double point = OTFServerQuadTree.transform(facility.getCoord()); out.putDouble(point.getX()); out.putDouble(point.getY()); } } }
private void handleAgentPTDeparture(final MobsimAgent planAgent, Id<Link> linkId) { // this puts the agent into the transit stop. Id<TransitStopFacility> accessStopId = ((PTPassengerAgent) planAgent).getDesiredAccessStopId(); if (accessStopId == null) { // looks like this agent has a bad transit route, likely no // route could be calculated for it log.error("pt-agent doesn't know to what transit stop to go. Removing agent from simulation. Agent " + planAgent.getId().toString()); this.qSim.getAgentCounter().decLiving(); this.qSim.getAgentCounter().incLost(); return; } TransitStopFacility stop = this.schedule.getFacilities().get(accessStopId); if (stop.getLinkId() == null || stop.getLinkId().equals(linkId)) { double now = this.qSim.getSimTimer().getTimeOfDay(); this.agentTracker.addAgentToStop(now, (PTPassengerAgent) planAgent, stop.getId()); this.internalInterface.registerAdditionalAgentOnLink(planAgent) ; } else { throw new TransitAgentTriesToTeleportException("Agent "+planAgent.getId() + " tries to enter a transit stop at link "+stop.getLinkId()+" but really is at "+linkId+"!"); } }
@Override public void afterSim() { double now = this.qSim.getSimTimer().getTimeOfDay(); for (Entry<Id<TransitStopFacility>, List<PTPassengerAgent>> agentsAtStop : this.agentTracker.getAgentsAtStop().entrySet()) { TransitStopFacility stop = this.schedule.getFacilities().get(agentsAtStop.getKey()); for (PTPassengerAgent agent : agentsAtStop.getValue()) { this.qSim.getEventsManager().processEvent(new PersonStuckEvent( now, agent.getId(), stop.getLinkId(), ((MobsimAgent)agent).getMode())); this.qSim.getAgentCounter().decLiving(); this.qSim.getAgentCounter().incLost(); } } }
HandleTransitStopResult handleTransitStop(final double now, final QVehicle veh, final TransitDriverAgent transitDriver, Id<Link> linkId) { TransitStopFacility stop = transitDriver.getNextTransitStop(); if ((stop != null) && (stop.getLinkId().equals(linkId))) { double delay = transitDriver.handleTransitStop(stop, now); if (delay > 0.0) { veh.setEarliestLinkExitTime(now + delay); // (if the vehicle is not removed from the queue in the following lines, then this will effectively block the lane if (!stop.getIsBlockingLane()) { transitVehicleStopQueue.add(veh); // transit vehicle which is removed to the transit stop space return HandleTransitStopResult.accepted; } else { // transit vehicle which blocks its lane by getting its exit time increased return HandleTransitStopResult.rehandle; } } else { // transit vehicle which instantaneously delivered passangers return HandleTransitStopResult.rehandle; } } else { // transit vehicle which either arrives or continues driving return HandleTransitStopResult.continue_driving; } }
public TransitRouterNetworkTravelTimeAndDisutilityWW(final TransitRouterConfig config, Network network, TransitRouterNetworkWW routerNetwork, TravelTime travelTime, WaitTime waitTime, TravelTimeCalculatorConfigGroup tTConfigGroup, double startTime, double endTime, PreparedTransitSchedule preparedTransitSchedule) { super(config, preparedTransitSchedule); timeSlot = tTConfigGroup.getTraveltimeBinSize(); numSlots = (int) ((endTime-startTime)/timeSlot); for(TransitRouterNetworkWW.TransitRouterNetworkLink link:routerNetwork.getLinks().values()) if(link.route!=null) { double[] times = new double[numSlots]; for(int slot = 0; slot<numSlots; slot++) { double linksTime = travelTime.getLinkTravelTime(network.getLinks().get(link.fromNode.stop.getStopFacility().getLinkId()), startTime+slot*timeSlot, null, null); for(Id<Link> linkId:link.route.getRoute().getSubRoute(link.fromNode.stop.getStopFacility().getLinkId(), link.toNode.stop.getStopFacility().getLinkId()).getLinkIds()) linksTime += travelTime.getLinkTravelTime(network.getLinks().get(linkId), startTime+slot*timeSlot, null, null); times[slot] = linksTime; } linkTravelTimes.put(link.getId(), times); } else if(link.toNode.route!=null) { double[] times = new double[numSlots]; for(int slot = 0; slot<numSlots; slot++) times[slot] = waitTime.getRouteStopWaitTime(link.toNode.line.getId(), link.toNode.route.getId(), link.fromNode.stop.getStopFacility().getId(), startTime+slot*timeSlot); linkWaitingTimes.put(link.getId(), times); } } @Override
final boolean addTransitToStopQueue(final double now, final QVehicle veh, final Id<Link> linkId) { if (veh.getDriver() instanceof TransitDriverAgent) { TransitDriverAgent driver = (TransitDriverAgent) veh.getDriver(); while (true) { TransitStopFacility stop = driver.getNextTransitStop(); if ((stop != null) && (stop.getLinkId().equals(linkId))) { double delay = driver.handleTransitStop(stop, now); if (delay > 0.0) { // yy removing this condition makes at least one test fail. I still think we could discuss doing this. kai, jun'13 veh.setEarliestLinkExitTime(now + delay); // add it to the stop queue: vehicle that is not yet on the road will never block transitVehicleStopQueue.add(veh); return true; } } else { return false; } } } return false; }
public static ValidationResult validateUsedStopsHaveLinkId(final TransitSchedule schedule) { ValidationResult result = new ValidationResult(); for (TransitLine line : schedule.getTransitLines().values()) { for (TransitRoute route : line.getRoutes().values()) { for (TransitRouteStop stop : route.getStops()) { Id<Link> linkId = stop.getStopFacility().getLinkId(); if (linkId == null) { result.addIssue(new ValidationResult.ValidationIssue(ValidationResult.Severity.ERROR,"Transit Stop Facility " + stop.getStopFacility().getId() + " has no linkId, but is used by transit line " + line.getId() + ", route " + route.getId(), ValidationResult.Type.HAS_NO_LINK_REF, Collections.singleton(stop.getStopFacility().getId()))); } } } } return result; }
/** * Creates a new fake Agent. If enterStop or exitStop are <code>null</code>, * the leg will have no route. * * @param enterStop may be <code>null</code> * @param exitStop may be <code>null</code> */ public FakeAgent(final TransitStopFacility enterStop, final TransitStopFacility exitStop) { this.exitStop = exitStop; this.dummyLeg = PopulationUtils.createLeg(TransportMode.pt); if ((enterStop != null) && (exitStop != null)) { Route route = new ExperimentalTransitRoute(enterStop, null, null, exitStop); route.setStartLinkId(enterStop.getLinkId()); route.setEndLinkId(exitStop.getLinkId()); route.setRouteDescription("PT1 " + enterStop.getId().toString() + " T1 " + exitStop.getId().toString()); this.dummyLeg.setRoute(route); } }
public void testLink() { Id<TransitStopFacility> id = Id.create(2491, TransitStopFacility.class); Coord coord = new Coord((double) 30, (double) 5); TransitStopFacility stop = createTransitStopFacility(id, coord, false); assertNull(stop.getLinkId()); Link link = new FakeLink(Id.create(99, Link.class), null, null); stop.setLinkId(link.getId()); assertEquals(link.getId(), stop.getLinkId()); stop.setLinkId(null); assertNull(stop.getLinkId()); }
private Leg createEgressTransitWalkLeg(RouteSegment routeSegement, Coord toCoord) { Leg leg = this.createTransitWalkLeg(routeSegement.toStop.getCoord(), toCoord); Route walkRoute = RouteUtils.createGenericRouteImpl(routeSegement.toStop.getLinkId(), null); walkRoute.setTravelTime(leg.getTravelTime() ); walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(routeSegement.toStop.getCoord(), toCoord)); leg.setRoute(walkRoute); return leg; }
private Leg createAccessTransitWalkLeg(Coord fromCoord, RouteSegment routeSegement) { Leg leg = this.createTransitWalkLeg(fromCoord, routeSegement.fromStop.getCoord()); Route walkRoute = RouteUtils.createGenericRouteImpl(null, routeSegement.fromStop.getLinkId()); walkRoute.setTravelTime(leg.getTravelTime() ); walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(fromCoord, routeSegement.fromStop.getCoord())); leg.setRoute(walkRoute); return leg; }
private Leg createTransferTransitWalkLeg(RouteSegment routeSegement) { Leg leg = this.createTransitWalkLeg(routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()); Route walkRoute = RouteUtils.createGenericRouteImpl(routeSegement.getFromStop().getLinkId(), routeSegement.getToStop().getLinkId()); // walkRoute.setTravelTime(leg.getTravelTime() ); // transit walk leg should include additional transfer time; Amit, Aug'17 leg.setTravelTime( getTransferTime(null, routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()) ); walkRoute.setTravelTime(getTransferTime(null, routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()) ); walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(routeSegement.fromStop.getCoord(), routeSegement.toStop.getCoord())); leg.setRoute(walkRoute); return leg; }
/** * 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()); }
@Test public void testStopFacility_Minimalistic() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); TransitScheduleReaderV1 reader = new TransitScheduleReaderV1(schedule, new RouteFactories()); Stack<String> context = new Stack<String>(); Attributes emptyAtts = AttributesBuilder.getEmpty(); reader.startTag(Constants.TRANSIT_SCHEDULE, emptyAtts, context); context.push(Constants.TRANSIT_SCHEDULE); reader.startTag(Constants.TRANSIT_STOPS, emptyAtts, context); context.push(Constants.TRANSIT_STOPS); Attributes atts = new AttributesBuilder().add(Constants.ID, "stop1"). add(Constants.X, "79").add(Constants.Y, "80").get(); reader.startTag(Constants.STOP_FACILITY, atts, context); reader.endTag(Constants.STOP_FACILITY, EMPTY_STRING, context); reader.endTag(context.pop(), EMPTY_STRING, context);// TRANSIT_STOPS reader.endTag(context.pop(), EMPTY_STRING, context);// TRANSIT_SCHEDULE assertEquals(1, schedule.getFacilities().size()); TransitStopFacility stop = schedule.getFacilities().get(Id.create("stop1", TransitStopFacility.class)); assertNotNull(stop); assertEquals(79.0, stop.getCoord().getX(), MatsimTestCase.EPSILON); assertEquals(80.0, stop.getCoord().getY(), MatsimTestCase.EPSILON); assertNull(stop.getLinkId()); assertNull(stop.getName()); assertFalse(stop.getIsBlockingLane()); }