Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tc issue 262 #271

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
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: 6 additions & 1 deletion transitclock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@
<dependency>
<groupId>com.esri.geometry</groupId>
<artifactId>esri-geometry-api</artifactId>
<version>1.1</version>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.bmw-carit</groupId>
<artifactId>barefoot</artifactId>
<version>0.1.5</version>
</dependency>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public static int getDaysPopulateHistoricalCache() {
private static IntegerConfigValue daysPopulateHistoricalCache =
new IntegerConfigValue("transitclock.cache.core.daysPopulateHistoricalCache", 0,
"How many days data to read in to populate historical cache on start up.");

public static BooleanConfigValue useDefaultSpatialMatcher = new BooleanConfigValue("transitclock.cache.core.useDefaultSpatialMatcher", false, "Set to true to use default matcher");

public static BooleanConfigValue useBarefootSpatialMatcher = new BooleanConfigValue("transitclock.cache.core.useBarefootSpatialMatcher", true, "Set to true to use default matcher");
/**
* When in playback mode or some other situations don't want to store
* generated data such as arrivals/departures, events, and such to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ private void estimateArrivalsDeparturesWithoutPreviousMatch(

// Determine departure time for first stop of trip
SpatialMatch beginningOfTrip = new SpatialMatch(0, block,
tripIndex, 0, 0, 0.0, 0.0);
tripIndex, 0, 0, 0.0, 0.0, SpatialMatch.MatchType.TRANSITCLOCK);
long travelTimeFromFirstStopToMatch = TravelTimes.getInstance()
.expectedTravelTimeBetweenMatches(vehicleId, avlReportTime,
beginningOfTrip, newMatch);
Expand Down
17 changes: 12 additions & 5 deletions transitclock/src/main/java/org/transitclock/core/AvlProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,20 @@ public void matchNewFixForPredictableVehicle(VehicleState vehicleState) {
logger.debug("STARTOFMATCHING");
logger.debug("Matching already predictable vehicle using new AVL "
+ "report. The old spatial match is {}", vehicleState);

List<SpatialMatch> spatialMatches = new ArrayList<>();

// Find possible spatial matches
List<SpatialMatch> spatialMatches = SpatialMatcher
.getSpatialMatches(vehicleState);
if(CoreConfig.useDefaultSpatialMatcher.getValue())
spatialMatches.addAll(SpatialMatcher
.getSpatialMatches(vehicleState));

if(CoreConfig.useBarefootSpatialMatcher.getValue())
spatialMatches.add(vehicleState.getMapMatchedSpatialMatch());

logger.debug("For vehicleId={} found the following {} spatial "
+ "matches: {}", vehicleState.getVehicleId(),
spatialMatches.size(), spatialMatches);
+ "matches: {} ", vehicleState.getVehicleId(),
spatialMatches.size(), spatialMatches);

// Find best temporal match of the spatial matches
TemporalMatch bestTemporalMatch = TemporalMatcher.getInstance()
Expand Down Expand Up @@ -824,7 +831,7 @@ private boolean matchVehicleToBlockAssignment(Block block,
block, block.getTripIndex(trip), 0, // stopPathIndex
0, // segmentIndex
distanceToSegment,
0.0); // distanceAlongSegment
0.0,SpatialMatch.MatchType.TRANSITCLOCK); // distanceAlongSegment

bestMatch = new TemporalMatch(beginningOfTrip,
new TemporalDifference(0));
Expand Down
8 changes: 8 additions & 0 deletions transitclock/src/main/java/org/transitclock/core/Indices.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.transitclock.core;

import java.io.Serializable;
import java.util.Objects;

import org.transitclock.applications.Core;
import org.transitclock.db.structs.ArrivalDeparture;
Expand Down Expand Up @@ -634,4 +635,11 @@ public boolean controlPoint() {
return false;
}

@Override
public int hashCode() {
return Objects.hash(block, segmentIndex, stopPathIndex, tripIndex);
}



}
12 changes: 12 additions & 0 deletions transitclock/src/main/java/org/transitclock/core/MapMatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.transitclock.core;

import java.util.Date;

import org.transitclock.db.structs.AvlReport;
import org.transitclock.db.structs.Block;
import org.transitclock.db.structs.Location;

public interface MapMatcher {
void setMatcher(Block block, Date assignmentTime);
SpatialMatch getSpatialMatch(AvlReport avlReport);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This file is part of Transitime.org
*
* Transitime.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License (GPL) as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Transitime.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transitime.org . If not, see <http://www.gnu.org/licenses/>.
*/

package org.transitclock.core;

import org.transitclock.config.StringConfigValue;
import org.transitclock.utils.ClassInstantiator;

/**
* For instantiating a map matcher object that matches avl locations to trip shapes
*
* @author Sean Óg Crudden
*
*/
public class MapMatcherFactory {

// The name of the class to instantiate
private static StringConfigValue className =
new StringConfigValue("transitclock.core.mapMatcherClass",
"org.transitclock.core.barefoot.BareFootMapMatcher",
"Specifies the name of the class used for map matching.");

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

public static MapMatcher getInstance() {


try {
return ClassInstantiator.instantiate(className.getValue(),
MapMatcher.class);
} catch (Exception e) {

e.printStackTrace();
}
return null;
}
}
22 changes: 18 additions & 4 deletions transitclock/src/main/java/org/transitclock/core/SpatialMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public class SpatialMatch {
protected final double distanceAlongSegment;
protected final VehicleAtStopInfo atStop;
protected final Location predictedLocation;
protected final MatchType type;

public enum MatchType {
TRANSITCLOCK,
BAREFOOT
} ;

private static final Logger logger =
LoggerFactory.getLogger(SpatialMatch.class);
Expand All @@ -58,7 +64,7 @@ public class SpatialMatch {

public SpatialMatch(long avlTime, Block block,
int tripIndex, int stopPathIndex, int segmentIndex,
double distanceToSegment, double distanceAlongSegment) {
double distanceToSegment, double distanceAlongSegment, MatchType type) {
this.avlTime = avlTime;
this.block = block;
this.tripIndex = tripIndex;
Expand All @@ -69,7 +75,12 @@ public SpatialMatch(long avlTime, Block block,

// Determine whether at stop
this.atStop = atStop();
this.predictedLocation = computeLocation();
this.predictedLocation = computeLocation();
this.type=type;
}

public MatchType getType() {
return type;
}

/**
Expand Down Expand Up @@ -145,6 +156,7 @@ public SpatialMatch(SpatialMatch toCopy, Trip newTrip) {
}
// recomupte predictedLocation for above reasons as well
this.predictedLocation = toCopy.computeLocation(toCopy.getIndices(), toCopy.distanceAlongSegment);
this.type=toCopy.type;
}

/**
Expand All @@ -167,6 +179,7 @@ public SpatialMatch(SpatialMatch toCopy, Indices newIndices,
this.distanceAlongSegment = distanceAlongSegment;
this.atStop = toCopy.atStop;
this.predictedLocation = computeLocation(newIndices, distanceAlongSegment);
this.type = toCopy.type;
}

/**
Expand All @@ -184,6 +197,7 @@ protected SpatialMatch(SpatialMatch toCopy) {
this.distanceAlongSegment = toCopy.distanceAlongSegment;
this.atStop = toCopy.atStop;
this.predictedLocation = toCopy.predictedLocation;
this.type = toCopy.type;
}

/**
Expand Down Expand Up @@ -452,7 +466,7 @@ public SpatialMatch getMatchAtJustBeforeNextStop() {
m.getStopPathIndex(),
segmentIndex,
Double.NaN, // distanceToSegment not set to a valid value
segmentLength);
segmentLength, this.type);
}

/**
Expand Down Expand Up @@ -511,7 +525,7 @@ public SpatialMatch getMatchAtPreviousStop() {
indices.getStopPathIndex(),
indices.getSegmentIndex(),
Double.NaN, // distanceToSegment not set to a valid value
segmentVectorLength);
segmentVectorLength, this.type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class SpatialMatcher {
private SpatialMatch smallestDistanceSpatialMatch = null;

// For keeping track of what kind of spatial matching being done
public enum MatchingType {STANDARD_MATCHING, AUTO_ASSIGNING_MATCHING};
public enum MatchingType {STANDARD_MATCHING, AUTO_ASSIGNING_MATCHING, BAREFOOT_MATCHING};

private static final Logger logger =
LoggerFactory.getLogger(SpatialMatcher.class);
Expand Down Expand Up @@ -618,7 +618,8 @@ private void processPossiblePotentialMatch(AvlReport avlReport,
potentialMatchIndices.getStopPathIndex(),
potentialMatchIndices.getSegmentIndex(),
distanceToSegment,
distanceAlongSegment);
distanceAlongSegment,
SpatialMatch.MatchType.TRANSITCLOCK);
logger.debug("For vehicleId={} examining match to see if it should " +
"be included in list of spatial matches. {}",
avlReport.getVehicleId(), spatialMatch);
Expand Down Expand Up @@ -732,6 +733,7 @@ && withinAllowableDistanceOfLayover(avlReport.getVehicleId(),
*/
public static List<SpatialMatch>
getSpatialMatches(VehicleState vehicleState) {

// Some convenience variables
TemporalMatch previousMatch = vehicleState.getMatch();
SpatialMatcher spatialMatcher = new SpatialMatcher();
Expand Down Expand Up @@ -855,7 +857,8 @@ && withinAllowableDistanceOfLayover(avlReport.getVehicleId(),
indexOfLastStopPath,
indexOfLastSegment,
Double.NaN, // distanceToSegment set to a non-valid value
segmentLength);
segmentLength,
SpatialMatch.MatchType.TRANSITCLOCK);

// Add that match to list of possible SpatialMatches
logger.debug("Because vehicleId={} within specified distance " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ private static TemporalDifference determineHowFarOffScheduledTime(
0, // stopPathIndex
0, // segmentIndex
0.0, // distanceToSegment
0.0); // distanceAlongSegment
0.0,
SpatialMatch.MatchType.TRANSITCLOCK); // distanceAlongSegment
int tripStartTimeSecs = spatialMatch.getTrip().getStartTime();
int travelTimeForCurrentTrip =
TravelTimes.getInstance().expectedTravelTimeBetweenMatches(vehicleId,
Expand Down
28 changes: 22 additions & 6 deletions transitclock/src/main/java/org/transitclock/core/VehicleState.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.transitclock.configData.CoreConfig;
Expand Down Expand Up @@ -66,6 +65,9 @@ public class VehicleState {
// First is most recent
private LinkedList<AvlReport> avlReportHistory =
new LinkedList<AvlReport>();



private List<IpcPrediction> predictions;
private TemporalDifference realTimeSchedAdh;

Expand Down Expand Up @@ -100,7 +102,8 @@ public class VehicleState {
private HoldingTime holdingTime=null;
//Used for schedPred AVL. Identify if trip is canceled.
private boolean isCanceled;


MapMatcher mapMatcher = null;

public Headway getHeadway() {
return headway;
Expand All @@ -109,8 +112,6 @@ public void setHeadway(Headway headway) {
this.headway = headway;
}



public HoldingTime getHoldingTime() {
return holdingTime;
}
Expand All @@ -131,8 +132,9 @@ public void incrementTripCounter() {

public VehicleState(String vehicleId) {
this.vehicleId = vehicleId;

}

/**
* Sets the block assignment for vehicle. Also, this is how it is specified
* whether a vehicle is predictable or not.
Expand Down Expand Up @@ -163,9 +165,23 @@ public void setBlock(Block newBlock, BlockAssignmentMethod assignmentMethod,
this.assignmentMethod = assignmentMethod;
this.assignmentId = assignmentId;
this.predictable = predictable;
this.assignmentTime = getAvlReport().getDate();
this.assignmentTime = getAvlReport().getDate();

this.mapMatcher=(MapMatcher) MapMatcherFactory.getInstance();
mapMatcher.setMatcher(block, assignmentTime);

}

public SpatialMatch getMapMatchedSpatialMatch()
{
if(mapMatcher!=null)
return mapMatcher.getSpatialMatch(getAvlReport());
else
return null;
}



/**
* Sets the block for this VehicleState to null. Also sets assignmentId
* to null and predictable to false.
Expand Down
Loading