MATSIM
UmlaufInterpolator.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * UmlaufInterpolator.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22 package org.matsim.pt;
23 
24 import java.util.List;
25 
26 import org.matsim.api.core.v01.Id;
38 
39 public final class UmlaufInterpolator {
40 
41  private final Network network;
43 
44  public UmlaufInterpolator(Network network, final ScoringConfigGroup config) {
45  super();
46  this.network = network;
48  this.routingAlgo = new DijkstraFactory().createPathCalculator(network, travelTimes, travelTimes);
49  }
50 
54  public void addUmlaufStueckToUmlauf(UmlaufStueckI umlaufStueck, Umlauf umlauf) {
55  List<UmlaufStueckI> existingUmlaufStuecke = umlauf.getUmlaufStuecke();
56 
57  // check if final link of last umlaufStueck and first link of new umlaufStueck are connected; otherwise compute and insert connecting route:
58  if (! existingUmlaufStuecke.isEmpty()) {
59  UmlaufStueckI previousUmlaufStueck = existingUmlaufStuecke.get(existingUmlaufStuecke.size() - 1);
60  NetworkRoute previousCarRoute = previousUmlaufStueck.getCarRoute();
61  Id<Link> fromLinkId = previousCarRoute.getEndLinkId();
62  Id<Link> toLinkId = umlaufStueck.getCarRoute().getStartLinkId();
63  if (!fromLinkId.equals(toLinkId)) {
64  insertWenden(fromLinkId, toLinkId, umlauf);
65  }
66  }
67 
68  existingUmlaufStuecke.add(umlaufStueck);
69  }
70 
71  private void insertWenden(Id<Link> fromLinkId, Id<Link> toLinkId, Umlauf umlauf) {
72  Node startNode = this.network.getLinks().get(fromLinkId).getToNode();
73  Node endNode = this.network.getLinks().get(toLinkId).getFromNode();
74  double depTime = 0.0;
75  Path wendenPath = routingAlgo.calcLeastCostPath(startNode, endNode, depTime, null, null);
76  if (wendenPath == null) {
77  throw new RuntimeException("No route found from node "
78  + startNode.getId() + " to node " + endNode.getId() + ".");
79  }
80  NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(fromLinkId, toLinkId);
81  route.setLinkIds(fromLinkId, NetworkUtils.getLinkIds(wendenPath.links), toLinkId);
82  umlauf.getUmlaufStuecke().add(new Wenden(route));
83  }
84 
85 }
void insertWenden(Id< Link > fromLinkId, Id< Link > toLinkId, Umlauf umlauf)
void addUmlaufStueckToUmlauf(UmlaufStueckI umlaufStueck, Umlauf umlauf)
Path calcLeastCostPath(Node fromNode, Node toNode, double starttime, final Person person, final Vehicle vehicle)
final LeastCostPathCalculator routingAlgo
static NetworkRoute createLinkNetworkRouteImpl(Id< Link > startLinkId, Id< Link > endLinkId)
static List< Id< Link > > getLinkIds(final String links)
Map< Id< Link >, ? extends Link > getLinks()
NetworkRoute getCarRoute()
synchronized LeastCostPathCalculator createPathCalculator(final Network network, final TravelDisutility travelCosts, final TravelTime travelTimes)
boolean equals(Object obj)
Definition: Id.java:139
void setLinkIds(final Id< Link > startLinkId, final List< Id< Link >> linkIds, final Id< Link > endLinkId)
List< UmlaufStueckI > getUmlaufStuecke()
UmlaufInterpolator(Network network, final ScoringConfigGroup config)