Skip to content

Commit

Permalink
Bugfix on SpeedTest - the graph is not indexed after it is loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
t2gran committed Jan 16, 2020
1 parent f76183e commit 036437c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/opentripplanner/datastore/OtpDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.opentripplanner.datastore.configure.DataStoreFactory;

import javax.validation.constraints.NotNull;
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -93,6 +94,22 @@ public void open() {
addAll(findMultipleSources(Collections.emptyList(), UNKNOWN));
}

/**
* Static method used to get direct access to graph file without creating the
* {@link OtpDataStore} - this is used by other application and tests that want to load the
* graph from a directory on the local file system.
*
* Never use this method in OTP main application to access the graph, use the data store.
*
* @param path the location where the graph file must exist.
*
* @return The graph file - the graph is not loaded, you can use the
* {@link org.opentripplanner.routing.graph.Graph#load(File)} to load the graph.
*/
public static File graphFile(File path) {
return new File(path, GRAPH_FILENAME);
}

/**
* @return a description(path) for each datasource used/enabled.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.transit.raptor.speed_test;

import org.opentripplanner.datastore.OtpDataStore;
import org.opentripplanner.routing.algorithm.raptor.transit.TransitLayer;
import org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule;
import org.opentripplanner.routing.algorithm.raptor.transit.mappers.TransitLayerMapper;
Expand Down Expand Up @@ -35,6 +36,7 @@
* Also demonstrates how to run basic searches without using the graphQL profile routing API.
*/
public class SpeedTest {

private static final boolean TEST_NUM_OF_ADDITIONAL_TRANSFERS = false;
private static final String TRAVEL_SEARCH_FILENAME = "travelSearch";

Expand All @@ -61,9 +63,9 @@ public class SpeedTest {
private RangeRaptorService<TripSchedule> service;


private SpeedTest(Graph graph, SpeedTestCmdLineOpts opts) {
this.graph = graph;
private SpeedTest(SpeedTestCmdLineOpts opts) {
this.opts = opts;
this.graph = loadGraph(opts.rootDir());
this.transitLayer = TransitLayerMapper.map(graph);
this.streetRouter = new EgressAccessRouter(graph, transitLayer);
this.nAdditionalTransfers = opts.numOfExtraTransfers();
Expand All @@ -76,15 +78,20 @@ public static void main(String[] args) throws Exception {
// Given the following setup
AvgTimer.enableTimers(true);
SpeedTestCmdLineOpts opts = new SpeedTestCmdLineOpts(args);
Graph graph = Graph.load(new File(opts.rootDir(), "Graph.obj"));

// create a new test
SpeedTest speedTest = new SpeedTest(graph, opts);
SpeedTest speedTest = new SpeedTest(opts);

// and run it
speedTest.runTest();
}

private static Graph loadGraph(File rootDir) {
Graph graph = Graph.load(OtpDataStore.graphFile(rootDir));
graph.index();
return graph;
}

private void runTest() throws Exception {
final SpeedTestProfile[] speedTestProfiles = opts.profiles();
final int nSamples = opts.numberOfTestsSamplesToRun();
Expand Down

1 comment on commit 036437c

@t2gran
Copy link
Member Author

@t2gran t2gran commented on 036437c Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit fixes the SpeedTest, witch after the DataStore was merged into dev-2.x did not work, due to the graph name change (from Graph.obj to graph.obj) and that the Graph now must explicit be indexed after it is loaded.

This commit do not have any effect on main OTP.

Please sign in to comment.