private PlansCalcRouteWithTollOrNot testee( final Scenario scenario, final RoadPricingScheme toll) { return Injector.createInjector( scenario.getConfig(), new AbstractModule() { @Override public void install() { bind(RoadPricingScheme.class).toInstance(toll); bind(Scenario.class).toInstance(scenario); addTravelTimeBinding(TransportMode.car).to(FreeSpeedTravelTime.class); bind(PlansCalcRouteWithTollOrNot.class); install(new ScenarioElementsModule()); addTravelDisutilityFactoryBinding(TransportMode.car) .toInstance( new RandomizingTimeDistanceTravelDisutility.Builder(TransportMode.car)); install(new TripRouterModule()); addControlerListenerBinding().to(RoadPricingControlerListener.class); // add the events handler to calculate the tolls paid by agents bind(CalcPaidToll.class).in(Singleton.class); addEventHandlerBinding().to(CalcPaidToll.class); bind(CalcAverageTolledTripLength.class).in(Singleton.class); addEventHandlerBinding().to(CalcAverageTolledTripLength.class); } }) .getInstance(PlansCalcRouteWithTollOrNot.class); }
public static TripRouterFactory createRichTripRouterFactoryImpl(final Scenario scenario) { return Injector.createInjector( scenario.getConfig(), new TripRouterFactoryModule(), new AbstractModule() { @Override public void install() { bind(Scenario.class).toInstance(scenario); } }) .getInstance(TripRouterFactory.class); }
private static void testRestrictedNetwork(final Config config) throws Exception { // create a simple scenario, with two parallel links, // a long one for cars, a short one for pt. final Scenario scenario = ScenarioUtils.createScenario(config); Network net = scenario.getNetwork(); Node n1 = net.getFactory().createNode(Id.create(1, Node.class), new Coord((double) 0, (double) 0)); Node n2 = net.getFactory().createNode(Id.create(2, Node.class), new Coord((double) 0, (double) 0)); Node n3 = net.getFactory().createNode(Id.create(3, Node.class), new Coord((double) 0, (double) 0)); Node n4 = net.getFactory().createNode(Id.create(4, Node.class), new Coord((double) 0, (double) 0)); Link l1 = net.getFactory().createLink(Id.create("l1", Link.class), n1, n2); Link l2c = net.getFactory().createLink(Id.create("l2c", Link.class), n2, n3); Link l2pt = net.getFactory().createLink(Id.create("l2pt", Link.class), n2, n3); Link l3 = net.getFactory().createLink(Id.create("l3", Link.class), n3, n4); l2c.setAllowedModes(Collections.singleton(TransportMode.car)); l2c.setLength(1000); l2pt.setAllowedModes(Collections.singleton(TransportMode.pt)); l2pt.setLength(10); net.addNode(n1); net.addNode(n2); net.addNode(n3); net.addNode(n4); net.addLink(l1); net.addLink(l2c); net.addLink(l2pt); net.addLink(l3); Injector injector = Injector.createInjector( scenario.getConfig(), new AbstractModule() { @Override public void install() { install( AbstractModule.override( Arrays.asList(new TripRouterModule()), new AbstractModule() { @Override public void install() { bind(Scenario.class).toInstance(scenario); addTravelTimeBinding("car") .toInstance( new FreespeedTravelTimeAndDisutility(config.planCalcScore())); addTravelDisutilityFactoryBinding("car") .toInstance(new OnlyTimeDependentTravelDisutilityFactory()); } })); } }); // create the factory, get a router, route. Provider<TripRouter> factory = injector.getProvider(TripRouter.class); TripRouter router = factory.get(); List<? extends PlanElement> trip = router.calcRoute( TransportMode.car, new LinkFacility(l1), new LinkFacility(l3), 0, PersonImpl.createPerson(Id.create("toto", Person.class))); Leg l = (Leg) trip.get(0); // actual test NetworkRoute r = (NetworkRoute) l.getRoute(); Assert.assertEquals("unexpected route length " + r.getLinkIds(), 1, r.getLinkIds().size()); Assert.assertEquals("unexpected link", l2c.getId(), r.getLinkIds().get(0)); }
/** Checks that routes are found when using a monomodal network (ie modes are not restricted) */ @Test public void testMonomodalNetwork() throws Exception { final Config config = ConfigUtils.createConfig(); final Scenario scenario = ScenarioUtils.createScenario(config); Network net = scenario.getNetwork(); Node n1 = net.getFactory().createNode(Id.create(1, Node.class), new Coord((double) 0, (double) 0)); Node n2 = net.getFactory().createNode(Id.create(2, Node.class), new Coord((double) 0, (double) 0)); Node n3 = net.getFactory().createNode(Id.create(3, Node.class), new Coord((double) 0, (double) 0)); Node n4 = net.getFactory().createNode(Id.create(4, Node.class), new Coord((double) 0, (double) 0)); Link l1 = net.getFactory().createLink(Id.create("l1", Link.class), n1, n2); Link l2long = net.getFactory().createLink(Id.create("l2long", Link.class), n2, n3); Link l2short = net.getFactory().createLink(Id.create("l2short", Link.class), n2, n3); Link l3 = net.getFactory().createLink(Id.create("l3", Link.class), n3, n4); l2long.setLength(1000); l2short.setLength(10); net.addNode(n1); net.addNode(n2); net.addNode(n3); net.addNode(n4); net.addLink(l1); net.addLink(l2long); net.addLink(l2short); net.addLink(l3); // create the factory, get a router, route. Injector injector = Injector.createInjector( scenario.getConfig(), new AbstractModule() { @Override public void install() { install( AbstractModule.override( Arrays.asList(new TripRouterModule()), new AbstractModule() { @Override public void install() { bind(Scenario.class).toInstance(scenario); addTravelTimeBinding("car") .toInstance( new FreespeedTravelTimeAndDisutility(config.planCalcScore())); addTravelDisutilityFactoryBinding("car") .toInstance(new OnlyTimeDependentTravelDisutilityFactory()); } })); } }); TripRouter router = injector.getInstance(TripRouter.class); List<? extends PlanElement> trip = router.calcRoute( TransportMode.car, new LinkFacility(l1), new LinkFacility(l3), 0, PersonImpl.createPerson(Id.create("toto", Person.class))); Leg l = (Leg) trip.get(0); // actual test NetworkRoute r = (NetworkRoute) l.getRoute(); Assert.assertEquals("unexpected route length " + r.getLinkIds(), 1, r.getLinkIds().size()); Assert.assertEquals("unexpected link", l2short.getId(), r.getLinkIds().get(0)); }