fromNode = this.network.getFactory().createNode(Id.create(this.prefix + toFacility.getId(), Node.class), fromFacility.getCoord()); this.network.addNode(fromNode); this.nodes.put(toFacility, fromNode); toNode = this.network.getFactory().createNode(Id.create(this.prefix + toFacility.getId(), Node.class), toFacility.getCoord()); this.network.addNode(toNode); this.nodes.put(toFacility, toNode); link = createAndAddLink(fromNode, toNode, connection); if (toFacility.getLinkId() == null) { toFacility.setLinkId(link.getId()); this.stopFacilities.put(connection, toFacility); } else { this.facilityCopies.put(toFacility, copies); Id<TransitStopFacility> newId = Id.create(toFacility.getId().toString() + "." + Integer.toString(copies.size() + 1), TransitStopFacility.class); TransitStopFacility newFacility = this.schedule.getFactory().createTransitStopFacility(newId, toFacility.getCoord(), toFacility.getIsBlockingLane()); newFacility.setStopAreaId(Id.create(toFacility.getId(), TransitStopArea.class)); newFacility.setLinkId(link.getId()); newFacility.setName(toFacility.getName()); copies.add(newFacility); this.nodes.put(newFacility, toNode);
for (TransitStopFacility stop : this.schedule.getFacilities().values()) { attributes.clear(); attributes.add(createTuple(Constants.ID, stop.getId().toString())); final Coord coord = this.coordinateTransformation.transform( stop.getCoord() ); attributes.add(createTuple("x", coord.getX())); attributes.add(createTuple("y", coord.getY())); attributes.add(createTuple("z", coord.getZ())); if (stop.getLinkId() != null) { attributes.add(createTuple("linkRefId", stop.getLinkId().toString())); if (stop.getName() != null) { attributes.add(createTuple("name", stop.getName())); if (stop.getStopAreaId() != null) { attributes.add(createTuple(Constants.STOP_AREA_ID, stop.getStopAreaId().toString())); attributes.add(createTuple("isBlocking", stop.getIsBlockingLane())); if (AttributesUtils.isEmpty(stop.getAttributes())) { this.writeStartTag(Constants.STOP_FACILITY, attributes, true); } else { this.writeStartTag(Constants.STOP_FACILITY, attributes, false); if (!AttributesUtils.isEmpty(stop.getAttributes())) { this.writer.write(NL); this.attributesWriter.writeAttributes("\t\t\t", this.writer, stop.getAttributes());
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 TransitStopFacility drawRandomStop(Geometry buffer, PRouteProvider pRouteProvider, Set<Id<TransitStopFacility>> stopsUsed) { List<TransitStopFacility> choiceSet = new LinkedList<>(); // find choice-set for (TransitStopFacility stop : pRouteProvider.getAllPStops()) { if (!stopsUsed.contains(stop.getId())) { if (buffer.contains(MGC.coord2Point(stop.getCoord()))) { choiceSet.add(stop); } } } return pRouteProvider.drawRandomStopFromList(choiceSet); }
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; }
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); }
@Override public String toString() { return "Id " + transitStopFacility.getId() + ", " + numberOfTransfers + " transfers from " + indexOfFirstTransfer; } }
@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()); } } }
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()); }
public void testInitialization() { Id<TransitStopFacility> id = Id.create(2491, TransitStopFacility.class); Coord coord = new Coord((double) 30, (double) 5); TransitStopFacility stop = createTransitStopFacility(id, coord, false); assertEquals(id.toString(), stop.getId().toString()); assertEquals(coord.getX(), stop.getCoord().getX(), EPSILON); assertEquals(coord.getY(), stop.getCoord().getY(), EPSILON); assertFalse(stop.getIsBlockingLane()); }
private ArrayList<TransitStopFacility> addStopToExistingStops(TransitStopFacility baseStop, TransitStopFacility remoteStop, ArrayList<TransitStopFacility> currentStopsToBeServed, TransitStopFacility newStop) { ArrayList<TransitStopFacility> newStopsToBeServed = new ArrayList<>(currentStopsToBeServed); // decide which stop is closer if (CoordUtils.calcEuclideanDistance(baseStop.getCoord(), newStop.getCoord()) < CoordUtils.calcEuclideanDistance(remoteStop.getCoord(), newStop.getCoord())) { // baseStop is closer - insert before baseStop newStopsToBeServed.add(0, newStop); } else { // remote stop is closer or both have the same distance - add after remote stop newStopsToBeServed.add(newStopsToBeServed.indexOf(remoteStop) + 1, newStop); } return newStopsToBeServed; }
stop2.getAttributes().putAttribute("air", "thin"); stop2.setStopAreaId(Id.create("GZ", TransitStopArea.class)); schedule.getMinimalTransferTimes().set(stop1.getId(), stop2.getId(), 300.0); schedule.getMinimalTransferTimes().set(stop2.getId(), stop1.getId(), 360.0); Assert.assertTrue(AttributesUtils.isEmpty(stop1.getAttributes())); TransitStopFacility stop2 = schedule2.getFacilities().get(Id.create(2, TransitStopFacility.class)); Assert.assertFalse(AttributesUtils.isEmpty(stop2.getAttributes())); Assert.assertEquals("thin", stop2.getAttributes().getAttribute("air")); Assert.assertTrue(stop2.getCoord().hasZ()); Assert.assertEquals(98765.0, stop2.getCoord().getZ(), 0.0); Assert.assertEquals("GZ", stop2.getStopAreaId().toString()); Assert.assertEquals(300, schedule2.getMinimalTransferTimes().get(stop1.getId(), stop2.getId()), 0.0); Assert.assertEquals(360, schedule2.getMinimalTransferTimes().get(stop2.getId(), stop1.getId()), 0.0); Assert.assertEquals(Double.NaN, schedule2.getMinimalTransferTimes().get(stop1.getId(), stop1.getId()), 0.0);
private int addStopOnLink(Link link) { if(link == null){ return 0; } if(linkToNodeNotInServiceArea(link)){ return 0; } if (linkHasAlreadyAFormalPTStopFromTheGivenSchedule(link)) { return 0; } if (link.getFreespeed() >= this.pConfigGroup.getSpeedLimitForStops()) { return 0; } if (this.linkId2StopFacilityMap.get(link.getId()) != null) { log.warn("Link " + link.getId() + " has already a stop. This should not happen. Check code."); return 0; } Id<TransitStopFacility> stopId = Id.create(this.pConfigGroup.getPIdentifier() + link.getId(), TransitStopFacility.class); TransitStopFacility stop = this.transitSchedule.getFactory().createTransitStopFacility(stopId, link.getToNode().getCoord(), false); stop.setLinkId(link.getId()); this.transitSchedule.addStopFacility(stop); return 1; }
this.coordinateTransformation.transform(coord), isBlocking); this.currentAttributes = stop.getAttributes(); if (atts.getValue(Constants.LINK_REF_ID) != null) { Id<Link> linkId = Id.create(atts.getValue(Constants.LINK_REF_ID), Link.class); stop.setLinkId(linkId); stop.setName(this.cache.get(atts.getValue(Constants.NAME))); stop.setStopAreaId(Id.create(atts.getValue(Constants.STOP_AREA_ID), TransitStopArea.class));
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()); }
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; } }
@Test public void testStopFacility_isBlocking() { 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").add(Constants.IS_BLOCKING, "true").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); assertTrue(stop.getIsBlockingLane()); }
@Test public void testStopFacility_withName() { 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").add(Constants.NAME, "some stop name").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); assertEquals("some stop name", stop.getName()); }
@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(); } } }