/** * 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); }
public RouteFactories() { this.setRouteFactory(NetworkRoute.class, new LinkNetworkRouteFactory()); this.setRouteFactory(ExperimentalTransitRoute.class, new ExperimentalTransitRouteFactory()); }
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; }
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)); }
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); }
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());
scenario.getPopulation().getFactory().getRouteFactories().setRouteFactory(NetworkRoute.class, new CompressedNetworkRouteFactory(scenario.getNetwork())); ScenarioUtils.loadScenario(scenario);