20 package org.matsim.core.router;
37 import java.util.Arrays;
38 import java.util.List;
51 class LinkToLinkRoutingModule
implements RoutingModule {
52 private final Network network;
53 private final Network invertedNetwork;
54 private final LeastCostPathCalculator leastCostPathCalculator;
55 private final PopulationFactory populationFactory;
56 private final String mode;
58 LinkToLinkRoutingModule(
final String mode,
final PopulationFactory populationFactory,
59 Network network, Network invertedNetwork, InvertedLeastPathCalculator leastCostPathCalc) {
60 this.network = network;
61 this.invertedNetwork = invertedNetwork;
62 this.populationFactory = populationFactory;
64 this.leastCostPathCalculator = leastCostPathCalc;
68 public List<? extends PlanElement> calcRoute(RoutingRequest request) {
69 final Facility fromFacility = request.getFromFacility();
70 final Facility toFacility = request.getToFacility();
71 final double departureTime = request.getDepartureTime();
72 final Person person = request.getPerson();
74 Leg newLeg = this.populationFactory.createLeg( this.mode );
76 Gbl.assertNotNull(fromFacility);
77 Gbl.assertNotNull(toFacility);
79 if (!toFacility.getLinkId().equals(fromFacility.getLinkId())) {
81 Node fromInvNode = this.invertedNetwork.getNodes()
82 .get(Id.create(fromFacility.getLinkId(), Node.class));
83 Node toInvNode = this.invertedNetwork.getNodes().get(Id.create(toFacility.getLinkId(), Node.class));
85 Path path = leastCostPathCalculator.calcLeastCostPath(fromInvNode, toInvNode, departureTime, person, null);
88 + fromFacility.getLinkId() +
" to link " + toFacility.getLinkId() +
".");
91 NetworkRoute route = this.populationFactory.getRouteFactories().createRoute(NetworkRoute.class, fromFacility.getLinkId(), toFacility.getLinkId());
92 route.setLinkIds(fromFacility.getLinkId(), NetworkUtils.getLinkIds(path.links), toFacility.getLinkId());
93 route.setTravelTime(path.travelTime);
94 route.setTravelCost(path.travelCost);
95 route.setDistance(RouteUtils.calcDistance(route, 1.0, 1.0,
this.network));
96 newLeg.setRoute(route);
97 newLeg.setTravelTime(path.travelTime);
101 NetworkRoute route = this.populationFactory.getRouteFactories().createRoute(NetworkRoute.class, fromFacility.getLinkId(), toFacility.getLinkId());
102 route.setTravelTime(0);
103 route.setDistance(0.0);
104 newLeg.setRoute(route);
105 newLeg.setTravelTime(0);
107 newLeg.setDepartureTime(departureTime);
108 return Arrays.asList( newLeg );