Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix router mapping

  • Loading branch information...
commit ba58884377665179076ba5229fbc5999fa898459 1 parent f463f3b
novalis authored
View
5 opentripplanner-api-webapp/src/main/java/org/opentripplanner/api/ws/Routers.java
@@ -47,15 +47,16 @@
public RouterList getRouterIds()
throws JSONException {
RouterList routerList = new RouterList();
+ graphService.loadAllGraphs();
for (String id : graphService.getGraphIds()) {
RouterInfo routerInfo = new RouterInfo();
routerInfo.routerId = id;
- Graph graph = graphService.getGraph();
+ Graph graph = graphService.getGraph(id);
HullService service = graph.getService(HullService.class);
if (service == null) {
//TODO: A concave hull would be better, but unfortunately is extremely slow to compute for
//large graphs
- Geometry hull = GraphUtils.makeBuffer(graph);
+ Geometry hull = GraphUtils.makeConvexHull(graph);
service = new StoredHullService(hull);
graph.putService(HullService.class, service);
}
View
4 opentripplanner-api-webapp/src/test/java/org/opentripplanner/api/ws/TestRequest.java
@@ -125,6 +125,10 @@ public void putGraph(String graphId, Graph graph) {
graphs.put(graphId, graph);
}
+ @Override
+ public void loadAllGraphs() {
+ //nothing to do
+ }
}
/* This is a hack to hold context and graph data between test runs, since loading it is slow. */
View
5 opentripplanner-routing/src/main/java/org/opentripplanner/routing/impl/GraphServiceBeanImpl.java
@@ -70,4 +70,9 @@ public Graph getGraph(String routerId) {
public List<String> getGraphIds() {
return Arrays.asList("default");
}
+
+ @Override
+ public void loadAllGraphs() {
+ //nothing to do
+ }
}
View
36 opentripplanner-routing/src/main/java/org/opentripplanner/routing/impl/GraphServiceImpl.java
@@ -14,7 +14,9 @@
package org.opentripplanner.routing.impl;
import java.util.Collection;
+import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
@@ -27,6 +29,7 @@
import org.springframework.context.annotation.Scope;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.io.support.ResourcePatternResolver;
@Scope("singleton")
public class GraphServiceImpl implements GraphService, ResourceLoaderAware {
@@ -75,6 +78,32 @@ public void preloadGraphs() {
}
}
+ @Override
+ public void loadAllGraphs() {
+ if (resourceLoader instanceof ResourcePatternResolver) {
+ ResourcePatternResolver resolver = (ResourcePatternResolver) resourceLoader;
+ try {
+ String resourceName = resourcePattern.replace("{}", "*/");
+ Resource[] resources = resolver.getResources(resourceName + "Graph.obj");
+ for (Resource resource : resources) {
+ resourceName = resource.getURI().toString();
+ if (graphs.get(resourceName) != null)
+ continue;
+ InputStream is = resource.getInputStream();
+ Graph graph = Graph.load(is, LoadLevel.FULL);
+ graphs.put(resourceName, graph);
+ levels.put(resourceName, LoadLevel.FULL);
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
@Override
public Graph getGraph() {
return getGraph(null);
@@ -146,7 +175,12 @@ public void setDefaultRouterId(String routerId) {
@Override
public Collection<String> getGraphIds() {
- return graphs.keySet();
+ ArrayList<String> out = new ArrayList<String>();
+ String base = resourcePattern.replace("{}", "");
+ for (String id : graphs.keySet()) {
+ out.add(id.replaceFirst(base, "").replace("/Graph.obj",""));
+ }
+ return out;
}
@Override
View
4 opentripplanner-routing/src/main/java/org/opentripplanner/routing/impl/raptor/Raptor.java
@@ -78,8 +78,9 @@ public void setMultiPathTimeout (double seconds) {
@Override
public List<GraphPath> getPaths(RoutingRequest options) {
+ final Graph graph = graphService.getGraph(options.getRouterId());
if (options.rctx == null) {
- options.setRoutingContext(graphService.getGraph(options.getRouterId()));
+ options.setRoutingContext(graph);
options.rctx.pathParsers = new PathParser[1];
options.rctx.pathParsers[0] = new BasicPathParser();
}
@@ -88,7 +89,6 @@ public void setMultiPathTimeout (double seconds) {
return sptService.getShortestPathTree(options).getPaths();
}
- Graph graph = graphService.getGraph(options.getRouterId());
RaptorData data = graph.getService(RaptorDataService.class).getData();
double initialWalk = options.getMaxWalkDistance() * 1.1;
View
3  opentripplanner-routing/src/main/java/org/opentripplanner/routing/services/GraphService.java
@@ -53,4 +53,7 @@
public Collection<String> getGraphIds();
+ /** Forces loading of all known graphs */
+ void loadAllGraphs();
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.