Skip to content

Commit

Permalink
Add 'tripDiscoveryMode': look out two weeks in future or past
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjacobs committed Nov 22, 2017
1 parent 2b34e57 commit a109081
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
Expand Up @@ -396,6 +396,10 @@ public abstract class RoutingResource {
@QueryParam("geoidElevation")
private Boolean geoidElevation;

/* If trip discovery mode (look out a week) should be used */
@QueryParam("tripDiscoveryMode")
private Boolean tripDiscoveryMode;

/*
* somewhat ugly bug fix: the graphService is only needed here for fetching per-graph time zones.
* this should ideally be done when setting the routing context, but at present departure/
Expand Down Expand Up @@ -646,6 +650,9 @@ protected RoutingRequest buildRequest() throws ParameterException {
if (geoidElevation != null)
request.geoidElevation = geoidElevation;

if (tripDiscoveryMode != null)
request.setTripDiscoveryMode(tripDiscoveryMode);

//getLocale function returns defaultLocale if locale is null
request.locale = ResourceBundleSingleton.INSTANCE.getLocale(locale);
return request;
Expand Down
Expand Up @@ -380,7 +380,15 @@ private void setServiceDays() {
addIfNotExists(this.serviceDays, new ServiceDay(graph, serviceDate, calendarService, agency.getId()));
addIfNotExists(this.serviceDays, new ServiceDay(graph, serviceDate.next(),
calendarService, agency.getId()));
if (opt.tripDiscoveryMode) {
ServiceDate sd = serviceDate;
for (int i = 0; i < 15; i++) {
sd = opt.arriveBy ? sd.previous() : sd.next();
addIfNotExists(this.serviceDays, new ServiceDay(graph, sd, calendarService, agency.getId()));
}
}
}

}
}

Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/opentripplanner/routing/core/RoutingRequest.java
Expand Up @@ -486,6 +486,9 @@ public class RoutingRequest implements Cloneable, Serializable {

public boolean enterStationsWithCar = false;

/** whether to use trip discovery mode - search farther in future or past for shortest trip */
public boolean tripDiscoveryMode = false;

/** Saves split edge which can be split on origin/destination search
*
* This is used so that TrivialPathException is thrown if origin and destination search would split the same edge
Expand Down Expand Up @@ -1007,7 +1010,8 @@ public boolean equals(Object o) {
&& Objects.equal(startingTransitTripId, other.startingTransitTripId)
&& useTraffic == other.useTraffic
&& disableAlertFiltering == other.disableAlertFiltering
&& geoidElevation == other.geoidElevation;
&& geoidElevation == other.geoidElevation
&& tripDiscoveryMode == other.tripDiscoveryMode;
}

/**
Expand Down Expand Up @@ -1038,7 +1042,8 @@ public int hashCode() {
+ new Boolean(reverseOptimizeOnTheFly).hashCode() * 95112799
+ new Boolean(ignoreRealtimeUpdates).hashCode() * 154329
+ new Boolean(disableRemainingWeightHeuristic).hashCode() * 193939
+ new Boolean(useTraffic).hashCode() * 10169;
+ new Boolean(useTraffic).hashCode() * 10169
+ new Boolean(tripDiscoveryMode).hashCode() * 209477;
if (batch) {
hashCode *= -1;
// batch mode, only one of two endpoints matters
Expand Down Expand Up @@ -1280,4 +1285,7 @@ public void canSplitEdge(StreetEdge edge) {

}

public void setTripDiscoveryMode(boolean tripDiscoveryMode) {
this.tripDiscoveryMode = tripDiscoveryMode;
}
}
@@ -0,0 +1,27 @@
/* This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */

package org.opentripplanner.routing.impl;

import org.opentripplanner.routing.spt.GraphPath;

import java.util.Comparator;

public class DurationComparator implements Comparator<GraphPath> {

@Override
public int compare(GraphPath o1, GraphPath o2) {
return o1.getDuration() - o2.getDuration();
}

}
Expand Up @@ -208,7 +208,11 @@ public List<GraphPath> getPaths(RoutingRequest options) {
LOG.debug("we have {} paths", paths.size());
}
LOG.debug("END SEARCH ({} msec)", System.currentTimeMillis() - searchBeginTime);
Collections.sort(paths, new PathComparator(options.arriveBy));
if (options.tripDiscoveryMode) {
paths.sort(new DurationComparator());
} else {
paths.sort(new PathComparator(options.arriveBy));
}

return paths;
}
Expand Down

0 comments on commit a109081

Please sign in to comment.