Skip to content

Commit

Permalink
Merge pull request #265 from HSLdevcom/DT-2775
Browse files Browse the repository at this point in the history
Fix OTP's default handling of transfers in fare computations
  • Loading branch information
pailakka authored Oct 31, 2018
2 parents 33cd3e4 + b865820 commit 4289beb
Showing 3 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -12,4 +12,4 @@ ADD src ${OTP_ROOT}/src
add .git ${OTP_ROOT}/.git

# Build OTP
RUN mvn -q package
RUN mvn package -DskipTests
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ the License, or (at your option) any later version.
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.LinkedList;
import java.util.Set;
import java.util.Map;

@@ -24,6 +25,9 @@ the License, or (at your option) any later version.
import org.opentripplanner.routing.core.Fare;
import org.opentripplanner.routing.core.Fare.FareType;
import org.opentripplanner.routing.core.FareRuleSet;
import org.opentripplanner.routing.core.State;
import org.opentripplanner.routing.edgetype.HopEdge;
import org.opentripplanner.routing.graph.Edge;
import org.opentripplanner.routing.spt.GraphPath;
import org.opentripplanner.routing.impl.DefaultFareServiceImpl;
import org.slf4j.Logger;
@@ -37,6 +41,41 @@ public class HSLFareServiceImpl extends DefaultFareServiceImpl {
private static final long serialVersionUID = 20131259L;
private static final Logger LOG = LoggerFactory.getLogger(HSLFareServiceImpl.class);

@Override
protected List<Ride> createRides(GraphPath path) {
// HSL version: ride ends (and hence ticket validity is considered)
// whenever consecutive sequence of hop edges breaks
List<Ride> rides = new LinkedList<Ride>();
Ride ride = null;
boolean newRide = true;
for (State state : path.states) {
Edge edge = state.getBackEdge();
if (!(edge instanceof HopEdge)) {
newRide = true;
continue;
}
HopEdge hEdge = (HopEdge) edge;
if (newRide == true) {
ride = new Ride();
rides.add(ride);
ride.startZone = hEdge.getBeginStop().getZoneId();
ride.zones.add(ride.startZone);
ride.agency = state.getBackTrip().getRoute().getAgency().getId();
ride.route = state.getRoute();
ride.startTime = state.getBackState().getTimeSeconds();
ride.firstStop = hEdge.getBeginStop();
ride.trip = state.getTripId();
newRide = false; // ride until hopping ends
}
ride.lastStop = hEdge.getEndStop();
ride.endZone = ride.lastStop.getZoneId();
ride.zones.add(ride.endZone);
ride.endTime = state.getTimeSeconds();
ride.classifier = state.getBackMode();
}
return rides;
}

@Override
public boolean boardingAllowed(GraphPath path, String zone, Set<String> allowedFareIds) {
for (Map.Entry<FareType, Collection<FareRuleSet>> kv : fareRulesPerType.entrySet()) {
@@ -94,9 +133,13 @@ but visit temporarily (maybe 1 stop only) an 'external' zone */
if (ruleSet.getContains().containsAll(zones)) { // contains, not equals !!
FareAttribute attribute = ruleSet.getFareAttribute();
// transfers are evaluated at boarding time
if (attribute.isTransferDurationSet() &&
tripTime > attribute.getTransferDuration()) {
continue;
if (attribute.isTransferDurationSet()) {
if(tripTime > attribute.getTransferDuration()) {
LOG.debug("transfer time exceeded; {} > {} in fare {}", tripTime, attribute.getTransferDuration(), attribute.getId());
continue;
} else {
LOG.debug("transfer time OK; {} < {} in fare {}", tripTime, attribute.getTransferDuration(), attribute.getId());
}
}
float newFare = getFarePrice(attribute, fareType);
if (newFare < bestFare) {
@@ -105,7 +148,7 @@ but visit temporarily (maybe 1 stop only) an 'external' zone */
}
}
}

LOG.debug("HSL {} best for {}", bestAttribute, rides);
return new FareAndId(bestFare, bestAttribute == null ? null : bestAttribute.getId());
}
}
5 changes: 3 additions & 2 deletions travis-build.sh
Original file line number Diff line number Diff line change
@@ -17,10 +17,11 @@ DOCKER_IMAGE_PROD=$DOCKER_IMAGE:prod

if [ -z $TRAVIS_TAG ]; then
# Build image
echo Building OTP
echo Building OTP
docker build --tag="$ORG/$DOCKER_IMAGE:builder" -f Dockerfile.builder .
mkdir export
docker run --rm --entrypoint tar "$ORG/$DOCKER_IMAGE:builder" -c target|tar x -C ./
#package OTP quietly while keeping travis happpy
docker build --tag="$DOCKER_IMAGE_COMMIT" -f Dockerfile .
fi

@@ -31,7 +32,7 @@ if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
docker pull $DOCKER_IMAGE_COMMIT
docker tag $DOCKER_IMAGE_COMMIT $DOCKER_IMAGE_PROD
docker push $DOCKER_IMAGE_PROD
else
else
echo "Pushing latest image"
docker push $DOCKER_IMAGE_COMMIT
docker tag $DOCKER_IMAGE_COMMIT $DOCKER_IMAGE_LATEST

0 comments on commit 4289beb

Please sign in to comment.