20 package org.matsim.core.population.routes;
22 import java.util.ArrayList;
23 import java.util.List;
25 import org.apache.logging.log4j.LogManager;
26 import org.apache.logging.log4j.Logger;
49 private static final Logger
log = LogManager.getLogger(
RouteUtils.class ) ;
62 List<Node> nodes =
new ArrayList<>(linkIds.size() + 1);
63 if ((linkIds.size() > 0)) {
64 nodes.add(network.
getLinks().get(linkIds.get(0)).getFromNode());
76 ArrayList<Link> links =
new ArrayList<>(nodes.size());
78 for (
Node node : nodes) {
79 if (prevNode != null) {
81 if (foundLink != null) {
92 ArrayList<Link> links =
new ArrayList<>(nodeIds.size());
96 if (prevNode != null) {
98 if (foundLink != null) {
110 if (link.getToNode().equals(node)) {
121 List<Id<Link>> linkIds =
new ArrayList<>(route.
getLinkIds().size() + 2);
128 fromLinkId = link.
getId();
131 toLinkId = link.
getId();
150 dist += network.
getLinks().get(linkId).getLength();
157 double newTravelTime = 0.0;
159 now + newTravelTime, person, vehicle);
160 return newTravelTime;
178 routeDistance += network.
getLinks().get(networkRoute.
getStartLinkId()).getLength() * (1.0 - relPosOnDepartureLink);
181 routeDistance += network.
getLinks().get(networkRoute.
getEndLinkId()).getLength() * relPosOnArrivalLink;
184 routeDistance -= network.
getLinks().get(networkRoute.
getEndLinkId()).getLength() * (1.0 - relPosOnArrivalLink);
186 return routeDistance;
195 double startTime = now;
206 return now - startTime;
212 for (
Link link : path.links ) {
223 List<Id<Link>> linksBetween = (routeLinkIds.size() > 2) ? routeLinkIds.subList(1, routeLinkIds.size() - 1) :
new ArrayList<>(0);
224 Id<Link> endLinkId = routeLinkIds.
get(routeLinkIds.size() - 1);
226 route.
setLinkIds(startLinkId, linksBetween, endLinkId);
242 return calcDistance(tr, accessFacility, egressFacility, network);
251 boolean count =
false;
259 log.error(
"link is null; linkId=" + linkId +
"; network=" + network ) ;
263 if (enterLinkId.
equals(linkId)) {
266 if (exitLinkId.
equals(linkId)) {
291 double routeLength = 0. ;
292 double coveredLength = 0. ;
301 if ( routeLength > 0. ) {
302 return coveredLength/routeLength ;
313 return new LinkNetworkRouteImpl(startLinkId, endLinkId);
318 return new LinkNetworkRouteImpl(startLinkId, linkIds, endLinkId);
323 return new LinkNetworkRouteImpl(startLinkId, linkIds, endLinkId);
Map< Id< TransitRoute >, TransitRoute > getRoutes()
static< T > Id< T > get(int index, final Class< T > type)
Id< Link > getStartLinkId()
Map< Id< Node >, ? extends Node > getNodes()
Map< Id< TransitStopFacility >, TransitStopFacility > getFacilities()
static Route createGenericRouteImpl(Id< Link > startLinkId, Id< Link > endLinkId)
static List< Link > getLinksFromNodes(final List< Node > nodes)
Id< TransitRoute > getRouteId()
static Link findLink(Node prevNode, Node node)
double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle)
NetworkRoute getSubRoute(final Id< Link > fromLinkId, final Id< Link > toLinkId)
List< Id< Link > > getLinkIds()
static List< Link > getLinksFromNodeIds(final Network network, final List< Id< Node >> nodeIds)
static NetworkRoute createLinkNetworkRouteImpl(Id< Link > startLinkId, List< Id< Link >> linkIds, Id< Link > endLinkId)
static double calcDistance(TransitRoute tr, TransitStopFacility accessFacility, TransitStopFacility egressFacility, Network network)
static NetworkRoute createLinkNetworkRouteImpl(Id< Link > startLinkId, Id< Link > endLinkId)
Id< TransitStopFacility > getEgressStopId()
Id< TransitLine > getLineId()
static NetworkRoute createNetworkRoute(List< Id< Link >> routeLinkIds)
static NetworkRoute createNetworkRoute(List< Id< Link >> routeLinkIds, Network network)
static void assertNotNull(Object obj)
static double calcDistance(final NetworkRoute networkRoute, final double relPosOnDepartureLink, final double relPosOnArrivalLink, final Network network)
Map< Id< Link >, ? extends Link > getLinks()
static double calcDistance(TransitPassengerRoute route, TransitSchedule ts, Network network)
static List< Node > getNodes(final NetworkRoute route, final Network network)
static double calcTravelTimeExcludingStartEndLink(final NetworkRoute networkRoute, double now, Person person, Vehicle vehicle, final Network network, TravelTime travelTime)
static double calcDistanceExcludingStartEndLink(final NetworkRoute route, final Network network)
static NetworkRoute createLinkNetworkRouteImpl(Id< Link > startLinkId, Id< Link >[] linkIds, Id< Link > endLinkId)
static double calcDistance(final LeastCostPathCalculator.Path path)
static double calculateCoverage(NetworkRoute route1, NetworkRoute route2, Network network)
Map< Id< Link >, ? extends Link > getOutLinks()
boolean equals(Object obj)
void setLinkIds(final Id< Link > startLinkId, final List< Id< Link >> linkIds, final Id< Link > endLinkId)
static double calcTravelTime(final NetworkRoute networkRoute, final double relPosOnDepartureLink, final double relPosOnArrivalLink, double now, Person person, Vehicle vehicle, final Network network, TravelTime travelTime)
Id< Link > getEndLinkId()
Map< Id< TransitLine >, TransitLine > getTransitLines()
static NetworkRoute getSubRoute(final NetworkRoute route, final Node fromNode, final Node toNode, final Network network)
Id< TransitStopFacility > getAccessStopId()