MATSIM
LeastCostRaptorRouteSelector.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 package ch.sbb.matsim.routing.pt.raptor;
21 
22 import java.util.List;
23 
36 
37  @Override
38  public RaptorRoute selectOne(List<RaptorRoute> routes, double desiredDepartureTime) {
39  if (routes == null || routes.isEmpty()) {
40  return null;
41  }
42  RaptorRoute bestRoute = null;
43  double bestDiff = 0;
44  for (RaptorRoute route : routes) {
45  if (bestRoute == null || route.getTotalCosts() < bestRoute.getTotalCosts()) {
46  bestRoute = route;
47  bestDiff = route.getDepartureTime() - desiredDepartureTime;
48  if (bestDiff < 0) {
49  bestDiff = -bestDiff * 2;
50  }
51  } else if (route.getTotalCosts() == bestRoute.getTotalCosts()) {
52  double diff = route.getDepartureTime() - desiredDepartureTime;
53  if (diff < 0) {
54  diff = -diff * 2; // make it positive and double
55  }
56  if (diff < bestDiff) {
57  bestRoute = route;
58  bestDiff = diff;
59  }
60  }
61  }
62  return bestRoute;
63  }
64 }
RaptorRoute selectOne(List< RaptorRoute > routes, double desiredDepartureTime)