|
16 | 16 | import org.opentripplanner.routing.graph.Edge;
|
17 | 17 | import org.opentripplanner.routing.graph.Graph;
|
18 | 18 | import org.opentripplanner.routing.graph.Vertex;
|
| 19 | +import org.opentripplanner.routing.impl.DurationComparator; |
| 20 | +import org.opentripplanner.routing.impl.PathComparator; |
19 | 21 | import org.opentripplanner.routing.request.BannedStopSet;
|
20 | 22 | import org.opentripplanner.routing.spt.DominanceFunction;
|
| 23 | +import org.opentripplanner.routing.spt.GraphPath; |
21 | 24 | import org.opentripplanner.routing.spt.ShortestPathTree;
|
22 | 25 | import org.opentripplanner.util.DateUtils;
|
23 | 26 | import org.slf4j.Logger;
|
24 | 27 | import org.slf4j.LoggerFactory;
|
25 | 28 |
|
26 | 29 | import java.io.Serializable;
|
27 | 30 | import java.util.ArrayList;
|
| 31 | +import java.util.Arrays; |
28 | 32 | import java.util.Collections;
|
29 |
| -import java.util.Collections; |
| 33 | +import java.util.Comparator; |
30 | 34 | import java.util.Date;
|
31 | 35 | import java.util.GregorianCalendar;
|
32 | 36 | import java.util.HashMap;
|
@@ -464,6 +468,9 @@ public class RoutingRequest implements Cloneable, Serializable {
|
464 | 468 | /** Whether to apply the ellipsoid->geoid offset to all elevations in the response */
|
465 | 469 | public boolean geoidElevation = false;
|
466 | 470 |
|
| 471 | + /** Which path comparator to use */ |
| 472 | + public String pathComparator = null; |
| 473 | + |
467 | 474 | /** Saves split edge which can be split on origin/destination search
|
468 | 475 | *
|
469 | 476 | * This is used so that TrivialPathException is thrown if origin and destination search would split the same edge
|
@@ -680,14 +687,14 @@ public void setOtherThanPreferredRoutesPenalty(int penalty) {
|
680 | 687 | if(penalty < 0) penalty = 0;
|
681 | 688 | this.otherThanPreferredRoutesPenalty = penalty;
|
682 | 689 | }
|
683 |
| - |
| 690 | + |
684 | 691 | public void setUnpreferredAgencies(String s) {
|
685 | 692 | if (!s.isEmpty()) {
|
686 | 693 | unpreferredAgencies = new HashSet<>();
|
687 | 694 | Collections.addAll(unpreferredAgencies, s.split(","));
|
688 | 695 | }
|
689 | 696 | }
|
690 |
| - |
| 697 | + |
691 | 698 | public void setUnpreferredRoutes(String s) {
|
692 | 699 | if (!s.isEmpty()) {
|
693 | 700 | //RouteMatcher expects route ids in format [FeedId]__[RouteId] -> replace ":" in ids with "__"
|
@@ -740,7 +747,7 @@ public void setBannedStopsHard(String s) {
|
740 | 747 | bannedStopsHard = StopMatcher.emptyMatcher();
|
741 | 748 | }
|
742 | 749 | }
|
743 |
| - |
| 750 | + |
744 | 751 | public void setBannedAgencies(String s) {
|
745 | 752 | if (!s.isEmpty()) {
|
746 | 753 | bannedAgencies = new HashSet<>();
|
@@ -801,7 +808,7 @@ public void setDateTime(String date, String time, TimeZone tz) {
|
801 | 808 | setDateTime(dateObject);
|
802 | 809 | }
|
803 | 810 |
|
804 |
| - public int getNumItineraries() { |
| 811 | + public int getNumItineraries() { |
805 | 812 | if (modes.isTransit()) {
|
806 | 813 | return numItineraries;
|
807 | 814 | } else {
|
@@ -837,14 +844,14 @@ public void setIntermediatePlacesFromStrings(List<String> intermediates) {
|
837 | 844 | intermediatePlaces.add(GenericLocation.fromOldStyleString(place));
|
838 | 845 | }
|
839 | 846 | }
|
840 |
| - |
| 847 | + |
841 | 848 | /** Clears any intermediate places from this request. */
|
842 | 849 | public void clearIntermediatePlaces() {
|
843 | 850 | if (this.intermediatePlaces != null) {
|
844 | 851 | this.intermediatePlaces.clear();
|
845 | 852 | }
|
846 | 853 | }
|
847 |
| - |
| 854 | + |
848 | 855 | /**
|
849 | 856 | * Returns true if there are any intermediate places set.
|
850 | 857 | */
|
@@ -946,7 +953,7 @@ public void setRoutingContext(Graph graph, Edge fromBackEdge, Vertex from, Verte
|
946 | 953 | this.rctx = new RoutingContext(this, graph, from, to);
|
947 | 954 | this.rctx.originBackEdge = fromBackEdge;
|
948 | 955 | }
|
949 |
| - |
| 956 | + |
950 | 957 | public void setRoutingContext(Graph graph, Vertex from, Vertex to) {
|
951 | 958 | setRoutingContext(graph, null, from, to);
|
952 | 959 | }
|
@@ -1429,4 +1436,12 @@ public List<Integer> getLocationSlacks() {
|
1429 | 1436 | }
|
1430 | 1437 | return locationSlacks;
|
1431 | 1438 | }
|
| 1439 | + |
| 1440 | + public Comparator<GraphPath> getPathComparator(boolean compareStartTimes) { |
| 1441 | + if ("duration".equals(pathComparator)) { |
| 1442 | + return new DurationComparator(); |
| 1443 | + } |
| 1444 | + return new PathComparator(compareStartTimes); |
| 1445 | + } |
| 1446 | + |
1432 | 1447 | }
|
0 commit comments