RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009,
5 + rand.nextInt(4), 1 + rand.nextInt(20), 4 + rand.nextInt(10),
rand.nextInt(60), 0);
ShortestPathTree spt;
GraphPath path;
options.setRoutingContext(graph, origin, destination);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(destination, false);
if (path == null)
continue;
System.out.println("Testing path between " + origin.getLabel() + " and "
+ destination.getLabel() + " at " + new Date(options.dateTime * 1000));
long arrivalTime1 = 0L;
long elapsedTime1 = 0L;
int numBoardings1 = 0;
Vertex arrivalVertex1 = null;
if (verbose)
System.out.println("PATH 1 ---------------------");
for (State s : path.states) {
if (verbose)
System.out.println(s + " [" + s.getVertex().getClass().getName() + "]");
arrivalTime1 = s.getTimeSeconds();
arrivalVertex1 = s.getVertex();
elapsedTime1 = s.getElapsedTimeSeconds();
numBoardings1 = s.getNumBoardings();
}
/* Get a random transit hop from the computed path */
Stop end = null;
PatternStopVertex nextV = null;
TripTimes tripTimes = null;
int stopIndex = 0;
long newStart = 0L;
int nhop = 0;
for (State s : path.states) {
if (s.getVertex() instanceof PatternArriveVertex
&& s.getBackEdge() instanceof PatternHop)
nhop++;
}
int hop = rand.nextInt(nhop);
nhop = 0;
float k = rand.nextFloat();
for (State s : path.states) {
Vertex v = s.getVertex();
if (v instanceof PatternArriveVertex && s.getBackEdge() instanceof PatternHop) {
if (hop == nhop) {
PatternArriveVertex pav = (PatternArriveVertex) v;
end = pav.getStop();
nextV = pav;
PatternHop phe = (PatternHop) s.getBackEdge();
stopIndex = phe.getStopIndex();
tripTimes = s.getTripTimes();
int hopDuration = tripTimes.getRunningTime(stopIndex);
/*
* New start time at k% of hop. Note: do not try to make: round(time +
* k.hop) as it will be off few seconds due to floating-point rounding
* errors.
*/
newStart = s.getBackState().getTimeSeconds() + Math.round(hopDuration * k);
break;
}
nhop++;
}
}
System.out.println("Boarded depart: trip=" + tripTimes.trip + ", nextStop="
+ nextV.getStop() + " stopIndex=" + stopIndex + " startTime="
+ new Date(newStart * 1000L));
/* And use it for onboard departure */
double lat = end.getLat();
double lon = end.getLon(); // Mock location, not really important here.
OnboardDepartVertex onboardOrigin = new OnboardDepartVertex("OnBoard_Origin", lat, lon);
@SuppressWarnings("unused")
OnBoardDepartPatternHop currentHop = new OnBoardDepartPatternHop(onboardOrigin, nextV,
tripTimes, options.rctx.serviceDays.get(1), stopIndex, k);
options.dateTime = newStart;
options.setRoutingContext(graph, onboardOrigin, destination);
spt = aStar.getShortestPathTree(options);
/* Re-compute a new path starting boarded */
GraphPath path2 = spt.getPath(destination, false);
assertNotNull(path2);
if (verbose)
System.out.println("PATH 2 ---------------------");
long arrivalTime2 = 0L;
long elapsedTime2 = 0L;