MATSIM
HeavyCompressedNetworkRouteFactory.java
Go to the documentation of this file.
1 package org.matsim.core.population.routes.heavycompressed;
2 
3 import org.matsim.api.core.v01.Id;
9 
14 
15  private final Network network;
16  private CompressionData compressionData = null;
17  private final String preferredMode;
18 
23  public HeavyCompressedNetworkRouteFactory(Network network, String preferredMode) {
24  this.network = network;
25  this.preferredMode = preferredMode;
26  }
27 
28  @Override
29  public NetworkRoute createRoute(final Id<Link> startLinkId, final Id<Link> endLinkId) {
30  if (this.network==null) {
31  throw new RuntimeException( "need to set Network in Population in order to be able to create compressed routes") ;
32  }
33  if (this.compressionData == null) {
34  Link[] subsequentLinks = new SubsequentLinksAnalyzer(this.network, this.preferredMode).getSubsequentLinks();
35  this.compressionData = createCompressionData(this.network, subsequentLinks);
36  }
37  return new HeavyCompressedNetworkRoute(startLinkId, endLinkId, this.compressionData);
38  }
39 
40  static CompressionData createCompressionData(Network network, Link[] subsequentLinks) {
41  Link[] links = new Link[Id.getNumberOfIds(Link.class)];
42  for (Link link : network.getLinks().values()) {
43  links[link.getId().index()] = link;
44  }
45  return new CompressionData(links, subsequentLinks);
46  }
47 
48  @Override
49  public String getCreatedRouteType() {
50  return "links";
51  }
52 
53  record CompressionData(Link[] links, Link[] subsequentLinks) {
54  }
55 }
static< T > int getNumberOfIds(final Class< T > type)
Definition: Id.java:122
NetworkRoute createRoute(final Id< Link > startLinkId, final Id< Link > endLinkId)
Map< Id< Link >, ? extends Link > getLinks()