public NetworkRoutingInclAccessEgressModule( final String mode, final PopulationFactory populationFactory, final Network network, final LeastCostPathCalculator routeAlgo, PlansCalcRouteConfigGroup calcRouteConfig) { Gbl.assertNotNull(network); Gbl.assertIf( network.getLinks().size()>0 ) ; // otherwise network for mode probably not defined this.network = network; this.routeAlgo = routeAlgo; this.mode = mode; this.populationFactory = populationFactory; this.stageActivityType = this.mode + " interaction"; if ( !calcRouteConfig.isInsertingAccessEgressWalk() ) { throw new RuntimeException("trying to use access/egress but not switched on in config. " + "currently not supported; there are too many other problems") ; } }
@Override public RoutingModule get() { if (filteredNetwork == null){ TransportModeNetworkFilter filter = new TransportModeNetworkFilter(network); Set<String> modes = new HashSet<>(); modes.add(TransportMode.car); filteredNetwork = NetworkUtils.createNetwork(); filter.filter(filteredNetwork, modes); } TravelDisutilityFactory travelDisutilityFactory = this.travelDisutilityFactory.get(PlansCalcRouteWithTollOrNot.CAR_WITH_PAYED_AREA_TOLL); TravelTime travelTime = travelTimes.get(TransportMode.car); LeastCostPathCalculator routeAlgo = leastCostPathCalculatorFactory.createPathCalculator( filteredNetwork, travelDisutilityFactory.createTravelDisutility(travelTime), travelTime); if ( plansCalcRouteConfigGroup.isInsertingAccessEgressWalk() ) { return DefaultRoutingModules.createAccessEgressNetworkRouter(TransportMode.car, populationFactory, filteredNetwork, routeAlgo, plansCalcRouteConfigGroup); } else { return DefaultRoutingModules.createPureNetworkRouter(TransportMode.car, populationFactory, filteredNetwork, routeAlgo); } // yyyyyy not so great that this differentiation is here; need to push it down a bit (again). kai, feb'2016 } }
if ( plansCalcRouteConfigGroup.isInsertingAccessEgressWalk() ) { return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, populationFactory, filteredNetwork, routeAlgo, plansCalcRouteConfigGroup) ;
if (config.plansCalcRoute().isInsertingAccessEgressWalk()) {
if (calcRouteConfig.isInsertingAccessEgressWalk()) { departureTime += NetworkRoutingInclAccessEgressModule.addBushwhackingLegFromFacilityToLinkIfNecessary( fromFacility, person, accessActLink, departureTime, result, population.getFactory(), if (calcRouteConfig.isInsertingAccessEgressWalk()) { NetworkRoutingInclAccessEgressModule.addBushwhackingLegFromLinkToFacilityIfNecessary(toFacility, person, egressActLink, departureTime, result, population.getFactory(), stageActivityType);
if ( ! config.plansCalcRoute().isInsertingAccessEgressWalk() ) {
public void testReplanCurrentLegRouteSeven() { createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9 } Activity activityH2; activityH2 = (Activity) plan.getPlanElements().get(4); activityH2.setLinkId(Id.create("l4", Link.class)); // move Activity location assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 2, 8.0*3600 )); // WH, en-route assertEquals(true, checkRouteValidity((NetworkRoute)((Leg)plan.getPlanElements().get(scndCarLeg)).getRoute())); } public void testReplanCurrentLegRouteEight()
public void testReplanCurrentLegRouteFour() { createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9 } Activity activityW1; activityW1 = (Activity) plan.getPlanElements().get(2); activityW1.setLinkId(Id.create("l2", Link.class)); // move Activity location assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 2, 8.0*3600 )); // HW, end Link final NetworkRoute route = (NetworkRoute)((Leg)plan.getPlanElements().get(firstCarLeg)).getRoute(); assertEquals(true, checkRouteValidity(route)); } public void testReplanCurrentLegRouteFive()
public void testReplanCurrentLegRouteTwo() { /* * replace destinations and create new routes */ // create new routes for HW-trip createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9 } Activity activityW1; activityW1 = (Activity) plan.getPlanElements().get(2); activityW1.setLinkId(Id.create("l2", Link.class)); // move Activity location final boolean result = ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 0, 8.0 * 3600); assertEquals(true, result); // HW, start Link final NetworkRoute route = (NetworkRoute)((Leg)plan.getPlanElements().get(firstCarLeg)).getRoute(); log.warn( route ); assertEquals(true, checkRouteValidity(route)); } public void testReplanCurrentLegRouteThree()
public void testReplanCurrentLegRouteFive() { // create new routes for WH-trip createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9 } Activity activityH2; activityH2 = (Activity) plan.getPlanElements().get(4); activityH2.setLinkId(Id.create("l4", Link.class)); // move Activity location assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 0, 8.0*3600 )); // WH, start Link assertEquals(true, checkRouteValidity((NetworkRoute)((Leg)plan.getPlanElements().get(scndCarLeg)).getRoute())); } public void testReplanCurrentLegRouteSix()
public void testReplanCurrentLegRouteEight() { createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9 } Activity activityH2; activityH2 = (Activity) plan.getPlanElements().get(4); activityH2.setLinkId(Id.create("l4", Link.class)); // move Activity location assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 3, 8.0*3600 ) ); // WH, en-route assertEquals(true, checkRouteValidity((NetworkRoute)((Leg)plan.getPlanElements().get(scndCarLeg)).getRoute())); } public void testReplanCurrentLegRouteNine()
public void testReplanCurrentLegRouteNine() { createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9 } Activity activityH2; activityH2 = (Activity) plan.getPlanElements().get(4); activityH2.setLinkId(Id.create("l4", Link.class)); // move Activity location assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 4, 8.0*3600 )); // WH, end Link assertEquals(true, checkRouteValidity((NetworkRoute)((Leg)plan.getPlanElements().get(scndCarLeg)).getRoute())); } public void testReplanCurrentLegRouteTen()
public void testReplanCurrentLegRouteThree() { createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9 } Activity activityW1; activityW1 = (Activity) plan.getPlanElements().get(2); activityW1.setLinkId(Id.create("l2", Link.class)); // move Activity location assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 1, 8.0*3600 ) ); // HW, en-route final NetworkRoute route = (NetworkRoute)((Leg)plan.getPlanElements().get(firstCarLeg)).getRoute(); assertEquals(true, checkRouteValidity(route)); } public void testReplanCurrentLegRouteFour()
public void testReplanCurrentLegRouteSix() { createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9 } Activity activityH2; activityH2 = (Activity) plan.getPlanElements().get(4); activityH2.setLinkId(Id.create("l4", Link.class)); // move Activity location assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 1, 8.0*3600 )); // WH, en-route assertEquals(true, checkRouteValidity((NetworkRoute)((Leg)plan.getPlanElements().get(scndCarLeg)).getRoute())); } public void testReplanCurrentLegRouteSeven()
public void testReplanCurrentLegRouteTen() { // expect EditRoutes to return false if the Route in the leg is not a NetworkRoute createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9 } Leg legHW = (Leg) plan.getPlanElements().get(firstCarLeg); Leg legWH = (Leg) plan.getPlanElements().get(scndCarLeg); legHW.setRoute(null); legHW.setMode(TransportMode.walk); legWH.setRoute(null); legWH.setMode(TransportMode.walk); assertEquals(false, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 0, 8.0*3600 )); assertEquals(false, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 0, 8.0*3600 )); }
if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9
int firstCarLeg = 1 ; // 1-->3 int scndCarLeg = 3 ; // 3-->9 if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndCarLeg = 9 ; // 3-->9
@Test public void passesVehicleFromOldPlan() { final Config config = ConfigUtils.loadConfig(IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("equil"), "config.xml")); config.plans().setInputFile("plans1.xml"); final Scenario scenario = ScenarioUtils.loadScenario(config); com.google.inject.Injector injector = Injector.createInjector(scenario.getConfig(), new AbstractModule() { @Override public void install() { install(new TripRouterModule()); install(new ScenarioByInstanceModule(scenario)); addTravelTimeBinding("car").toInstance(new FreespeedTravelTimeAndDisutility(config.planCalcScore())); addTravelDisutilityFactoryBinding("car").toInstance(new OnlyTimeDependentTravelDisutilityFactory()); } }); TripRouter tripRouter = injector.getInstance(TripRouter.class); PlanRouter testee = new PlanRouter(tripRouter); Plan plan = scenario.getPopulation().getPersons().get(Id.createPersonId(1)).getSelectedPlan(); Id<Vehicle> vehicleId = Id.create(1, Vehicle.class); ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).setVehicleId(vehicleId); testee.run(plan); if ( !config.plansCalcRoute().isInsertingAccessEgressWalk() ) { Assert.assertEquals("Vehicle Id transferred to new Plan", vehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).getVehicleId()); } else { Assert.assertEquals("Vehicle Id transferred to new Plan", vehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(1).getRoute()).getVehicleId()); // yy I changed get(0) to get(1) since in the input file there is no intervening walk leg, but in the output there is. kai, feb'16 } }
if ( !config.plansCalcRoute().isInsertingAccessEgressWalk() ) { Assert.assertEquals("Vehicle Id from TripRouter used", newVehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).getVehicleId()); } else {
int scndCarLeg = 3 ; // 3-->9 int thrdAct = 4 ; if ( scenario.getConfig().plansCalcRoute().isInsertingAccessEgressWalk() ) { firstCarLeg = 3 ; // 1-->3 scndAct = 6 ;