private void startRoute(final Attributes atts) { this.currroute = this.plans.getFactory().getRouteFactories().createRoute(NetworkRoute.class, this.prevAct.getLinkId(), this.prevAct.getLinkId()); this.currleg.setRoute(this.currroute); if (atts.getValue("dist") != null) { this.currroute.setDistance(Double.parseDouble(atts.getValue("dist"))); } if (atts.getValue("trav_time") != null) { this.currroute.setTravelTime(Time.parseTime(atts.getValue("trav_time"))); } }
public void testSetRouteFactory() { PopulationFactory factory = ScenarioUtils.createScenario(ConfigUtils.createConfig()).getPopulation().getFactory(); // test default Route carRoute = factory.getRouteFactories().createRoute(NetworkRoute.class, null, null); Assert.assertTrue(carRoute instanceof NetworkRoute); Route route = factory.getRouteFactories().createRoute(Route.class, null, null); Assert.assertTrue(route instanceof GenericRouteImpl); // overwrite car-mode factory.getRouteFactories().setRouteFactory(CarRouteMock.class, new CarRouteMockFactory()); // add pt-mode factory.getRouteFactories().setRouteFactory(PtRouteMock.class, new PtRouteMockFactory()); // test car-mode carRoute = factory.getRouteFactories().createRoute(CarRouteMock.class, null, null); Assert.assertTrue(carRoute instanceof CarRouteMock); // add pt-mode Route ptRoute = factory.getRouteFactories().createRoute(PtRouteMock.class, null, null); Assert.assertTrue(ptRoute instanceof PtRouteMock); // remove pt-mode factory.getRouteFactories().setRouteFactory(PtRouteMock.class, null); // test pt again route = factory.getRouteFactories().createRoute(PtRouteMock.class, null, null); Assert.assertTrue(route instanceof GenericRouteImpl); }
public static Population createPopulation(PlansConfigGroup plansConfigGroup, Network network) { // yyyy my intuition would be to rather get this out of a standard scenario. kai, jun'16 RouteFactories routeFactory = new RouteFactories(); String networkRouteType = plansConfigGroup.getNetworkRouteType(); RouteFactory factory; if (PlansConfigGroup.NetworkRouteType.LinkNetworkRoute.equals(networkRouteType)) { factory = new LinkNetworkRouteFactory(); } else if (PlansConfigGroup.NetworkRouteType.CompressedNetworkRoute.equals(networkRouteType) && network != null) { factory = new CompressedNetworkRouteFactory(network); } else { throw new IllegalArgumentException("The type \"" + networkRouteType + "\" is not a supported type for network routes."); } routeFactory.setRouteFactory(NetworkRoute.class, factory); return new PopulationImpl(new PopulationFactoryImpl(routeFactory)); }
Class<? extends Route> routeClass = factory.getRouteClassForType(routeType); this.currRoute = this.scenario.getPopulation().getFactory().getRouteFactories().createRoute(routeClass, startLinkId == null ? null : Id.create(startLinkId, Link.class), endLinkId == null ? null : Id.create(endLinkId, Link.class)); this.currleg.setRoute(this.currRoute);
@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()); }
/** * Registers a {@link RouteFactory} for the specified route type. If <code>factory</code> is <code>null</code>, * the existing entry for this <code>routeType</code> will be deleted. If <code>routeType</code> is <code>null</code>, * then the default factory is set that is used if no specific RouteFactory for a routeType is set. * */ public void setRouteFactory(final Class<? extends Route> routeType, final RouteFactory factory) { this.routeFactory.setRouteFactory(routeType, factory); }
@Test public void testTransitLine_Multiple() { 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> lineId1 = Id.create("23", TransitLine.class); reader.startTag(Constants.TRANSIT_LINE, new AttributesBuilder().add(Constants.ID, lineId1.toString()).get(), context); reader.endTag(Constants.TRANSIT_LINE, EMPTY_STRING, context);// TRANSIT_LINE Id<TransitLine> lineId2 = Id.create("42", TransitLine.class); reader.startTag(Constants.TRANSIT_LINE, new AttributesBuilder().add(Constants.ID, lineId2.toString()).get(), context); reader.endTag(Constants.TRANSIT_LINE, EMPTY_STRING, context);// TRANSIT_LINE reader.endTag(context.pop(), EMPTY_STRING, context);// TRANSIT_SCHEDULE assertEquals(2, schedule.getTransitLines().size()); TransitLine line1 = schedule.getTransitLines().get(lineId1); assertNotNull(line1); assertEquals(lineId1, line1.getId()); TransitLine line2 = schedule.getTransitLines().get(lineId2); assertNotNull(line2); assertEquals(lineId2, line2.getId()); }
Class<? extends Route> routeClass = factory.getRouteClassForType(routeType); this.currRoute = this.scenario.getPopulation().getFactory().getRouteFactories().createRoute(routeClass, startLinkId == null ? null : Id.create(startLinkId, Link.class), endLinkId == null ? null : Id.create(endLinkId, Link.class)); this.currleg.setRoute(this.currRoute);
public RouteFactories() { this.setRouteFactory(NetworkRoute.class, new LinkNetworkRouteFactory()); this.setRouteFactory(ExperimentalTransitRoute.class, new ExperimentalTransitRouteFactory()); }
private void startRoute(final Attributes atts) { Class<? extends Route> routeType = Route.class; if ("pt".equals(this.currleg.getMode())) { routeType = ExperimentalTransitRoute.class; } if ("car".equals(this.currleg.getMode())) { routeType = NetworkRoute.class; } this.currRoute = this.plans.getFactory().getRouteFactories().createRoute(routeType, null, null); this.currleg.setRoute(this.currRoute); if (atts.getValue("dist") != null) { this.currRoute.setDistance(Double.parseDouble(atts.getValue("dist"))); } if (atts.getValue("trav_time") != null) { this.currRoute.setTravelTime(Time.parseTime(atts.getValue("trav_time"))); } }
@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()); }
Link link6 = NetworkUtils.createAndAddLink(f.network,Id.create("6", Link.class), fromNode1, toNode2, 100, 10, 60000, 9 ); f.scenario.getPopulation().getFactory().getRouteFactories().setRouteFactory(NetworkRoute.class, new LinkNetworkRouteFactory()); a1.setEndTime(8*3600); Leg leg = PopulationUtils.createAndAddLeg( plan, TransportMode.car ); NetworkRoute route = f.scenario.getPopulation().getFactory().getRouteFactories().createRoute(NetworkRoute.class, f.link1.getId(), link5.getId()); route.setLinkIds(Id.create(startLinkId, Link.class), NetworkUtils.getLinkIds(linkIds), Id.create(endLinkId, Link.class)); leg.setRoute(route); a2.setEndTime(9*3600); leg = PopulationUtils.createAndAddLeg( plan, TransportMode.car ); route = f.scenario.getPopulation().getFactory().getRouteFactories().createRoute(NetworkRoute.class, link5.getId(), link6.getId()); route.setLinkIds(link5.getId(), null, link6.getId()); leg.setRoute(route);
public static Scenario createScenario(final Config config) { final Scenario sc = ScenarioUtils.createScenario( config ); final RouteFactories rFactory = ((PopulationFactory) sc.getPopulation().getFactory()).getRouteFactories(); rFactory.setRouteFactory( DriverRoute.class,//JointActingTypes.DRIVER, new DriverRouteFactory()); rFactory.setRouteFactory( PassengerRoute.class,//JointActingTypes.PASSENGER, new PassengerRouteFactory()); return sc; }
@Override public void endTag(final String name, final String content, final Stack<String> context) { if (Constants.DESCRIPTION.equals(name) && Constants.TRANSIT_ROUTE.equals(context.peek())) { this.currentTransitRoute.description = content; } else if (Constants.TRANSPORT_MODE.equals(name)) { this.currentTransitRoute.mode = content.intern(); } else if (Constants.TRANSIT_ROUTE.equals(name)) { List<TransitRouteStop> stops = new ArrayList<TransitRouteStop>(this.currentTransitRoute.stops.size()); for (TempStop tStop : this.currentTransitRoute.stops) { TransitRouteStopImpl routeStop = new TransitRouteStopImpl(tStop.stop, tStop.arrival, tStop.departure); stops.add(routeStop); routeStop.setAwaitDepartureTime(tStop.awaitDeparture); } NetworkRoute route = null; if (this.currentRouteProfile.firstLinkId != null) { if (this.currentRouteProfile.lastLinkId == null) { this.currentRouteProfile.lastLinkId = this.currentRouteProfile.firstLinkId; } route = this.routeFactory.createRoute(NetworkRoute.class, this.currentRouteProfile.firstLinkId, this.currentRouteProfile.lastLinkId); route.setLinkIds(this.currentRouteProfile.firstLinkId, this.currentRouteProfile.linkIds, this.currentRouteProfile.lastLinkId); } TransitRoute transitRoute = this.schedule.getFactory().createTransitRoute(this.currentTransitRoute.id, route, stops, this.currentTransitRoute.mode); transitRoute.setDescription(this.currentTransitRoute.description); for (Departure departure : this.currentTransitRoute.departures.values()) { transitRoute.addDeparture(departure); } this.currentTransitLine.addRoute(transitRoute); } }
@Test public void testTransitLineName() { String filename = this.utils.getOutputDirectory() + "schedule.xml"; TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitSchedule schedule = builder.createTransitSchedule(); TransitLine line = builder.createTransitLine(Id.create(1, TransitLine.class)); line.setName("Blue line"); schedule.addTransitLine(line); TransitScheduleWriter writer = new TransitScheduleWriter(schedule); writer.writeFile(filename); TransitScheduleFactory builder2 = new TransitScheduleFactoryImpl(); TransitSchedule schedule2 = builder2.createTransitSchedule(); new TransitScheduleReaderV1(schedule2, new RouteFactories()).readFile(filename); Assert.assertEquals(1, schedule2.getTransitLines().size()); Assert.assertEquals("Blue line", schedule2.getTransitLines().get(Id.create(1, TransitLine.class)).getName()); } }
scenario.getPopulation().getFactory().getRouteFactories().setRouteFactory(NetworkRoute.class, new CompressedNetworkRouteFactory(scenario.getNetwork())); ScenarioUtils.loadScenario(scenario);
this.currentRouteProfile.lastLinkId = this.currentRouteProfile.firstLinkId; route = this.routeFactory.createRoute(NetworkRoute.class, this.currentRouteProfile.firstLinkId, this.currentRouteProfile.lastLinkId); route.setLinkIds(this.currentRouteProfile.firstLinkId, this.currentRouteProfile.linkIds, this.currentRouteProfile.lastLinkId);
/** * Tests that the default format written is in v2 format. * * @throws IOException * @throws SAXException * @throws ParserConfigurationException */ @Test public void testDefaultV2() throws IOException, SAXException, ParserConfigurationException { String filename = this.utils.getOutputDirectory() + "schedule.xml"; TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitSchedule schedule = builder.createTransitSchedule(); TransitLine line = builder.createTransitLine(Id.create(1, TransitLine.class)); schedule.addTransitLine(line); TransitScheduleWriter writer = new TransitScheduleWriter(schedule); writer.writeFile(filename); TransitScheduleFactory builder2 = new TransitScheduleFactoryImpl(); TransitSchedule schedule2 = builder2.createTransitSchedule(); new TransitScheduleReaderV2(schedule2, new RouteFactories()).readFile(filename); Assert.assertEquals(1, schedule2.getTransitLines().size()); }
private void startRoute() { this.currroute = this.plans.getFactory().getRouteFactories().createRoute(NetworkRoute.class, this.prevAct.getLinkId(), this.prevAct.getLinkId()); this.currleg.setRoute(this.currroute); }
@Test public void testTransitRoute_Description() { 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);