20 package org.matsim.core.router;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
29 import org.apache.logging.log4j.LogManager;
30 import org.apache.logging.log4j.Logger;
62 import javax.annotation.Nullable;
118 throw new RuntimeException(
"trying to use access/egress but not switched on in config. " 119 +
"currently not supported; there are too many other problems");
121 hasWarnedAccessEgress =
true;
123 ". That means, access and egress won't get network-routed - even if you specified corresponding RoutingModules for access and egress ");
125 if (invertedNetwork != null && !(routeAlgo instanceof InvertedLeastPathCalculator)) {
126 throw new IllegalArgumentException(
"Inverted network must be used with inverted least path calculator.");
146 double now = departureTime;
148 List<PlanElement> result =
new ArrayList<>();
154 if(accessTrip == null )
return null;
156 result.addAll(accessTrip);
161 Leg newLeg = this.populationFactory.
createLeg(this.mode);
163 now += routeLeg(person, newLeg, accessActLink, egressActLink, now);
173 if(egressTrip == null )
return null;
174 result.addAll(egressTrip);
181 final Link egressActLink,
double departureTime,
PlanElement previousPlanElement,
185 log.debug(
"do bushwhacking leg from link=" + egressActLink.
getId() +
" to facility=" + toFacility.toString());
188 return Collections.emptyList();
195 List<PlanElement> egressTrip =
new ArrayList<>();
197 if (previousPlanElement instanceof
Leg) {
199 egressTrip.add(interactionActivity);
207 if (endLinkId == null) {
208 endLinkId = startLinkId;
217 egressTrip.add(egressLeg);
225 egressTrip.add(egressLeg);
228 List<? extends PlanElement> networkRoutedEgressTrip = egressFromNetworkRouter.
calcRoute(
DefaultRoutingRequest.
of(fromFacility, toFacility, departureTime, person, routingAttributes));
229 if(networkRoutedEgressTrip == null)
return null;
237 egressTrip.addAll(networkRoutedEgressTrip);
245 if (toFacility.
getCoord() == null) {
254 final Link accessActLink,
double departureTime,
258 return Collections.emptyList();
262 List<PlanElement> accessTrip =
new ArrayList<>();
271 if (startLinkId == null) {
272 startLinkId = accessActLink.
getId();
278 accessTrip.add(accessLeg);
283 if (startLinkId == null) {
284 startLinkId = accessActLink.
getId();
292 accessTrip.add(accessLeg);
296 List<? extends PlanElement> networkRoutedAccessTrip = accessToNetworkRouter.
calcRoute(
DefaultRoutingRequest.
of(fromFacility, toFacility, departureTime, person, routingAttributes));
297 if (networkRoutedAccessTrip == null)
return null;
305 accessTrip.addAll(networkRoutedAccessTrip);
311 accessTrip.add(interactionActivity);
330 log.fatal(
"(1) " +
TransportMode.
walk +
" is teleported. Then you need to define the corresponding teleportation (= mode routing) params for " +
TransportMode.
walk +
"." );
331 log.fatal(
"(2) " +
TransportMode.
walk +
" is routed on the network. Then you need to define the corresponding teleportation (= mode routing) params for " 333 log.fatal(
"The old default fallback bevhavior was disabled in may'21.");
334 throw new RuntimeException(
"Need teleportation params for bushwhacking modes. See log statements above." );
372 double estimatedNetworkDistance = dist * beelineDistanceFactor;
373 int travTime = (int) (estimatedNetworkDistance / networkTravelSpeed);
385 return "[NetworkRoutingModule: mode=" + this.mode +
"]";
388 double routeLeg(
Person person,
Leg leg,
Link fromLink,
Link toLink,
double depTime) {
394 if (toLink != fromLink) {
396 if (invertedNetwork != null) {
405 throw new RuntimeException(
"No route found from node " + startNode.
getId() +
" to node " + endNode.
getId() +
" for mode " + mode +
".");
411 double relPosOnDepartureLink = 1.0;
412 double relPosOnArrivalLink = 1.0;
415 double travelTimeEstimateOnToLink = (toLink.
getLength() / maxSpeedOnToLink) * relPosOnArrivalLink;
416 route.setTravelTime((
int) (path.
travelTime+travelTimeEstimateOnToLink));
419 route.setDistance(
RouteUtils.
calcDistance(route, relPosOnDepartureLink, relPosOnArrivalLink,
this.filteredNetwork));
420 route.setVehicleId(vehicleId);
AccessEgressType getAccessEgressType()
static boolean isNotNeedingBushwhackingLeg(Facility toFacility)
Attributes getAttributes()
Map< Id< Node >, ? extends Node > getNodes()
final RoutingModule egressFromNetworkRouter
final Network filteredNetwork
void setDistance(final double distance)
static RoutingRequest of(Facility fromFacility, Facility toFacility, double departureTime, Person person, Attributes attributes)
final LeastCostPathCalculator routeAlgo
static double calcEuclideanDistance(Coord coord, Coord other)
static void assertIf(boolean flag)
Map< String, TeleportedModeParams > getModeRoutingParams()
Leg createLeg(String legMode)
void setDepartureTime(final double seconds)
final RoutingConfigGroup.AccessEgressType accessEgressType
final double getMaximumVelocity()
Link decideAccessLink(RoutingRequest request, Network network)
static OptionalTime getLinkEgressTime(Link link, String routingMode)
Double getBeelineDistanceFactor()
Path calcLeastCostPath(Node fromNode, Node toNode, double starttime, final Person person, final Vehicle vehicle)
static< T > Id< T > create(final long key, final Class< T > type)
final TimeInterpretation timeInterpretation
static Facility wrapLinkAndCoord(final Link link, final Coord coord)
double getDepartureTime()
static boolean hasWarnedAccessEgress
RouteFactories getRouteFactories()
static Coord findNearestPointOnLink(Coord coord, Link link)
Population getPopulation()
static Id< Vehicle > getVehicleId(Person person, String mode)
List<? extends PlanElement > calcRoute(RoutingRequest request)
abstract void setVehicleId(final Id< Vehicle > vehicleId)
Double getTeleportedModeSpeed()
void setRoute(Route route)
List<? extends PlanElement > computeAccessTripFromFacilityToLinkIfNecessary(final Facility fromFacility, final Person person, final Link accessActLink, double departureTime, final PopulationFactory populationFactory, final String stageActivityType, Config config, Attributes routingAttributes)
static void assertNotNull(Object obj)
static List< Id< Link > > getLinkIds(final String links)
static double calcDistance(final NetworkRoute networkRoute, final double relPosOnDepartureLink, final double relPosOnArrivalLink, final Network network)
Link decideEgressLink(RoutingRequest request, Network network)
RoutingConfigGroup routing()
Map< Id< Link >, ? extends Link > getLinks()
final MultimodalLinkChooser multimodalLinkChooser
List< PlanElement > computeEgressTripFromLinkToFacilityIfNecessary(final Facility toFacility, final Person person, final Link egressActLink, double departureTime, PlanElement previousPlanElement, final PopulationFactory populationFactory, final String stageActivityType, Config config, Attributes routingAttributes)
OptionalTime getTravelTime()
OptionalTime decideOnElementsEndTime(List<? extends PlanElement > elements, final double startTime)
static Activity createInteractionActivity(final Coord interactionCoord, final Id< Link > interactionLink, final String mode)
static final String non_network_walk
void setTravelTime(final double seconds)
Map< Id< Vehicle >, Vehicle > getVehicles()
final PopulationFactory populationFactory
synchronized List<? extends PlanElement > calcRoute(RoutingRequest request)
static OptionalTime getLinkAccessTime(Link link, String routingMode)
final Network invertedNetwork
PopulationFactory getFactory()
accessEgressModeToLinkPlusTimeConstant
static Activity createStageActivityFromCoordLinkIdAndModePrefix(final Coord interactionCoord, final Id< Link > interactionLink, String modePrefix)
static List< Leg > getLegs(final Plan plan)
static void routeBushwhackingLeg(Person person, Leg leg, Coord fromCoord, Coord toCoord, double depTime, Id< Link > dpLinkId, Id< Link > arLinkId, PopulationFactory pf, Config config)
void setTravelTime(final double travelTime)
final RoutingModule accessToNetworkRouter
Facility getFromFacility()