Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions transitclock/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>TheTransitClock</groupId>
Expand Down Expand Up @@ -139,9 +140,9 @@

<!-- For GTFS-realtime feed -->
<dependency>
<groupId>com.google.transit</groupId>
<groupId>io.mobilitydata.transit</groupId>
<artifactId>gtfs-realtime-bindings</artifactId>
<version>0.0.4</version>
<version>0.0.6-SNAPSHOT</version>
</dependency>

<!-- For more easily handling command line options -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.transitclock.ipc.servers.CacheQueryServer;
import org.transitclock.ipc.servers.CommandsServer;
import org.transitclock.ipc.servers.ConfigServer;
import org.transitclock.ipc.servers.DiversionsServer;
import org.transitclock.ipc.servers.HoldingTimeServer;
import org.transitclock.ipc.servers.PredictionAnalysisServer;
import org.transitclock.ipc.servers.PredictionsServer;
Expand Down Expand Up @@ -409,6 +410,7 @@ public static void startRmiServers(String agencyId) {
CacheQueryServer.start(agencyId);
PredictionAnalysisServer.start(agencyId);
HoldingTimeServer.start(agencyId);
DiversionsServer.start(agencyId);
}

static private void populateCaches() throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
import org.transitclock.db.structs.Location;
import org.transitclock.ipc.clients.CommandsInterfaceFactory;
import org.transitclock.ipc.clients.ConfigInterfaceFactory;
import org.transitclock.ipc.clients.DiversionsInterfaceFactory;
import org.transitclock.ipc.clients.PredictionsInterfaceFactory;
import org.transitclock.ipc.clients.VehiclesInterfaceFactory;
import org.transitclock.ipc.data.IpcActiveBlock;
import org.transitclock.ipc.data.IpcBlock;
import org.transitclock.ipc.data.IpcDirectionsForRoute;
import org.transitclock.ipc.data.IpcDiversions;
import org.transitclock.ipc.data.IpcPredictionsForRouteStopDest;
import org.transitclock.ipc.data.IpcRoute;
import org.transitclock.ipc.data.IpcRouteSummary;
Expand All @@ -48,6 +50,7 @@
import org.transitclock.ipc.data.IpcVehicleComplete;
import org.transitclock.ipc.interfaces.CommandsInterface;
import org.transitclock.ipc.interfaces.ConfigInterface;
import org.transitclock.ipc.interfaces.DiversionsInterface;
import org.transitclock.ipc.interfaces.PredictionsInterface;
import org.transitclock.ipc.interfaces.VehiclesInterface;
import org.transitclock.ipc.interfaces.PredictionsInterface.RouteStop;
Expand Down Expand Up @@ -79,7 +82,7 @@ public class RmiQuery {

private static enum Command {NOT_SPECIFIED, GET_PREDICTIONS, GET_VEHICLES,
GET_ROUTE_CONFIG, GET_CONFIG,
GET_ACTIVE_BLOCKS, RESET_VEHICLE};
GET_ACTIVE_BLOCKS, RESET_VEHICLE, GET_DETOURS};

/********************** Member Functions **************************/

Expand Down Expand Up @@ -197,6 +200,8 @@ else if ("activeBlocks".equals(commandStr))
command = Command.GET_ACTIVE_BLOCKS;
else if ("resetVehicle".equals(commandStr))
command = Command.RESET_VEHICLE;
else if("detours".equals(commandStr))
command = Command.GET_DETOURS;
else {
System.out.println("Command \"" + commandStr + "\" is not valid.\n");
displayCommandLineOptionsAndExit(options);
Expand Down Expand Up @@ -461,13 +466,26 @@ public static void main(String[] args) {
getActiveBlocks();
} else if(command == Command.RESET_VEHICLE) {
resetVehicles();
}
} else if(command == Command.GET_DETOURS)
getDetours();

} catch (Exception e) {
// Output stack trace as error message
e.printStackTrace();
}
}

private static void getDetours() throws Exception {
// TODO Auto-generated method stub
DiversionsInterface detourInterface=DiversionsInterfaceFactory.get(agencyId);

IpcDiversions result = detourInterface.getDiversionsForTrip(tripId);

if(result!=null)
System.out.println(result.toString());

}

private static void resetVehicles() throws Exception {
CommandsInterface commandsInterface =
CommandsInterfaceFactory.get(agencyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ private static int getMaxStopsBetweenMatches() {
* @param avlReport
* @return
*/
private boolean tooManyStopsTraversed(SpatialMatch oldMatch,
SpatialMatch newMatch, AvlReport previousAvlReport,
private boolean tooManyStopsTraversed(RouteMatch oldMatch,
RouteMatch newMatch, AvlReport previousAvlReport,
AvlReport avlReport) {
// If there is no old match then we are fine
if (oldMatch == null)
Expand Down Expand Up @@ -224,8 +224,8 @@ private boolean tooManyStopsTraversed(SpatialMatch oldMatch,
* The new match for the vehicle.
* @return
*/
private boolean shouldProcessArrivedOrDepartedStops(SpatialMatch oldMatch,
SpatialMatch newMatch) {
private boolean shouldProcessArrivedOrDepartedStops(RouteMatch oldMatch,
RouteMatch newMatch) {
// If there is no old match at all then we likely finally got a
// AVL report after vehicle had left terminal. Still want to
// determine arrival/departure times for the first stops of the
Expand All @@ -239,7 +239,7 @@ private boolean shouldProcessArrivedOrDepartedStops(SpatialMatch oldMatch,
// truly know what is going on it is best to not generate
// arrivals/departures for between the matches.
int stopsTraversed =
SpatialMatch.numberStopsBetweenMatches(oldMatch, newMatch);
RouteMatch.numberStopsBetweenMatches(oldMatch, newMatch);
if (stopsTraversed > getMaxStopsBetweenMatches()) {
logger.error("Attempting to traverse {} stops between oldMatch " +
"and newMatch, which is more thanThere are more than " +
Expand Down Expand Up @@ -611,7 +611,7 @@ private void estimateArrivalsDeparturesWithoutPreviousMatch(
}

// Couple of convenience variables
SpatialMatch newMatch = vehicleState.getMatch();
RouteMatch newMatch = vehicleState.getMatch();
String vehicleId = vehicleState.getVehicleId();

if (newMatch.getTripIndex() == 0 &&
Expand All @@ -624,7 +624,7 @@ private void estimateArrivalsDeparturesWithoutPreviousMatch(
int stopPathIndex = 0;

// Determine departure time for first stop of trip
SpatialMatch beginningOfTrip = new SpatialMatch(0, block,
RouteMatch beginningOfTrip = new RouteMatch(0, block,
tripIndex, 0, 0, 0.0, 0.0);
long travelTimeFromFirstStopToMatch = TravelTimes.getInstance()
.expectedTravelTimeBetweenMatches(vehicleId, avlReportTime,
Expand Down Expand Up @@ -799,7 +799,7 @@ private long handleVehicleDepartingStop(VehicleState vehicleState) {

// If vehicle wasn't departing a stop then simply return the
// previous AVL time as the beginTime.
SpatialMatch oldMatch = vehicleState.getPreviousMatch();
RouteMatch oldMatch = vehicleState.getPreviousMatch();
VehicleAtStopInfo oldVehicleAtStopInfo = oldMatch.getAtStop();
AvlReport previousAvlReport =
vehicleState.getPreviousAvlReportFromSuccessfulMatch();
Expand All @@ -813,13 +813,13 @@ private long handleVehicleDepartingStop(VehicleState vehicleState) {

// Use match right at the departed stop. This way we are including the
// time it takes to get from the actual stop to the new match.
SpatialMatch matchJustAfterStop =
RouteMatch matchJustAfterStop =
oldMatch.getMatchAdjustedToBeginningOfPath();

// Determine departure info for the old stop by using the current
// AVL report and subtracting the expected travel time to get from
// there to the new match.
SpatialMatch newMatch = vehicleState.getMatch();
RouteMatch newMatch = vehicleState.getMatch();
int travelTimeToNewMatchMsec = TravelTimes.getInstance()
.expectedTravelTimeBetweenMatches(vehicleId,
previousAvlReport.getDate(), matchJustAfterStop,
Expand All @@ -846,7 +846,7 @@ private long handleVehicleDepartingStop(VehicleState vehicleState) {
} else {
// The oldMatch is before the stop so add the travel time from the
// oldMatch to the stop to the previous AVL report time.
SpatialMatch matchJustBeforeStop =
RouteMatch matchJustBeforeStop =
oldMatch.getMatchAdjustedToEndOfPath();
int travelTimeFromOldMatchToStopMsec = TravelTimes.getInstance()
.expectedTravelTimeBetweenMatches(vehicleId,
Expand Down Expand Up @@ -935,7 +935,7 @@ private long handleVehicleArrivingAtStop(VehicleState vehicleState,

// If vehicle hasn't arrived at a stop then simply return the
// AVL time as the endTime.
SpatialMatch newMatch = vehicleState.getMatch();
RouteMatch newMatch = vehicleState.getMatch();
VehicleAtStopInfo newVehicleAtStopInfo = newMatch.getAtStop();
AvlReport avlReport = vehicleState.getAvlReport();
if (newVehicleAtStopInfo == null)
Expand All @@ -949,14 +949,14 @@ private long handleVehicleArrivingAtStop(VehicleState vehicleState,
// Use match right at the stop. This way we are including the
// time it takes to get from the new match to the actual
// stop and not just to some distance before the stop.
SpatialMatch matchJustBeforeStop =
RouteMatch matchJustBeforeStop =
newMatch.getMatchAdjustedToEndOfPath();

// Determine arrival info for the new stop based on the
// old AVL report. This will give us the proper time if
// the vehicle already arrived before the current AVL
// report
SpatialMatch oldMatch = vehicleState.getPreviousMatch();
RouteMatch oldMatch = vehicleState.getPreviousMatch();
int travelTimeFromOldMatchMsec = TravelTimes.getInstance()
.expectedTravelTimeBetweenMatches(vehicleId,
avlReport.getDate(), oldMatch, matchJustBeforeStop);
Expand Down Expand Up @@ -985,7 +985,7 @@ private long handleVehicleArrivingAtStop(VehicleState vehicleState,
// The new match is after the stop so subtract the travel time
// from the stop to the match from the AVL time to get the
// arrivalTimeBasedOnNewMatch.
SpatialMatch matchJustAfterStop =
RouteMatch matchJustAfterStop =
newMatch.getMatchAdjustedToBeginningOfPath();

int travelTimeFromStoptoNewMatchMsec = TravelTimes.getInstance()
Expand Down Expand Up @@ -1077,8 +1077,8 @@ private long handleVehicleArrivingAtStop(VehicleState vehicleState,
* @param newMatch
* @return Number of zero travel or stop times
*/
private int numberOfZeroTravelOrStopTimes(SpatialMatch oldMatch,
SpatialMatch newMatch) {
private int numberOfZeroTravelOrStopTimes(RouteMatch oldMatch,
RouteMatch newMatch) {
int counter = 0;
Indices indices = oldMatch.getIndices();
Indices newIndices = newMatch.getIndices();
Expand Down Expand Up @@ -1123,8 +1123,8 @@ private void handleIntermediateStops(VehicleState vehicleState,

// Convenience variables
String vehicleId = vehicleState.getVehicleId();
SpatialMatch oldMatch = vehicleState.getPreviousMatch();
SpatialMatch newMatch = vehicleState.getMatch();
RouteMatch oldMatch = vehicleState.getPreviousMatch();
RouteMatch newMatch = vehicleState.getMatch();
Date previousAvlDate = vehicleState
.getPreviousAvlReportFromSuccessfulMatch().getDate();
Date avlDate = vehicleState.getAvlReport().getDate();
Expand Down Expand Up @@ -1173,7 +1173,7 @@ private void handleIntermediateStops(VehicleState vehicleState,
newVehicleAtStopInfo.clone() : newMatch.getIndices();

// Determine time to first stop
SpatialMatch matchAtNextStop = oldMatch.getMatchAtJustBeforeNextStop();
RouteMatch matchAtNextStop = oldMatch.getMatchAtJustBeforeNextStop();
long travelTimeToFirstStop = TravelTimes.getInstance()
.expectedTravelTimeBetweenMatches(vehicleId,
avlDate, oldMatch, matchAtNextStop);
Expand Down Expand Up @@ -1250,7 +1250,7 @@ public void generate(VehicleState vehicleState) {
// Return empty arrivalDepartures list
return;
}
SpatialMatch newMatch = vehicleState.getMatch();
RouteMatch newMatch = vehicleState.getMatch();
if (newMatch == null) {
logger.error("Vehicle was not matched when trying to process " +
"arrival/departure times. {}", vehicleState);
Expand All @@ -1264,7 +1264,7 @@ public void generate(VehicleState vehicleState) {
// stop of the block due to not getting assignment right away or some
// kind of AVL issue. For this situation still want to estimate the
// arrival/departure times for the previous stops.
SpatialMatch oldMatch = vehicleState.getPreviousMatch();
RouteMatch oldMatch = vehicleState.getPreviousMatch();
if (oldMatch == null) {
logger.debug("For vehicleId={} there was no previous match " +
"so seeing if can generate arrivals/departures for " +
Expand Down
27 changes: 17 additions & 10 deletions transitclock/src/main/java/org/transitclock/core/AvlProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -441,17 +441,24 @@ public void matchNewFixForPredictableVehicle(VehicleState vehicleState) {
logger.debug("Matching already predictable vehicle using new AVL "
+ "report. The old spatial match is {}", vehicleState);

// Find possible spatial matches
List<SpatialMatch> spatialMatches = SpatialMatcher
// Find possible route matches
List<RouteMatch> spatialMatches = SpatialMatcher
.getSpatialMatches(vehicleState);
logger.debug("For vehicleId={} found the following {} spatial "
+ "matches: {}", vehicleState.getVehicleId(),
spatialMatches.size(), spatialMatches);

// Find possible diversion matches.
List<DiversionMatch> divesionMatches = DiversionMatcher.getDiversionMatches(vehicleState);
logger.debug("For vehicleId={} found the following {} diversion "
+ "matches: {}", vehicleState.getVehicleId(),
divesionMatches.size(), divesionMatches);


// Find best temporal match of the spatial matches
TemporalMatch bestTemporalMatch = TemporalMatcher.getInstance()
.getBestTemporalMatch(vehicleState, spatialMatches);

.getBestTemporalMatch(vehicleState, spatialMatches, divesionMatches);
// Log this as info since matching is a significant milestone
logger.info("For vehicleId={} the best match is {}",
vehicleState.getVehicleId(), bestTemporalMatch);
Expand Down Expand Up @@ -521,7 +528,7 @@ public void matchNewFixForPredictableVehicle(VehicleState vehicleState) {
* @param match
* @return True if the match can be used when matching vehicle to a route
*/
private static boolean matchOkForRouteMatching(SpatialMatch match) {
private static boolean matchOkForRouteMatching(RouteMatch match) {
return match.awayFromTerminals(getTerminalDistanceForRouteMatching());
}

Expand Down Expand Up @@ -684,7 +691,7 @@ private boolean matchVehicleToRouteAssignment(String routeId,
}
}

List<SpatialMatch> allPotentialSpatialMatchesForRoute = new ArrayList<SpatialMatch>();
List<RouteMatch> allPotentialSpatialMatchesForRoute = new ArrayList<RouteMatch>();

// Go through each block and determine best spatial matches
for (Block block : allBlocksForRoute) {
Expand Down Expand Up @@ -718,12 +725,12 @@ private boolean matchVehicleToRouteAssignment(String routeId,
block.getId(), potentialTrips);

// Get the potential spatial matches
List<SpatialMatch> spatialMatchesForBlock = SpatialMatcher
List<RouteMatch> spatialMatchesForBlock = SpatialMatcher
.getSpatialMatches(vehicleState.getAvlReport(),
block, potentialTrips, MatchingType.AUTO_ASSIGNING_MATCHING);

// Add appropriate spatial matches to list
for (SpatialMatch spatialMatch : spatialMatchesForBlock) {
for (RouteMatch spatialMatch : spatialMatchesForBlock) {
if (!SpatialMatcher.problemMatchDueToLackOfHeadingInfo(
spatialMatch, vehicleState, MatchingType.AUTO_ASSIGNING_MATCHING)
&& matchOkForRouteMatching(spatialMatch))
Expand Down Expand Up @@ -779,7 +786,7 @@ private boolean matchVehicleToBlockAssignment(Block block,
// specifying the block assignment so it should find a match even
// if it pretty far off.
List<Trip> potentialTrips = block.getTripsCurrentlyActive(avlReport);
List<SpatialMatch> spatialMatches =
List<RouteMatch> spatialMatches =
SpatialMatcher.getSpatialMatches(vehicleState.getAvlReport(),
block, potentialTrips, MatchingType.STANDARD_MATCHING);
logger.debug("For vehicleId={} and blockId={} spatial matches={}",
Expand Down Expand Up @@ -819,7 +826,7 @@ private boolean matchVehicleToBlockAssignment(Block block,
double distanceToSegment =
firstStopInTripLoc.distance(avlReport.getLocation());

SpatialMatch beginningOfTrip = new SpatialMatch(
RouteMatch beginningOfTrip = new RouteMatch(
avlReport.getTime(),
block, block.getTripIndex(trip), 0, // stopPathIndex
0, // segmentIndex
Expand Down
Loading