@Override public void addTransitLine(final TransitLine line) { final Id<TransitLine> id = line.getId(); if (this.transitLines.containsKey(id)) { throw new IllegalArgumentException("There is already a transit line with id " + id.toString()); } this.transitLines.put(id, line); }
/** * Why do we need this constructor, if we only keep the id of the line/route? */ public ExperimentalTransitRoute(final TransitStopFacility accessFacility, final TransitLine line, final TransitRoute route, final TransitStopFacility egressFacility) { this(accessFacility, egressFacility, (line == null ? null : line.getId()), (route == null ? null : route.getId())); }
private Id<TransitLine> getLineId(Collection<UmlaufStueckI> umlaufInConstruction) { Id<TransitLine> lineId = null; for (UmlaufStueckI umlaufStueck : umlaufInConstruction) { if (umlaufStueck.isFahrt()) { if (lineId == null) { lineId = umlaufStueck.getLine().getId(); } } } return lineId; }
private static String getHash(TransitLine transitLine, TransitRoute transitRoute, TransitRouteStop transitRouteStop, int position){ return transitLine.getId().toString() + "-" + transitRoute.getId().toString() + "-" + transitRouteStop.getStopFacility().getId().toString() + "-" + position; } }
public VehicleOccupancyCalculator(final TransitSchedule transitSchedule, final Vehicles vehicles, final int timeSlot, final int totalTime) { this.timeSlot = timeSlot; for(TransitLine line:transitSchedule.getTransitLines().values()) for(TransitRoute route:line.getRoutes().values()) { Map<Id<TransitStopFacility>, VehicleOccupancyData> routeMap = new HashMap<Id<TransitStopFacility>, VehicleOccupancyData>(100); vehicleOccupancy.put(new Tuple<Id<TransitLine>, Id<TransitRoute>>(line.getId(), route.getId()), routeMap); for(int s=0; s<route.getStops().size()-1; s++) { routeMap.put(route.getStops().get(s).getStopFacility().getId(), new VehicleOccupancyDataArray((int) (totalTime/timeSlot)+1)); } } this.vehicles = vehicles; }
private void addPTransitScheduleToOriginalOne(TransitSchedule baseSchedule, TransitSchedule pSchedule) { if(pSchedule == null){ log.info("pSchedule does not exist, doing nothing"); return; } for (TransitStopFacility pStop : pSchedule.getFacilities().values()) { if (!baseSchedule.getFacilities().containsKey(pStop.getId())) { baseSchedule.addStopFacility(pStop); currentExclusivePFacilityIDs.add(pStop.getId()); } } for (TransitLine pLine : pSchedule.getTransitLines().values()) { if (!baseSchedule.getTransitLines().containsKey(pLine.getId())) { baseSchedule.addTransitLine(pLine); currentExclusivePTransitLineIDs.add(pLine.getId()); } } }
private void writeTransitLine(final TransitLine line) throws UncheckedIOException { List<Tuple<String, String>> attributes = new ArrayList<Tuple<String, String>>(1); attributes.add(this.createTuple(Constants.ID, line.getId().toString())); if (line.getName() != null) { attributes.add(this.createTuple(Constants.NAME, line.getName())); } this.writeStartTag(Constants.TRANSIT_LINE, attributes); for (TransitRoute route : line.getRoutes().values()) { writeTransitRoute(route); } this.writeEndTag(Constants.TRANSIT_LINE); }
public List<StopInformation> getDepartureStopInformation(final TransitLine line, final TransitRoute route, final TransitStopFacility stopFacility, final Departure departure) { return getStopInformation(line.getId(), route.getId(), stopFacility.getId(), departure.getId(), false); }
private void writeTransitLine(final TransitLine line) throws IOException, UncheckedIOException { List<Tuple<String, String>> attributes = new ArrayList<>(1); attributes.add(createTuple(Constants.ID, line.getId().toString())); if (line.getName() != null) { attributes.add(createTuple(Constants.NAME, line.getName())); } this.writeStartTag(Constants.TRANSIT_LINE, attributes); if (!AttributesUtils.isEmpty(line.getAttributes())) { this.writer.write(NL); this.attributesWriter.writeAttributes("\t\t", this.writer, line.getAttributes()); } for (TransitRoute route : line.getRoutes().values()) { writeTransitRoute(route); } this.writeEndTag(Constants.TRANSIT_LINE); }
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; }
@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 testInitialization() { Id<TransitLine> id = Id.create(511, TransitLine.class); TransitLine tLine = createTransitLine(id); assertNotNull(tLine); assertEquals("different ids.", id.toString(), tLine.getId().toString()); }
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; }
@Test public void testGetTransitLinesImmutable() { TransitSchedule schedule = new TransitScheduleImpl(new TransitScheduleFactoryImpl()); TransitLine line1 = new TransitLineImpl(Id.create(1, TransitLine.class)); try { schedule.getTransitLines().put(line1.getId(), line1); fail("missing exception."); } catch (UnsupportedOperationException e) { log.info("catched expected exception.", e); } }
@Test public void testAddTransitLine() { TransitSchedule schedule = new TransitScheduleImpl(new TransitScheduleFactoryImpl()); TransitLine line1 = new TransitLineImpl(Id.create(1, TransitLine.class)); TransitLine line2 = new TransitLineImpl(Id.create(2, TransitLine.class)); assertEquals(0, schedule.getTransitLines().size()); schedule.addTransitLine(line1); assertEquals(1, schedule.getTransitLines().size()); assertEquals(line1, schedule.getTransitLines().get(line1.getId())); schedule.addTransitLine(line2); assertEquals(2, schedule.getTransitLines().size()); assertEquals(line1, schedule.getTransitLines().get(line1.getId())); assertEquals(line2, schedule.getTransitLines().get(line2.getId())); }
@Test public void testCreateTransitLine() { TransitScheduleFactory builder = createTransitScheduleBuilder(); Id<TransitLine> id = Id.create(1, TransitLine.class); TransitLine line = builder.createTransitLine(id); Assert.assertEquals(id, line.getId()); }
@Test public void testTransitLine_Single() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); TransitScheduleReaderV1 reader = new TransitScheduleReaderV1(schedule, new RouteFactories()); Stack<String> context = new Stack<String>(); reader.startTag(Constants.TRANSIT_SCHEDULE, AttributesBuilder.getEmpty(), context); context.push(Constants.TRANSIT_SCHEDULE); Id<TransitLine> lineId = Id.create("23", TransitLine.class); reader.startTag(Constants.TRANSIT_LINE, new AttributesBuilder().add(Constants.ID, lineId.toString()).get(), context); reader.endTag(Constants.TRANSIT_LINE, EMPTY_STRING, context);// TRANSIT_LINE reader.endTag(context.pop(), EMPTY_STRING, context);// TRANSIT_SCHEDULE assertEquals(1, schedule.getTransitLines().size()); TransitLine line = schedule.getTransitLines().get(lineId); assertNotNull(line); assertEquals(lineId, line.getId()); }
final void sendTransitDriverStartsEvent(final double now) { // A test initializes this Agent without internalInterface. // Actually, I am not sure if agents should send Events (or just be reactive, so they can be // tested / exercised as a unit, without a QSim. michaz if (internalInterface != null) { // check if "Wenden" if(getTransitLine() == null){ eventsManager.processEvent(new TransitDriverStartsEvent(now, this.dummyPerson.getId(), this.vehicle.getId(), Id.create("Wenden", TransitLine.class), Id.create("Wenden", TransitRoute.class), Id.create("Wenden", Departure.class))); } else { eventsManager.processEvent(new TransitDriverStartsEvent(now, this.dummyPerson.getId(), this.vehicle.getId(), getTransitLine().getId(), getTransitRoute().getId(), getDeparture().getId())); } } }
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()); }