Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new SimpleStreetLinker on origin/destination
Working on #2267. Linking works but code is a little messy. Currently one temporary vertex is created when closest thing is existing from/to vertex. And a second split vertex is created if the closest edge is a street which is splitted. All new edges and vertices are temporary and are removed when thread finishes.
- Loading branch information
Showing
7 changed files
with
305 additions
and
55 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
src/main/java/org/opentripplanner/graph_builder/linking/OriginDestinationLinker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.opentripplanner.graph_builder.linking; | ||
|
||
import com.vividsolutions.jts.geom.Coordinate; | ||
import org.apache.lucene.store.TrackingDirectoryWrapper; | ||
import org.opentripplanner.common.model.GenericLocation; | ||
import org.opentripplanner.common.model.P2; | ||
import org.opentripplanner.routing.core.RoutingRequest; | ||
import org.opentripplanner.routing.core.TraverseMode; | ||
import org.opentripplanner.routing.core.TraverseModeSet; | ||
import org.opentripplanner.routing.edgetype.StreetEdge; | ||
import org.opentripplanner.routing.edgetype.TemporaryFreeEdge; | ||
import org.opentripplanner.routing.graph.Graph; | ||
import org.opentripplanner.routing.graph.Vertex; | ||
import org.opentripplanner.routing.location.TemporaryStreetLocation; | ||
import org.opentripplanner.routing.vertextype.StreetVertex; | ||
import org.opentripplanner.util.NonLocalizedString; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** Linking seems to work. | ||
* | ||
* | ||
* Created by mabu on 20.5.2016. | ||
*/ | ||
public class OriginDestinationLinker extends SimpleStreetSplitter { | ||
private static final Logger LOG = LoggerFactory.getLogger(OriginDestinationLinker.class); | ||
/** | ||
* Construct a new SimpleStreetSplitter. Be aware that only one SimpleStreetSplitter should be | ||
* active on a graph at any given time. | ||
* | ||
* @param graph | ||
*/ | ||
public OriginDestinationLinker(Graph graph) { | ||
super(graph); | ||
} | ||
|
||
public Vertex getClosestVertex(GenericLocation location, RoutingRequest options, | ||
boolean endVertex) { | ||
if (endVertex) { | ||
LOG.debug("Finding end vertex for {}", location); | ||
} else { | ||
LOG.debug("Finding start vertex for {}", location); | ||
} | ||
Coordinate coord = location.getCoordinate(); | ||
//TODO: add nice name | ||
TemporaryStreetLocation closest = new TemporaryStreetLocation( | ||
"corner " + Math.random(), coord, new NonLocalizedString("generated point"), endVertex); | ||
|
||
TraverseModeSet modes = options.modes; | ||
TraverseMode nonTransitMode = TraverseMode.WALK; | ||
if (modes.getCar()) | ||
nonTransitMode = TraverseMode.CAR; | ||
else if (modes.getWalk()) | ||
nonTransitMode = TraverseMode.WALK; | ||
else if (modes.getBicycle()) | ||
nonTransitMode = TraverseMode.BICYCLE; | ||
|
||
if(!link(closest, nonTransitMode)) { | ||
LOG.warn("Couldn't link {}", location); | ||
} | ||
return closest; | ||
|
||
} | ||
|
||
/** | ||
* Make the appropriate type of link edges from a vertex | ||
* | ||
* @param from | ||
* @param to | ||
*/ | ||
@Override | ||
protected void makeLinkEdges(Vertex from, StreetVertex to) { | ||
TemporaryStreetLocation tse = (TemporaryStreetLocation) from; | ||
if (tse.isEndVertex()) { | ||
LOG.debug("Linking end vertex to {} -> {}", to, tse); | ||
new TemporaryFreeEdge(to, tse); | ||
} else { | ||
LOG.debug("Linking start vertex to {} -> {}", tse, to); | ||
new TemporaryFreeEdge(tse, to); | ||
} | ||
} | ||
|
||
@Override | ||
protected void removeOriginalEdge(StreetEdge edge) { | ||
//Intentionally empty since we are creating temporary edges which should not change the graph | ||
//and they are removed anyway when thread is disposed | ||
} | ||
|
||
@Override | ||
protected void updateIndex(P2<StreetEdge> edges) { | ||
//Intentionally empty since we are creating temporary edges which should not change the graph | ||
//and they are removed anyway when thread is disposed | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.