MATSIM
RaptorRoute.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.* *
3  *
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2023 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package ch.sbb.matsim.routing.pt.raptor;
22 
28 
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.List;
32 
36 public class RaptorRoute {
37 
38  final Facility fromFacility;
39  final Facility toFacility;
40  private final double totalCosts;
41  private double departureTime = Double.NaN;
42  private double travelTime = 0;
43  private int ptLegCount = 0;
44  private final List<RoutePart> editableParts = new ArrayList<>();
45  final List<RoutePart> parts = Collections.unmodifiableList(this.editableParts);
46 
47  RaptorRoute(Facility fromFacility, Facility toFacility, double totalCosts) {
48  this.fromFacility = fromFacility;
49  this.toFacility = toFacility;
50  this.totalCosts = totalCosts;
51  }
52 
53  void addNonPt(TransitStopFacility fromStop, TransitStopFacility toStop, double depTime, double travelTime, double distance, String mode) {
54  this.editableParts.add(new RoutePart(fromStop, toStop, mode, depTime, Double.NaN, Double.NaN, depTime + travelTime, distance, null, null, null));
55  if (Double.isNaN(this.departureTime)) {
56  this.departureTime = depTime;
57  }
58  this.travelTime += travelTime;
59  }
60 
61  void addPlanElements(double depTime, double travelTime, List<? extends PlanElement> planElements) {
62  this.editableParts.add(new RoutePart(null, null, null, depTime, Double.NaN, Double.NaN, depTime + travelTime, Double.NaN, null, null, planElements));
63  if (Double.isNaN(this.departureTime)) {
64  this.departureTime = depTime;
65  }
66  this.travelTime += travelTime;
67  }
68 
69  void addPt(TransitStopFacility fromStop, TransitStopFacility toStop, TransitLine line, TransitRoute route, String mode, double depTime, double boardingTime, double vehDepTime, double arrivalTime, double distance) {
70  this.editableParts.add(new RoutePart(fromStop, toStop, mode, depTime, boardingTime, vehDepTime, arrivalTime, distance, line, route, null));
71  if (Double.isNaN(this.departureTime)) {
72  this.departureTime = depTime;
73  }
74  this.travelTime += (arrivalTime - depTime);
75  this.ptLegCount++;
76  }
77 
78  public double getTotalCosts() {
79  return this.totalCosts;
80  }
81 
82  public double getDepartureTime() {
83  return this.departureTime;
84  }
85 
86  public double getTravelTime() {
87  return this.travelTime;
88  }
89 
90  public int getNumberOfTransfers() {
91  if (this.ptLegCount > 0) {
92  return this.ptLegCount - 1;
93  }
94  return 0;
95  }
96 
98  return this.parts;
99  }
100 
101  public static final class RoutePart {
104  public final String mode;
105  // the agent's departure time, i.e. when the agent starts waiting for this bus/train/...
106  public final double depTime;
107  public final double boardingTime;
108  public final double vehicleDepTime;
109  public final double arrivalTime;
110  public final double distance;
111  public final TransitLine line;
112  public final TransitRoute route;
113  final List<? extends PlanElement> planElements;
114 
115  RoutePart(TransitStopFacility fromStop, TransitStopFacility toStop, String mode, double depTime, double boardingTime, double vehicleDepTime, double arrivalTime, double distance, TransitLine line, TransitRoute route, List<? extends PlanElement> planElements) {
116  this.fromStop = fromStop;
117  this.toStop = toStop;
118  this.mode = mode;
119  this.depTime = depTime;
120  this.boardingTime = boardingTime;
121  this.vehicleDepTime = vehicleDepTime;
122  this.arrivalTime = arrivalTime;
123  this.distance = distance;
124  this.line = line;
125  this.route = route;
126  this.planElements = planElements;
127  }
128  }
129 }