@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); }
private static void replaceRemainderOfCurrentRoute(Leg currentLeg, List<? extends PlanElement> newTrip, MobsimAgent agent) { Leg newCurrentLeg = (Leg) newTrip.get(0) ; Gbl.assertNotNull(newCurrentLeg); // prune remaining route from current route: NetworkRoute oldNWRoute = (NetworkRoute) currentLeg.getRoute(); final Integer currentRouteLinkIdIndex = WithinDayAgentUtils.getCurrentRouteLinkIdIndex(agent); final NetworkRoute newNWRoute = (NetworkRoute)newCurrentLeg.getRoute(); final List<Id<Link>> newLinksIds = newNWRoute.getLinkIds().subList(0,newNWRoute.getLinkIds().size()) ; EditRoutes.spliceNewPathIntoOldRoute(currentRouteLinkIdIndex, newNWRoute.getEndLinkId(), oldNWRoute, newLinksIds, agent.getCurrentLinkId()) ; // for (int ii = currentRouteLinkIdIndex; ii<oldNWRoute.getLinkIds().size() ; ii++ ) { // oldNWRoute.getLinkIds().remove(ii) ; // } // // // now add the new route (yyyyyy not sure if it starts with correct link) // oldNWRoute.getLinkIds().addAll( newNWRoute.getLinkIds() ) ; // // // also change the arrival link id: // oldNWRoute.setEndLinkId( newNWRoute.getEndLinkId() ) ; WithinDayAgentUtils.resetCaches(agent); } private static void pruneUpToCurrentLeg(Leg currentLeg, List<? extends PlanElement> newTrip) {
@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; }