Skip to content

Commit 84930d2

Browse files
author
TeemuP
committed
Merge branch 'kryo-serialization' into kryo-merge
# Conflicts: # src/main/java/org/opentripplanner/api/common/RoutingResource.java # src/main/java/org/opentripplanner/routing/core/RoutingRequest.java # src/main/java/org/opentripplanner/routing/graph/Graph.java
2 parents 55dbb0d + 4996b6d commit 84930d2

20 files changed

+471
-180
lines changed

docs/Changelog.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Update onebusaway-gtfs to latest version from OBA project (#2636)
66
- Remove the coupling to OneBusAway GTFS within OTP's internal model by creating new classes replacing the external classes (#2494)
7+
- Allow itineraries in response to be sorted by duration (#2593)
78

89
## 1.3 (2018-08-03)
910

@@ -364,4 +365,4 @@ This release was made to consolidate all the development that had occurred with
364365
- and of course, lots of bugfixes
365366

366367
## 0.4.4 (2012-02-06)
367-
Release in anticipation of upcoming merges.
368+
Release in anticipation of upcoming merges.

docs/Governance.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ OpenTripPlanner is a member project of the [Software Freedom Conservancy](https:
77
| Sean Barbeau | University of South Florida |
88
| Torbjørn Barslett | Ruter Oslo |
99
| Sheldon Brown | Cambridge Systematics |
10-
| Andrew Byrd | Conveyal |
10+
| Andrew Byrd | PlannerStack Foundation |
1111
| Drew Dara-Abrams | Interline |
1212
| David Emory | Conveyal |
13-
| Jasper Hartong | PlannerStack Foundation |
1413
| Tuukka Hastrup | Helsingin Seudun Liikenne |
1514
| Frank Purcell | TriMet |
1615
| David Turner | ex-OpenPlans |
1716

1817
The PLC holds a quarterly video conference on the first Thursday of June, September, December, and March. An agenda is prepared as a collaborative document in advance of each quarterly meeting. These meetings are held at 9AM US Pacific time to accommodate members in the US Pacific, US Eastern, and Central European time zones.
1918

2019
We take care to avoid a governance system that is too conceptual or process-heavy. The main goal is to have regular agenda-driven meetings that yield clear decisions and action items assigned to specific people. The committee should ideally be composed of active, professional contributors to the OpenTripPlanner project, including representatives of organizations that host official public deployments of OTP.
20+
21+
We enfore a policy on the review and merging of new changes to the OTP system, guided by a roadmap maintained by the committee. All changes must be reviewed and approved by at least two people from two different organizations. The list of approved reviewers is the PLC Github group, visible here https://github.com/orgs/opentripplanner/teams/plc/members
22+

enunciate.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
<ruby-json-client disabled="true"/>
2020
<idl disabled="true"/>
2121
<swagger disabled="true"/>
22-
<docs disableRestMountpoint="true"/>
22+
<docs disableRestMountpoint="true" includeApplicationPath="true"/>
23+
<jaxrs>
24+
<application path="/otp/" />
25+
</jaxrs>
2326
</modules>
2427

2528
</enunciate>

pom.xml

+12-6
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,17 @@
464464
<artifactId>aws-java-sdk-sqs</artifactId>
465465
<version>${aws.version}</version>
466466
</dependency>
467-
<!-- Fast drop-in serialization including compound value types (structs) for Java -->
467+
<!-- Kryo serialization, used to save graphs to disk. -->
468468
<dependency>
469-
<groupId>de.ruedigermoeller</groupId>
470-
<artifactId>fst</artifactId>
471-
<version>2.34</version>
469+
<groupId>com.esotericsoftware</groupId>
470+
<artifactId>kryo</artifactId>
471+
<version>4.0.2</version>
472+
</dependency>
473+
<!-- Extra serializers for Kryo -->
474+
<dependency>
475+
<groupId>de.javakaffee</groupId>
476+
<artifactId>kryo-serializers</artifactId>
477+
<version>0.42</version>
472478
</dependency>
473479
<!-- XXX: temporary fox for the build that is currently broken because some transitive deps are not handled correctly -->
474480
<dependency>
@@ -823,11 +829,11 @@
823829
<artifactId>traffic-engine</artifactId>
824830
<version>0.2</version>
825831
</dependency>
826-
<!-- R5 may eventually be an alternate routing option within OTP, and provides Graph serialization. -->
832+
<!-- OTP 2.0 will adopt routing methods based on those in R5. This also contains a serialization test framework. -->
827833
<dependency>
828834
<groupId>com.conveyal</groupId>
829835
<artifactId>r5</artifactId>
830-
<version>4.0.0-SNAPSHOT</version>
836+
<version>4.4.0</version>
831837
<exclusions>
832838
<exclusion>
833839
<artifactId>slf4j-simple</artifactId>

src/main/java/org/opentripplanner/api/common/RoutingResource.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,14 @@ public abstract class RoutingResource {
415415
@QueryParam("heuristicStepsPerMainStep")
416416
private Integer heuristicStepsPerMainStep;
417417

418+
/**
419+
* Set the method of sorting itineraries in the response. Right now, the only supported value is "duration";
420+
* otherwise it uses default sorting. More sorting methods may be added in the future.
421+
*/
422+
@QueryParam("pathComparator")
423+
private String pathComparator;
424+
425+
418426
/*
419427
* somewhat ugly bug fix: the graphService is only needed here for fetching per-graph time zones.
420428
* this should ideally be done when setting the routing context, but at present departure/
@@ -545,7 +553,7 @@ protected RoutingRequest buildRequest() throws ParameterException {
545553
request.setWhiteListedAgencies(whiteListedAgencies);
546554

547555
HashMap<FeedScopedId, BannedStopSet> bannedTripMap = makeBannedTripMap(bannedTrips);
548-
556+
549557
if (bannedTripMap != null)
550558
request.bannedTrips = bannedTripMap;
551559

@@ -670,6 +678,9 @@ protected RoutingRequest buildRequest() throws ParameterException {
670678
if (heuristicStepsPerMainStep != null)
671679
request.heuristicStepsPerMainStep = heuristicStepsPerMainStep;
672680

681+
if (pathComparator != null)
682+
request.pathComparator = pathComparator;
683+
673684
//getLocale function returns defaultLocale if locale is null
674685
request.locale = ResourceBundleSingleton.INSTANCE.getLocale(locale);
675686
return request;

src/main/java/org/opentripplanner/api/resource/Routers.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.opentripplanner.graph_builder.GraphBuilder;
3333
import org.opentripplanner.routing.error.GraphNotFoundException;
3434
import org.opentripplanner.routing.graph.Graph;
35-
import org.opentripplanner.routing.graph.Graph.LoadLevel;
3635
import org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory;
3736
import org.opentripplanner.routing.impl.MemoryGraphSource;
3837
import org.opentripplanner.routing.services.GraphService;
@@ -189,7 +188,6 @@ public Response putGraphId(@PathParam("routerId") String routerId,
189188
public Response postGraphOverWire (
190189
@PathParam("routerId") String routerId,
191190
@QueryParam("preEvict") @DefaultValue("true") boolean preEvict,
192-
@QueryParam("loadLevel") @DefaultValue("FULL") LoadLevel level,
193191
InputStream is) {
194192
if (preEvict) {
195193
LOG.debug("pre-evicting graph");
@@ -198,7 +196,7 @@ public Response postGraphOverWire (
198196
LOG.debug("deserializing graph from POST data stream...");
199197
Graph graph;
200198
try {
201-
graph = Graph.load(is, level);
199+
graph = Graph.load(is);
202200
GraphService graphService = otpServer.getGraphService();
203201
graphService.registerGraph(routerId, new MemoryGraphSource(routerId, graph));
204202
return Response.status(Status.CREATED).entity(graph.toString() + "\n").build();

src/main/java/org/opentripplanner/graph_builder/GraphBuilder.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.opentripplanner.reflect.ReflectionLibrary;
2424
import org.opentripplanner.routing.core.RoutingRequest;
2525
import org.opentripplanner.routing.graph.Graph;
26-
import org.opentripplanner.routing.graph.Graph.LoadLevel;
2726
import org.opentripplanner.standalone.CommandLineParameters;
2827
import org.opentripplanner.standalone.GraphBuilderParameters;
2928
import org.opentripplanner.standalone.OTPMain;
@@ -91,7 +90,7 @@ public void setAlwaysRebuild(boolean alwaysRebuild) {
9190
public void setBaseGraph(String baseGraph) {
9291
this.baseGraph = baseGraph;
9392
try {
94-
graph = Graph.load(new File(baseGraph), LoadLevel.FULL);
93+
graph = Graph.load(new File(baseGraph));
9594
} catch (Exception e) {
9695
throw new RuntimeException("error loading base graph");
9796
}

src/main/java/org/opentripplanner/graph_builder/GraphStats.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private void run() {
9595
/* open input graph (same for all commands) */
9696
File graphFile = new File(graphPath);
9797
try {
98-
graph = Graph.load(graphFile, Graph.LoadLevel.FULL);
98+
graph = Graph.load(graphFile);
9999
} catch (Exception e) {
100100
LOG.error("Exception while loading graph from " + graphFile);
101101
return;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.opentripplanner.kryo;
2+
3+
import com.esotericsoftware.kryo.Kryo;
4+
import com.esotericsoftware.kryo.io.Input;
5+
import com.esotericsoftware.kryo.serializers.MapSerializer;
6+
import com.google.common.collect.HashBiMap;
7+
8+
import java.util.Map;
9+
10+
/**
11+
* Created by abyrd on 2018-10-25
12+
*/
13+
public class HashBiMapSerializer extends MapSerializer {
14+
15+
protected Map create(Kryo kryo, Input input, Class<Map> type) {
16+
return HashBiMap.create();
17+
}
18+
19+
}

src/main/java/org/opentripplanner/routing/core/RoutingRequest.java

+23-8
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616
import org.opentripplanner.routing.graph.Edge;
1717
import org.opentripplanner.routing.graph.Graph;
1818
import org.opentripplanner.routing.graph.Vertex;
19+
import org.opentripplanner.routing.impl.DurationComparator;
20+
import org.opentripplanner.routing.impl.PathComparator;
1921
import org.opentripplanner.routing.request.BannedStopSet;
2022
import org.opentripplanner.routing.spt.DominanceFunction;
23+
import org.opentripplanner.routing.spt.GraphPath;
2124
import org.opentripplanner.routing.spt.ShortestPathTree;
2225
import org.opentripplanner.util.DateUtils;
2326
import org.slf4j.Logger;
2427
import org.slf4j.LoggerFactory;
2528

2629
import java.io.Serializable;
2730
import java.util.ArrayList;
31+
import java.util.Arrays;
2832
import java.util.Collections;
29-
import java.util.Collections;
33+
import java.util.Comparator;
3034
import java.util.Date;
3135
import java.util.GregorianCalendar;
3236
import java.util.HashMap;
@@ -464,6 +468,9 @@ public class RoutingRequest implements Cloneable, Serializable {
464468
/** Whether to apply the ellipsoid->geoid offset to all elevations in the response */
465469
public boolean geoidElevation = false;
466470

471+
/** Which path comparator to use */
472+
public String pathComparator = null;
473+
467474
/** Saves split edge which can be split on origin/destination search
468475
*
469476
* 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) {
680687
if(penalty < 0) penalty = 0;
681688
this.otherThanPreferredRoutesPenalty = penalty;
682689
}
683-
690+
684691
public void setUnpreferredAgencies(String s) {
685692
if (!s.isEmpty()) {
686693
unpreferredAgencies = new HashSet<>();
687694
Collections.addAll(unpreferredAgencies, s.split(","));
688695
}
689696
}
690-
697+
691698
public void setUnpreferredRoutes(String s) {
692699
if (!s.isEmpty()) {
693700
//RouteMatcher expects route ids in format [FeedId]__[RouteId] -> replace ":" in ids with "__"
@@ -740,7 +747,7 @@ public void setBannedStopsHard(String s) {
740747
bannedStopsHard = StopMatcher.emptyMatcher();
741748
}
742749
}
743-
750+
744751
public void setBannedAgencies(String s) {
745752
if (!s.isEmpty()) {
746753
bannedAgencies = new HashSet<>();
@@ -801,7 +808,7 @@ public void setDateTime(String date, String time, TimeZone tz) {
801808
setDateTime(dateObject);
802809
}
803810

804-
public int getNumItineraries() {
811+
public int getNumItineraries() {
805812
if (modes.isTransit()) {
806813
return numItineraries;
807814
} else {
@@ -837,14 +844,14 @@ public void setIntermediatePlacesFromStrings(List<String> intermediates) {
837844
intermediatePlaces.add(GenericLocation.fromOldStyleString(place));
838845
}
839846
}
840-
847+
841848
/** Clears any intermediate places from this request. */
842849
public void clearIntermediatePlaces() {
843850
if (this.intermediatePlaces != null) {
844851
this.intermediatePlaces.clear();
845852
}
846853
}
847-
854+
848855
/**
849856
* Returns true if there are any intermediate places set.
850857
*/
@@ -946,7 +953,7 @@ public void setRoutingContext(Graph graph, Edge fromBackEdge, Vertex from, Verte
946953
this.rctx = new RoutingContext(this, graph, from, to);
947954
this.rctx.originBackEdge = fromBackEdge;
948955
}
949-
956+
950957
public void setRoutingContext(Graph graph, Vertex from, Vertex to) {
951958
setRoutingContext(graph, null, from, to);
952959
}
@@ -1429,4 +1436,12 @@ public List<Integer> getLocationSlacks() {
14291436
}
14301437
return locationSlacks;
14311438
}
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+
14321447
}

0 commit comments

Comments
 (0)