@Override public NetworkRoute getCarRoute() { return route.getRoute(); }
private void setLeg(final TransitLine line, final TransitRoute route, final Departure departure) { this.transitLine = line; this.transitRoute = route; this.departure = departure; this.departureTime = departure.getDepartureTime(); this.carRoute = route.getRoute(); }
private void createUmlaufStuecke() { this.umlaufStuecke = new ArrayList<>(); log.info("Generating UmlaufStuecke"); int cnt = 0; for (TransitLine line : transitLines) { for (TransitRoute route : line.getRoutes().values()) { Gbl.assertNotNull(route.getRoute()); // will fail much later if this is null. kai, may'17 for (Departure departure : route.getDepartures().values()) { UmlaufStueck umlaufStueck = new UmlaufStueck(line, route, departure); umlaufStuecke.add(umlaufStueck); cnt++; printStatus(cnt); } } } Collections.sort(this.umlaufStuecke, departureTimeComparator); }
coords.add(network.getLinks().get(route.getRoute().getStartLinkId()).getToNode().getCoord()); for (Id<Link> id : route.getRoute().getLinkIds()) { coords.add(network.getLinks().get(id).getToNode().getCoord()); coords.add(network.getLinks().get(route.getRoute().getEndLinkId()).getToNode().getCoord());
@Override public ArrayList<Umlauf> build() { int id = 0; ArrayList<Umlauf> umlaeufe = new ArrayList<Umlauf>(); for (TransitLine line : transitLines) { for (TransitRoute route : line.getRoutes().values()) { Gbl.assertNotNull(route.getRoute()); // will fail much later if this is null. kai, may'17 for (Departure departure : route.getDepartures().values()) { UmlaufStueck umlaufStueck = new UmlaufStueck(line, route, departure); Umlauf umlauf = new UmlaufImpl(Id.create(id++, Umlauf.class)); umlauf.getUmlaufStuecke().add(umlaufStueck); umlaeufe.add(umlauf); } } } return umlaeufe; }
NetworkRoute netRoute = route.getRoute(); if (netRoute == null) { result.addIssue(new ValidationResult.ValidationIssue(ValidationResult.Severity.ERROR, "Transit line " + line.getId() + ", route " + route.getId() + " has no network route.", ValidationResult.Type.OTHER, Collections.singleton(route.getId())));
Id<Link> exitLinkId = ts.getFacilities().get(exitStopId).getLinkId(); NetworkRoute nr = tr.getRoute(); double dist = 0; boolean count = false;
private void writeTransitRoute(final TransitRoute route) throws UncheckedIOException { List<Tuple<String, String>> attributes = new ArrayList<Tuple<String, String>>(1); attributes.add(this.createTuple(Constants.ID, route.getId().toString())); this.writeStartTag(Constants.TRANSIT_ROUTE, attributes); if (route.getDescription() != null) { this.writeStartTag(Constants.DESCRIPTION, null); this.writeContent(route.getDescription(), false); this.writeEndTag(Constants.DESCRIPTION); } this.writeStartTag(Constants.TRANSPORT_MODE, null); this.writeContent(route.getTransportMode(), false); this.writeEndTag(Constants.TRANSPORT_MODE); this.writeRouteProfile(route.getStops()); this.writeRoute(route.getRoute()); this.writeDepartures(route.getDepartures()); this.writeEndTag(Constants.TRANSIT_ROUTE); }
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
NetworkRoute netRoute = route.getRoute(); if (netRoute == null) { result.addIssue(new ValidationResult.ValidationIssue(ValidationResult.Severity.ERROR, "Transit line " + line.getId() + ", route " + route.getId() + " has no network route.", ValidationResult.Type.OTHER, Collections.singleton(route.getId())));
private void writeTransitRoute(final TransitRoute route) throws IOException, UncheckedIOException { List<Tuple<String, String>> attributes = new ArrayList<>(1); attributes.add(createTuple(Constants.ID, route.getId().toString())); this.writeStartTag(Constants.TRANSIT_ROUTE, attributes); if (!AttributesUtils.isEmpty(route.getAttributes())) { this.writer.write(NL); this.attributesWriter.writeAttributes("\t\t\t", this.writer, route.getAttributes()); } if (route.getDescription() != null) { this.writeStartTag(Constants.DESCRIPTION, null); this.writeContent(route.getDescription(), false); this.writeEndTag(Constants.DESCRIPTION); } this.writeStartTag(Constants.TRANSPORT_MODE, null); this.writeContent(route.getTransportMode(), false); this.writeEndTag(Constants.TRANSPORT_MODE); this.writeRouteProfile(route.getStops()); this.writeRoute(route.getRoute()); this.writeDepartures(route.getDepartures()); this.writeEndTag(Constants.TRANSIT_ROUTE); }
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(); } }
public void testInitialization() { Id<TransitRoute> id = Id.create(9791, TransitRoute.class); Link fromLink = new FakeLink(Id.create(10, Link.class), null, null); Link toLink = new FakeLink(Id.create(5, Link.class), null, null); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(fromLink.getId(), toLink.getId()); List<TransitRouteStop> stops = new ArrayList<TransitRouteStop>(); TransitRouteStop stop = new TransitRouteStopImpl(null, 50, 60); stops.add(stop); TransitRoute tRoute = createTransitRoute(id, route, stops, "train"); assertEquals("wrong id.", id.toString(), tRoute.getId().toString()); assertEquals("wrong route.", route, tRoute.getRoute()); assertEquals(stops.size(), tRoute.getStops().size()); assertEquals(stop, tRoute.getStops().get(0)); assertEquals("train", tRoute.getTransportMode()); }
@Test public void testPtTutorialWithError() { Scenario scenario = ScenarioUtils.loadScenario(ConfigUtils.loadConfig("test/scenarios/pt-tutorial/0.config.xml")); TransitLine transitLine = scenario.getTransitSchedule().getTransitLines().get(Id.create("Blue Line", TransitLine.class)); transitLine.getRoutes().get(Id.create("3to1", TransitRoute.class)).getRoute().setLinkIds(Id.createLinkId("33"), Collections.<Id<Link>>emptyList(), Id.createLinkId("11")); TransitScheduleValidator.ValidationResult validationResult = TransitScheduleValidator.validateAll(scenario.getTransitSchedule(), scenario.getNetwork()); Assert.assertThat(validationResult.getIssues(), containsInAnyOrder(Matchers.allOf( hasProperty("severity", Matchers.equalTo(TransitScheduleValidator.ValidationResult.Severity.ERROR)), hasProperty("entities", containsInAnyOrder(Matchers.equalTo(Id.create("2b", TransitStopFacility.class))))))); }
@Test public void testCreateTransitRoute() { TransitScheduleFactory builder = createTransitScheduleBuilder(); Id<TransitRoute> id = Id.create(2, TransitRoute.class); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(Id.create(3, Link.class), Id.create(4, Link.class)); List<TransitRouteStop> stops = new ArrayList<TransitRouteStop>(); TransitRouteStop stop1 = new TransitRouteStopImpl(null, 50, 60); stops.add(stop1); String mode = TransportMode.pt; TransitRoute tRoute = builder.createTransitRoute(id, route, stops, mode); Assert.assertEquals(id, tRoute.getId()); Assert.assertEquals(route, tRoute.getRoute()); Assert.assertEquals(1, tRoute.getStops().size()); Assert.assertEquals(stop1, tRoute.getStops().get(0)); Assert.assertEquals(mode, tRoute.getTransportMode()); }
public void testRoute() { Fixture f = new Fixture(); Link link1 = new FakeLink(Id.create(1, Link.class), null, null); Link link2 = new FakeLink(Id.create(2, Link.class), null, null); Link link3 = new FakeLink(Id.create(3, Link.class), null, null); NetworkRoute route1 = RouteUtils.createLinkNetworkRouteImpl(link1.getId(), link2.getId()); NetworkRoute route2 = RouteUtils.createLinkNetworkRouteImpl(link1.getId(), link3.getId()); f.tRoute.setRoute(route1); assertEquals(route1, f.tRoute.getRoute()); f.tRoute.setRoute(route2); assertEquals(route2, f.tRoute.getRoute()); }
@Test public void testRouteProfileRoute_NoLink() { 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); // now the other stuff Id<TransitLine> lineId = Id.create("1", TransitLine.class); reader.startTag(Constants.TRANSIT_LINE, new AttributesBuilder().add(Constants.ID, lineId.toString()).get(), context); context.push(Constants.TRANSIT_LINE); Id<TransitRoute> routeId1 = Id.create("1", TransitRoute.class); reader.startTag(Constants.TRANSIT_ROUTE, new AttributesBuilder().add(Constants.ID, routeId1.toString()).get(), context); context.push(Constants.TRANSIT_ROUTE); // by definition of the file format, transitRoute *must* have transportMode, routeProfile and departures defined reader.startTag(Constants.TRANSPORT_MODE, AttributesBuilder.getEmpty(), context); reader.endTag(Constants.TRANSPORT_MODE, "bus", context); reader.startTag(Constants.ROUTE_PROFILE, AttributesBuilder.getEmpty(), context); // route profile can be empty, but must exist reader.endTag(Constants.ROUTE_PROFILE, EMPTY_STRING, context); reader.startTag(Constants.ROUTE, AttributesBuilder.getEmpty(), context); reader.endTag(Constants.ROUTE, EMPTY_STRING, context); reader.endTag(Constants.ROUTE_PROFILE, EMPTY_STRING, context); reader.startTag(Constants.DEPARTURES, AttributesBuilder.getEmpty(), context); // departures can be empty, but must exist reader.endTag(Constants.DEPARTURES, EMPTY_STRING, context); reader.endTag(context.pop(), EMPTY_STRING, context); // TRANSIT_ROUTE reader.endTag(context.pop(), EMPTY_STRING, context); // TRANSIT_LINE reader.endTag(context.pop(), EMPTY_STRING, context); // TRANSIT_SCHEDULE TransitRoute route = schedule.getTransitLines().get(lineId).getRoutes().get(routeId1); assertNull(route.getRoute()); }
public void testReadFileV1() throws SAXException, ParserConfigurationException, IOException { final String inputDir = getClassInputDirectory(); Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(inputDir + INPUT_TEST_FILE_NETWORK); TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitSchedule schedule = builder.createTransitSchedule(); new TransitScheduleReaderV1(schedule, scenario.getPopulation().getFactory().getRouteFactories()).readFile(inputDir + INPUT_TEST_FILE_TRANSITSCHEDULE); assertEquals("wrong number of transit lines.", 1, schedule.getTransitLines().size()); assertEquals("wrong line id.", Id.create("T1", TransitLine.class), schedule.getTransitLines().keySet().iterator().next()); TransitLine lineT1 = schedule.getTransitLines().get(Id.create("T1", TransitLine.class)); assertNotNull("could not find line with id T1.", lineT1); TransitRoute route1 = lineT1.getRoutes().get(Id.create("1", TransitRoute.class)); assertNotNull("could not find route 1 in line T1.", route1); Map<Id<Departure>, Departure> departures = route1.getDepartures(); assertNotNull("could not get departures of route 1 in line T1.", departures); assertEquals("wrong number of departures.", 3, departures.size()); List<TransitRouteStop> stops = route1.getStops(); assertNotNull("could not get transit route stops.", stops); assertEquals("wrong number of stops.", 6, stops.size()); NetworkRoute route = route1.getRoute(); assertNotNull("could not get route.", route); assertEquals("wrong start link.", network.getLinks().get(Id.create("1", Link.class)).getId(), route.getStartLinkId()); assertEquals("wrong end link.", network.getLinks().get(Id.create("8", Link.class)).getId(), route.getEndLinkId()); assertEquals("wrong number of links in route.", 4, route.getLinkIds().size()); }
assertEquals("bus", route1.getTransportMode()); assertEquals(0, route1.getStops().size()); assertNull(route1.getRoute()); assertEquals(0, route1.getDepartures().size());
@Override public void insertAgentsIntoMobsim() { TestHandleStopSimulation.this.driver = new SpyDriver(TestHandleStopSimulation.this.line, TestHandleStopSimulation.this.route, TestHandleStopSimulation.this.departure, transitEngine.getAgentTracker(), transitEngine); VehicleType vehicleType = new VehicleTypeImpl(Id.create("transitVehicleType", VehicleType.class)); VehicleCapacity capacity = new VehicleCapacityImpl(); capacity.setSeats(101); capacity.setStandingRoom(0); vehicleType.setCapacity(capacity); TransitQVehicle veh = new TransitQVehicle(new VehicleImpl(Id.create(TestHandleStopSimulation.this.driver.getId(), Vehicle.class), vehicleType)); veh.setDriver(TestHandleStopSimulation.this.driver); veh.setStopHandler(new SimpleTransitStopHandler()); TestHandleStopSimulation.this.driver.setVehicle(veh); TestHandleStopSimulation.this.departure.setVehicleId(veh.getVehicle().getId()); qSim.addParkedVehicle(veh, route.getRoute().getStartLinkId()); qSim.insertAgentIntoMobsim(TestHandleStopSimulation.this.driver); } });