MATSIM
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility Class Reference
Inheritance diagram for org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility:
Inheritance graph
[legend]

Public Member Functions

 TransitRouterNetworkTravelTimeAndDisutility (final TransitRouterConfig config)
 
 TransitRouterNetworkTravelTimeAndDisutility (final TransitRouterConfig config, PreparedTransitSchedule preparedTransitSchedule)
 
double getLinkTravelDisutility (final Link link, final double time, final Person person, final Vehicle vehicle, final CustomDataManager dataManager)
 
double getLinkTravelTime (final Link link, final double time, Person person, Vehicle vehicle)
 
double getVehArrivalTime (final Link link, final double now)
 
double getWalkTravelDisutility (Person person, Coord coord, Coord toCoord)
 
double getWalkTravelTime (Person person, Coord coord, Coord toCoord)
 

Protected Member Functions

double offVehicleWaitTime (final Link link, final double time)
 
final double defaultTransferCost (final Link link, final double time, final Person person, final Vehicle vehicle)
 

Protected Attributes

final TransitRouterConfig config
 

Private Attributes

Link previousLink = null
 
double previousTime = Double.NaN
 
double cachedTravelTime = Double.NaN
 
final PreparedTransitSchedule preparedTransitSchedule
 

Detailed Description

TravelTime and TravelCost calculator to be used with the transit network used for transit routing.

This class is NOT thread-safe!

Author
mrieser

Definition at line 39 of file TransitRouterNetworkTravelTimeAndDisutility.java.

Constructor & Destructor Documentation

◆ TransitRouterNetworkTravelTimeAndDisutility() [1/2]

org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.TransitRouterNetworkTravelTimeAndDisutility ( final TransitRouterConfig  config)

◆ TransitRouterNetworkTravelTimeAndDisutility() [2/2]

org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.TransitRouterNetworkTravelTimeAndDisutility ( final TransitRouterConfig  config,
PreparedTransitSchedule  preparedTransitSchedule 
)

Member Function Documentation

◆ getLinkTravelDisutility()

double org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getLinkTravelDisutility ( final Link  link,
final double  time,
final Person  person,
final Vehicle  vehicle,
final CustomDataManager  dataManager 
)

Returns the disutility to travel on the specified link at the specified time.

Parameters
linkThe link for which the travel disutility is calculated.
timeThe departure time (in seconds since 00:00) at the beginning of the link for which the disutility is calculated.
personThe person that wants to travel along the link. Note that this parameter can be null!
vehicleThe vehicle with which the person wants to travel along the link. Note that this parameter can be null!
dataManagerA helper class to enable the cost calculator store arbitrary data during one routing request.
Returns
The disutility to travel over the link link, departing at time time.

Implements org.matsim.pt.router.TransitTravelDisutility.

Definition at line 67 of file TransitRouterNetworkTravelTimeAndDisutility.java.

References org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.defaultTransferCost(), org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink.getLength(), org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getLinkTravelTime(), org.matsim.pt.router.TransitRouterConfig.getMarginalUtilityOfTravelDistancePt_utl_m(), org.matsim.pt.router.TransitRouterConfig.getMarginalUtilityOfTravelTimePt_utl_s(), org.matsim.pt.router.TransitRouterConfig.getMarginalUtilityOfWaitingPt_utl_s(), and org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.offVehicleWaitTime().

67  {
68  double cost;
69  if (((TransitRouterNetworkLink) link).getRoute() == null) {
70  // "route" here means "pt route". If no pt route is attached, it means that it is a transfer link.
71 
72  cost = defaultTransferCost(link, time, person, vehicle);
73 
74  } else {
75  double offVehWaitTime = offVehicleWaitTime(link, time);
76  double inVehTime = getLinkTravelTime(link,time, person, vehicle) - offVehWaitTime;
77  cost = - inVehTime * this.config.getMarginalUtilityOfTravelTimePt_utl_s()
78  -offVehWaitTime * this.config.getMarginalUtilityOfWaitingPt_utl_s()
79  -link.getLength() * this.config.getMarginalUtilityOfTravelDistancePt_utl_m();
80 
81  }
82  return cost;
83  }
final double defaultTransferCost(final Link link, final double time, final Person person, final Vehicle vehicle)
double getLinkTravelTime(final Link link, final double time, Person person, Vehicle vehicle)
Here is the call graph for this function:

◆ offVehicleWaitTime()

double org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.offVehicleWaitTime ( final Link  link,
final double  time 
)
protected

method to allow inclusion of offVehicleWaitTime without code replication. kai, oct'12

Parameters
link
time
Returns

Definition at line 92 of file TransitRouterNetworkTravelTimeAndDisutility.java.

References org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getVehArrivalTime().

Referenced by org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getLinkTravelDisutility().

92  {
93  double offVehWaitTime=0;
94  double nextVehArrivalTime = getVehArrivalTime(link, time);
95  if (time < nextVehArrivalTime){ // it means the agent waits outside the veh
96  offVehWaitTime = nextVehArrivalTime-time;
97  }
98  return offVehWaitTime;
99 
100  }
Here is the call graph for this function:

◆ defaultTransferCost()

final double org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.defaultTransferCost ( final Link  link,
final double  time,
final Person  person,
final Vehicle  vehicle 
)
protected

convenience method for derived classes in order to bring Manuel's version closer to this one here. kai, oct'12

Definition at line 106 of file TransitRouterNetworkTravelTimeAndDisutility.java.

References org.matsim.pt.router.TransitRouterConfig.getAdditionalTransferTime(), and org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getLinkTravelTime().

Referenced by org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getLinkTravelDisutility().

107  {
108  double cost;
109  double transfertime = getLinkTravelTime(link, time, person, vehicle);
110  double waittime = this.config.getAdditionalTransferTime();
111 
112  // say that the effective walk time is the transfer time minus some "buffer"
113  double walktime = transfertime - waittime;
114  // (this looks like walktime might become negative. But at least in the default version, the additional transfer time is always
115  // _added_ to the walk time (see getLinkTravelTime below) so at least in that case this cannot happen. kai, triggered by cd, may'16)
116  if ( walktime < 0. ) {
117  throw new RuntimeException( "negative walk time; should not happen; needs to be repaired" ) ;
118  }
119 
120  double walkDistance = link.getLength();
121 
122  // weigh this "buffer" not with the walk time disutility, but with the wait time disutility:
123  // (note that this is the same "additional disutl of wait" as in the scoring function. Its default is zero.
124  // only if you are "including the opportunity cost of time into the router", then the disutility of waiting will
125  // be the same as the marginal opprotunity cost of time). kai, nov'11
126  cost = - walktime * this.config.getMarginalUtilityOfTravelTimeWalk_utl_s()
128  - waittime * this.config.getMarginalUtilityOfWaitingPt_utl_s()
130  return cost;
131  }
double getLinkTravelTime(final Link link, final double time, Person person, Vehicle vehicle)
Here is the call graph for this function:

◆ getLinkTravelTime()

double org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getLinkTravelTime ( final Link  link,
final double  time,
Person  person,
Vehicle  vehicle 
)

Returns the travel time for the specified link at the specified time.

Parameters
linkThe link for which the travel time is calculated.
timeThe departure time (in seconds since 00:00) at the beginning of the link for which the travel time is calculated.
personTODO
vehicleTODO
Returns
The time (in seconds) needed to travel over the link link, departing at time time.

Implements org.matsim.core.router.util.TravelTime.

Definition at line 134 of file TransitRouterNetworkTravelTimeAndDisutility.java.

References org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.cachedTravelTime, org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink.fromNode, org.matsim.pt.router.TransitRouterConfig.getAdditionalTransferTime(), org.matsim.pt.transitSchedule.api.TransitRouteStop.getArrivalOffset(), org.matsim.pt.router.TransitRouterConfig.getBeelineWalkSpeed(), org.matsim.pt.transitSchedule.api.TransitRouteStop.getDepartureOffset(), org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink.getLength(), org.matsim.pt.router.PreparedTransitSchedule.getNextDepartureTime(), org.matsim.core.utils.misc.OptionalTime.or(), org.matsim.core.utils.misc.OptionalTime.seconds, org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkNode.stop, and org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink.toNode.

Referenced by org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.defaultTransferCost(), and org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getLinkTravelDisutility().

134  {
135  if ((link == this.previousLink) && (time == this.previousTime)) {
136  return this.cachedTravelTime;
137  }
138  this.previousLink = link;
139  this.previousTime = time;
140 
141  TransitRouterNetworkLink wrapped = (TransitRouterNetworkLink) link;
142  TransitRouteStop fromStop = wrapped.fromNode.stop;
143  TransitRouteStop toStop = wrapped.toNode.stop;
144  if (wrapped.route != null) {
145  // (agent stays on the same route, so use transit line travel time)
146 
147  // get the next departure time:
148  double bestDepartureTime = preparedTransitSchedule.getNextDepartureTime(wrapped.route, fromStop, time);
149 
150  // the travel time on the link is
151  // the time until the departure (``dpTime - now'')
152  // + the travel time on the link (there.arrivalTime - here.departureTime)
153  // But quite often, we only have the departure time at the next stop. Then we use that:
154  double arrivalOffset = toStop.getArrivalOffset().or(toStop::getDepartureOffset).seconds();
155  double time2 = (bestDepartureTime - time) + (arrivalOffset - fromStop.getDepartureOffset().seconds());
156  if (time2 < 0) {
157  // ( this can only happen, I think, when ``bestDepartureTime'' is after midnight but ``time'' was before )
158  time2 += MIDNIGHT;
159  }
160  this.cachedTravelTime = time2;
161  return time2;
162  }
163  // different transit routes, so it must be a line switch
164  double distance = wrapped.getLength();
165  double time2 = distance / this.config.getBeelineWalkSpeed() + this.config.getAdditionalTransferTime();
166  this.cachedTravelTime = time2;
167  return time2;
168  }
double getNextDepartureTime(final TransitRoute route, final TransitRouteStop stop, final double depTime)
Here is the call graph for this function:

◆ getVehArrivalTime()

double org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getVehArrivalTime ( final Link  link,
final double  now 
)

Definition at line 175 of file TransitRouterNetworkTravelTimeAndDisutility.java.

References org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink.getRoute().

Referenced by org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.offVehicleWaitTime().

175  {
176  if ((link == this.previousWaitLink) && (now == this.previousWaitTime)) {
177  return this.cachedVehArrivalTime;
178  }
179  this.previousWaitLink = link;
180  this.previousWaitTime = now;
181 
182  //first find out vehicle arrival time to fromStop according to transit schedule
183  TransitRouterNetworkLink wrapped = (TransitRouterNetworkLink) link;
184  if (wrapped.getRoute() == null) {
185  throw new RuntimeException("should not happen") ;
186  }
187  TransitRouteStop fromStop = wrapped.fromNode.stop;
188 
189  double nextDepartureTime = preparedTransitSchedule.getNextDepartureTime(wrapped.getRoute(), fromStop, now);
190 
191  double fromStopDepartureOffset = fromStop.getDepartureOffset().seconds();
192  double fromStopArrivalOffset = fromStop.getArrivalOffset().orElse(fromStopDepartureOffset);
193  double vehWaitAtStopTime = fromStopDepartureOffset - fromStopArrivalOffset; //time in which the veh stops at station
194  double vehArrivalTime = nextDepartureTime - vehWaitAtStopTime;
195  cachedVehArrivalTime = vehArrivalTime ;
196  return vehArrivalTime ;
197  }
double getNextDepartureTime(final TransitRoute route, final TransitRouteStop stop, final double depTime)
Here is the call graph for this function:

◆ getWalkTravelDisutility()

double org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getWalkTravelDisutility ( Person  person,
Coord  coord,
Coord  toCoord 
)

Implements org.matsim.pt.router.TransitTravelDisutility.

Definition at line 200 of file TransitRouterNetworkTravelTimeAndDisutility.java.

References org.matsim.core.utils.geometry.CoordUtils.calcEuclideanDistance(), org.matsim.pt.router.TransitRouterConfig.getBeelineDistanceFactor(), org.matsim.pt.router.TransitRouterConfig.getMarginalUtilityOfTravelDistanceWalk_utl_m(), org.matsim.pt.router.TransitRouterConfig.getMarginalUtilityOfTravelTimeWalk_utl_s(), and org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getWalkTravelTime().

200  {
201  // getMarginalUtilityOfTravelTimeWalk INCLUDES the opportunity cost of time. kai, dec'12
202  double timeCost = - getWalkTravelTime(person, coord, toCoord) * config.getMarginalUtilityOfTravelTimeWalk_utl_s() ;
203  // (sign: margUtl is negative; overall it should be positive because it is a cost.)
204 
205  double distanceCost = - CoordUtils.calcEuclideanDistance(coord,toCoord) *
207  // (sign: same as above)
208 
209  return timeCost + distanceCost ;
210  }
Here is the call graph for this function:

◆ getWalkTravelTime()

double org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getWalkTravelTime ( Person  person,
Coord  coord,
Coord  toCoord 
)

This is used for walking to and from the nearest transit stop from the start and end location, as well as for the "direct" walk from start to finish without using a pt line at all. It is not used for transfer links (these are handled by the transitTravelDisutility).

Implements org.matsim.pt.router.TransitTravelDisutility.

Definition at line 213 of file TransitRouterNetworkTravelTimeAndDisutility.java.

References org.matsim.core.utils.geometry.CoordUtils.calcEuclideanDistance(), and org.matsim.pt.router.TransitRouterConfig.getBeelineWalkSpeed().

Referenced by org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.getWalkTravelDisutility().

213  {
214  double distance = CoordUtils.calcEuclideanDistance(coord, toCoord);
215  double initialTime = distance / config.getBeelineWalkSpeed();
216  return initialTime;
217  }
Here is the call graph for this function:

Member Data Documentation

◆ config

final TransitRouterConfig org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.config
protected

◆ previousLink

Link org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.previousLink = null
private

◆ previousTime

double org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.previousTime = Double.NaN
private

◆ cachedTravelTime

double org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.cachedTravelTime = Double.NaN
private

◆ preparedTransitSchedule

final PreparedTransitSchedule org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility.preparedTransitSchedule
private

The documentation for this class was generated from the following file: