Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adapt routing classes to GraphVertex refactor

  • Loading branch information...
commit fb0ce234d3e6ca84020efc2bc1d83d748f37c95a 1 parent 4806579
@abyrd abyrd authored
View
4 opentripplanner-routing/src/main/java/org/opentripplanner/routing/algorithm/Dijkstra.java
@@ -92,7 +92,7 @@ public BasicShortestPathTree getShortestPathTree(Vertex target, double weightLim
if (u == target)
break;
- Iterable<Edge> outgoing = graph.getOutgoing(u);
+ Iterable<Edge> outgoing = u.getOutgoing();
for (Edge edge : outgoing) {
State sv = edge.traverse(su);
if (sv != null
@@ -137,7 +137,7 @@ public BasicShortestPathTree getShortestPathTree(double weightLimit, int nodeLim
break;
}
- Iterable<Edge> outgoing = graph.getOutgoing(u);
+ Iterable<Edge> outgoing = u.getOutgoing();
for (Edge edge : outgoing) {
// if (!(edge instanceof TurnEdge || edge instanceof FreeEdge || edge instanceof Shortcut || edge instanceof PlainStreetEdge)) {
// //only consider street edges when contracting
View
82 ...tripplanner-routing/src/main/java/org/opentripplanner/routing/algorithm/GraphLibrary.java
@@ -15,14 +15,11 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.opentripplanner.routing.core.Edge;
import org.opentripplanner.routing.core.Graph;
-import org.opentripplanner.routing.core.GraphVertex;
-import org.opentripplanner.routing.core.HasEdges;
import org.opentripplanner.routing.core.Vertex;
public class GraphLibrary {
@@ -30,85 +27,26 @@
public static Collection<Edge> getIncomingEdges(Graph graph, Vertex tov,
Map<Vertex, List<Edge>> extraEdges) {
- Collection<Edge> incoming = null;
-
- if (tov instanceof HasEdges) {
-
- /**
- * As a performance tweak, note that we don't examine 'extraEdges' if the Vertex
- * implements HasEdges, since the whole point is to avoid the HashMap lookup.
- */
- incoming = extendEdges(incoming, ((HasEdges) tov).getIncoming());
-
+ if (extraEdges.containsKey(tov)) {
+ Collection<Edge> ret = new ArrayList<Edge>(tov.getIncoming());
+ ret.addAll(extraEdges.get(tov));
+ return ret;
} else {
- GraphVertex gv = graph.getGraphVertex(tov);
- if (gv != null)
- incoming = extendEdges(incoming, gv.getIncoming());
-
- if (extraEdges != null && extraEdges.containsKey(tov))
- incoming = extendEdges(incoming, extraEdges.get(tov));
+ return tov.getIncoming();
}
- if (incoming == null)
- incoming = Collections.emptyList();
-
- return incoming;
}
public static Collection<Edge> getOutgoingEdges(Graph graph, Vertex fromv,
Map<Vertex, List<Edge>> extraEdges) {
- Collection<Edge> outgoing = null;
-
- if (fromv instanceof HasEdges) {
-
- /**
- * As a performance tweak, note that we don't examine 'extraEdges' if the Vertex
- * implements HasEdges, since the whole point is to avoid the HashMap lookup.
- */
- outgoing = extendEdges(outgoing, ((HasEdges) fromv).getOutgoing());
-
+ if (extraEdges.containsKey(fromv)) {
+ Collection<Edge> ret = new ArrayList<Edge>(fromv.getOutgoing());
+ ret.addAll(extraEdges.get(fromv));
+ return ret;
} else {
- GraphVertex gv = graph.getGraphVertex(fromv);
- if (gv != null)
- outgoing = extendEdges(outgoing, gv.getOutgoing());
-
- if (extraEdges != null && extraEdges.containsKey(fromv))
- outgoing = extendEdges(outgoing, extraEdges.get(fromv));
+ return fromv.getOutgoing();
}
-
-// Is this necessary? It includes both incoming and outgoing extra edges in the result,
-// which causes a lot of defective traversals. (AMB)
-// if (fromv instanceof StreetLocation) {
-// StreetLocation sl = (StreetLocation) fromv;
-// outgoing = extendEdges(outgoing, sl.getExtra());
-// }
-
- if (outgoing == null)
- outgoing = Collections.emptyList();
-
- return outgoing;
}
- /****
- * Private Methods
- ****/
-
- private static <E extends Edge> Collection<Edge> extendEdges(Collection<Edge> existing,
- Collection<E> additionalEdges) {
-
- if (existing == null || existing.size() == 0) {
- if (additionalEdges == null || additionalEdges.isEmpty())
- return null;
- return new ArrayList<Edge>(additionalEdges);
- }
-
- if (additionalEdges == null || additionalEdges.size() == 0)
- return existing;
-
- List<Edge> edges = new ArrayList<Edge>(existing.size() + additionalEdges.size());
- edges.addAll(existing);
- edges.addAll(additionalEdges);
- return edges;
- }
}
View
20 ...r-routing/src/main/java/org/opentripplanner/routing/algorithm/strategies/WeightTable.java
@@ -29,11 +29,9 @@
import org.apache.commons.pool.impl.GenericObjectPool;
import org.opentripplanner.routing.core.Edge;
import org.opentripplanner.routing.core.Graph;
-import org.opentripplanner.routing.core.GraphVertex;
import org.opentripplanner.routing.core.State;
import org.opentripplanner.routing.core.StateEditor;
import org.opentripplanner.routing.core.TransitStop;
-import org.opentripplanner.routing.core.TraverseMode;
import org.opentripplanner.routing.core.TraverseOptions;
import org.opentripplanner.routing.core.Vertex;
import org.opentripplanner.routing.core.GenericVertex;
@@ -62,7 +60,8 @@
public WeightTable(Graph g) {
this.g = g;
// default max walk speed is biking speed
- maxWalkSpeed = new TraverseOptions(TraverseMode.BICYCLE).speed;
+ //maxWalkSpeed = new TraverseOptions(TraverseMode.BICYCLE).speed;
+ maxWalkSpeed = new TraverseOptions().speed;
}
public double getWeight(Vertex from, Vertex to) {
@@ -125,9 +124,9 @@ public void buildTable() {
LOG.debug("Number of vertices: " + g.getVertices().size());
stopVertices = new ArrayList<TransitStop>();
- for (GraphVertex gv : g.getVertices())
- if (gv.vertex instanceof TransitStop)
- stopVertices.add((TransitStop) gv.vertex);
+ for (Vertex gv : g.getVertices())
+ if (gv instanceof TransitStop)
+ stopVertices.add((TransitStop) gv);
int nStops = stopVertices.size();
stopIndices = new IdentityHashMap<GenericVertex, Integer>(nStops);
@@ -230,8 +229,7 @@ public Void call() throws Exception {
table[oi][di] = (float) w;
// LOG.debug(" Dest " + u + " w=" + w);
}
- GraphVertex gu = g.getGraphVertex(uVertex.getLabel());
- for (Edge e : gu.getOutgoing()) {
+ for (Edge e : uVertex.getOutgoing()) {
if (!(e instanceof PreBoardEdge)) {
State v = e.optimisticTraverse(u);
if (v != null && spt.add(v))
@@ -248,8 +246,7 @@ public Void call() throws Exception {
q.add(origin);
while (!q.isEmpty()) {
Vertex u = q.poll();
- GraphVertex gu = g.getGraphVertex(u.getLabel());
- for (Edge e : gu.getOutgoing()) {
+ for (Edge e : u.getOutgoing()) {
if (e instanceof PatternBoard) {
Vertex v = ((PatternBoard) e).getToVertex();
// give onboard vertices same index as their
@@ -292,8 +289,7 @@ public Void call() throws Exception {
}
continue;
}
- GraphVertex gu = g.getGraphVertex(uVertex.getLabel());
- for (Edge e : gu.getOutgoing()) {
+ for (Edge e : uVertex.getOutgoing()) {
// LOG.debug(" Edge " + e);
State v = e.optimisticTraverse(u);
if (v != null && spt.add(v))
View
10 opentripplanner-routing/src/main/java/org/opentripplanner/routing/core/LowerBoundGraph.java
@@ -54,15 +54,15 @@ public LowerBoundGraph(Graph original, int kind) {
opt.setArriveBy(true);
LOG.info("Loading origial graph into compact representation...");
ArrayList<State> svs = new ArrayList<State>();
- for (GraphVertex gv : original.getVertices()) {
- GenericVertex u = (GenericVertex) (gv.vertex);
+ for (Vertex gv : original.getVertices()) {
+ GenericVertex u = (GenericVertex) (gv);
State su = new State(u, opt);
svs.clear();
Iterable<Edge> edges;
if (kind == INCOMING)
- edges = original.getIncoming(u);
+ edges = u.getIncoming();
else
- edges = original.getOutgoing(u);
+ edges = u.getOutgoing();
// avoid empty edgelist entries by traversing all edges first
for (Edge e : edges) {
State sv = e.optimisticTraverse(su);
@@ -277,7 +277,7 @@ private BasicShortestPathTree originalSSSP(Vertex o){
while ( ! q.empty()) {
State su = q.extract_min();
if ( ! spt.visit(su)) continue;
- for (Edge e : originalGraph.getOutgoing(su.getVertex())) {
+ for (Edge e : su.getVertex().getOutgoing()) {
State sv = e.optimisticTraverse(su);
if (sv != null && spt.add(sv))
q.insert(sv, sv.getWeight());
View
21 opentripplanner-routing/src/main/java/org/opentripplanner/routing/edgetype/TurnEdge.java
@@ -13,6 +13,8 @@
package org.opentripplanner.routing.edgetype;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -46,13 +48,9 @@
public int turnCost;
- /* these are set from edge lists during deserialization.
- * some other solution should be used instead of making them public
- */
-
- public transient StreetVertex fromv;
+ StreetVertex fromv;
- public transient StreetVertex tov;
+ StreetVertex tov;
private List<Patch> patches;
@@ -280,4 +278,15 @@ public boolean hasBogusName() {
public boolean isNoThruTraffic() {
return fromv.isNoThruTraffic();
}
+
+ private void writeObject(ObjectOutputStream out) throws IOException, ClassNotFoundException {
+ if (fromv == null)
+ System.out.printf("fromv null %s \n", this);
+
+ if (tov == null)
+ System.out.printf("tov null %s \n", this);
+
+ out.defaultWriteObject();
+ }
+
}
View
13 ...er-routing/src/main/java/org/opentripplanner/routing/impl/ContractionPathServiceImpl.java
@@ -24,11 +24,11 @@
import java.util.regex.Pattern;
import org.onebusaway.gtfs.model.AgencyAndId;
+import org.opentripplanner.routing.algorithm.strategies.LBGRemainingWeightHeuristic;
import org.opentripplanner.routing.algorithm.strategies.TableRemainingWeightHeuristic;
import org.opentripplanner.routing.algorithm.strategies.WeightTable;
import org.opentripplanner.routing.core.Edge;
import org.opentripplanner.routing.core.Graph;
-import org.opentripplanner.routing.core.GraphVertex;
import org.opentripplanner.routing.core.State;
import org.opentripplanner.routing.core.StateEditor;
import org.opentripplanner.routing.core.TransitStop;
@@ -152,10 +152,10 @@ public void setIndexService(StreetVertexIndexService indexService) {
LOG
.debug("No weight table in graph or non-transit itinerary requested. Keeping existing A* heuristic.");
}
-
+
// EXPERIMENTAL
// options.remainingWeightHeuristic = new
- // LBGRemainingWeightHeuristic(_graphService.getGraph());
+ // LBGRemainingWeightHeuristic(_graphService.getGraph());
// If transit is not to be used, disable walk limit and only search for one itinerary.
if (!options.getModes().getTransit()) {
@@ -330,14 +330,9 @@ public boolean isAccessible(String place, TraverseOptions options) {
}
public boolean multipleOptionsBefore(Edge edge) {
- Graph graph = _graphService.getGraph();
boolean foundAlternatePaths = false;
Vertex start = edge.getFromVertex();
- GraphVertex gv = graph.getGraphVertex(start);
- if (gv == null) {
- return false;
- }
- for (Edge out : gv.getOutgoing()) {
+ for (Edge out : start.getOutgoing()) {
if (out == edge) {
continue;
}
Please sign in to comment.
Something went wrong with that request. Please try again.