@Deprecated // yyyy but I don't have an easy replacement yet // (maybe just editTrips.replanCurrentTrip(...)?) protected final void reRouteCurrentLeg( MobsimAgent agent, double now ) { Plan plan = WithinDayAgentUtils.getModifiablePlan(agent) ; PlanElement pe = plan.getPlanElements().get( WithinDayAgentUtils.getCurrentPlanElementIndex(agent)) ; if ( !(pe instanceof Leg) ) { return ; } int currentLinkIndex = WithinDayAgentUtils.getCurrentRouteLinkIdIndex(agent) ; this.editRoutes.replanCurrentLegRoute((Leg)pe, ((HasPerson)agent).getPerson(), currentLinkIndex, now ) ; WithinDayAgentUtils.resetCaches(agent); } @Deprecated // I don't think that this is really needed for the bushfire applications. kai, nov'17
public final void replanCurrentLeg( MobsimAgent agent, double now ) { Plan plan = WithinDayAgentUtils.getModifiablePlan(agent) ; PlanElement pe = plan.getPlanElements().get( WithinDayAgentUtils.getCurrentPlanElementIndex(agent)) ; if ( !(pe instanceof Leg) ) { return ; } int currentLinkIndex = WithinDayAgentUtils.getCurrentRouteLinkIdIndex(agent) ; this.replanCurrentLegRoute((Leg)pe, ((HasPerson)agent).getPerson(), currentLinkIndex, now ) ; WithinDayAgentUtils.resetCaches(agent); }
@Override public boolean doReplanning(MobsimAgent withinDayAgent) { Plan executedPlan = WithinDayAgentUtils.getModifiablePlan(withinDayAgent); // If we don't have an executed plan if (executedPlan == null) return false; PlanElement currentPlanElement = WithinDayAgentUtils.getCurrentPlanElement(withinDayAgent); if (!(currentPlanElement instanceof Leg)) return false; Leg currentLeg = (Leg) currentPlanElement; int currentLinkIndex = WithinDayAgentUtils.getCurrentRouteLinkIdIndex(withinDayAgent); EditRoutes editRoutes = new EditRoutes( scenario.getNetwork(), pathCalculator, populationFactory ) ; editRoutes.replanCurrentLegRoute(currentLeg, executedPlan.getPerson(), currentLinkIndex, this.time ) ; // Finally reset the cached Values of the PersonAgent - they may have changed! WithinDayAgentUtils.resetCaches(withinDayAgent); return true; }
ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), -1, 8.0*3600 ); ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 100, 8.0*3600 ); fail("expected ArrayIndexOutOfBoundsException."); } catch (ArrayIndexOutOfBoundsException e) { assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 0, 8.0*3600 )); // HW, start Link assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 1, 8.0*3600 )); // HW, en-route assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(firstCarLeg), plan.getPerson(), 2, 8.0*3600 )); // HW, end Link assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 0, 8.0*3600 )); // WH, start Link assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 1, 8.0*3600 )); // WH, en-route assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 2, 8.0*3600 )); // WH, en-route assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 3, 8.0*3600 )); // WH, en-route assertEquals(true, ed.replanCurrentLegRoute((Leg) plan.getPlanElements().get(scndCarLeg), plan.getPerson(), 4, 8.0*3600 )); // WH, end Link
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 )); }
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 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 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 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 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()