21 package org.matsim.withinday.utils;
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.apache.logging.log4j.LogManager;
27 import org.apache.logging.log4j.Logger;
79 private static final Logger
log = LogManager.getLogger(
EditRoutes.class);
123 if (path == null)
throw new RuntimeException(
"No route found from node " + startNode.
getId() +
" to node " + endNode.
getId() +
".");
137 if ( !(pe instanceof
Leg) ) {
163 List<? extends PlanElement> planElements = tripRouter.
calcRoute(leg.
getMode(), fromFacility, toFacility,
166 if (planElements.size() != 1) {
167 throw new RuntimeException(
"Expected a list of PlanElements containing exactly one element, " +
168 "but the returned list contained " + planElements.size() +
" elements.");
171 Leg newLeg = (
Leg) planElements.get(0);
247 log.warn(
"route not instance of NetworkRoute");
251 NetworkRoute oldRoute = (NetworkRoute) route;
258 Id<Link> currentLinkId = oldLinkIds.
get(currentLinkIndex);
260 final Link startLink = network.
getLinks().get(currentLinkId);
271 static void spliceNewPathIntoOldRoute(
int currentLinkIndex,
Id<Link> toLinkId,
NetworkRoute oldRoute,
273 List<Id<Link>> oldLinkIds = oldRoute.
getLinkIds();
274 List<Id<Link>> resultingLinkIds =
new ArrayList<>();
286 if (currentLinkIndex > 0) {
289 resultingLinkIds.addAll(oldLinkIds.subList(0, currentLinkIndex-1));
296 resultingLinkIds.add(currentLinkId);
310 if (resultingLinkIds.size() > 0 && newLinksIds.size()>0
311 && resultingLinkIds.get(resultingLinkIds.size() - 1).equals( newLinksIds.get( newLinksIds.size()-1 ) )
313 resultingLinkIds.remove( resultingLinkIds.size()-1 );
316 resultingLinkIds.addAll( newLinksIds ) ;
318 StringBuilder strb =
new StringBuilder() ;
319 for (
int ii= Math.max(0,currentLinkIndex-2) ; ii < Math.min( resultingLinkIds.size(), currentLinkIndex+3) ; ii++ ) {
321 strb.append( resultingLinkIds.get(ii) ) ;
324 log.info(
"linkIds at join: " + strb ) ;
372 log.warn(
"route not instance of NetworkRoute");
388 List<Id<Link>> linkIds =
new ArrayList<>();
391 NetworkRoute networkRoute = (NetworkRoute) route;
396 throw new RuntimeException(
"Currently only NetworkRoutes are supported for Within-Day Replanning!");
synchronized List<? extends PlanElement > calcRoute(final String mainMode, final Facility fromFacility, final Facility toFacility, final double departureTime, final Person person, final Attributes routingAttributes)
static Integer getCurrentRouteLinkIdIndex(MobsimAgent agent)
static< T > Id< T > get(int index, final Class< T > type)
Id< Link > getStartLinkId()
Attributes getAttributes()
RouteFactories routeFactories
static List< Id< Link > > getRouteLinkIds(Route route)
static Integer getCurrentPlanElementIndex(MobsimAgent agent)
boolean relocateFutureLegRoute(Leg leg, Id< Link > fromLinkId, Id< Link > toLinkId, Person person)
boolean replanFutureLegRoute(Leg leg, Person person)
OptionalTime getDepartureTime()
Path calcLeastCostPath(Node fromNode, Node toNode, double starttime, final Person person, final Vehicle vehicle)
final LeastCostPathCalculator getPathCalculator()
boolean replanCurrentLegRoute(Leg leg, Person person, int currentLinkIndex, double time)
EditRoutes(Network network, LeastCostPathCalculator pathCalculator, PopulationFactory popFactory)
List< Id< Link > > getLinkIds()
LeastCostPathCalculator pathCalculator
RouteFactories getRouteFactories()
final void replanCurrentLeg(MobsimAgent agent, double now)
void setRoute(Route route)
List< PlanElement > getPlanElements()
static List< Id< Link > > getLinkIds(final String links)
static double calcDistance(final NetworkRoute networkRoute, final double relPosOnDepartureLink, final double relPosOnArrivalLink, final Network network)
static void resetCaches(MobsimAgent agent)
Map< Id< Link >, ? extends Link > getLinks()
boolean relocateCurrentLegRoute(Leg leg, Person person, int currentLinkIndex, Id< Link > toLinkId, double time)
static boolean relocateFutureLegRoute(Leg leg, Id< Link > fromLinkId, Id< Link > toLinkId, Person person, Network network, TripRouter tripRouter, Activity fromActivity)
void setTravelTime(final double seconds)
void setLinkIds(final Id< Link > startLinkId, final List< Id< Link >> linkIds, final Id< Link > endLinkId)
Id< Link > getEndLinkId()
static Plan getModifiablePlan(MobsimAgent agent)