forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor StreetEdge splitting for bike rentals
The testing is a work in progress Refs opentripplanner#2787
- Loading branch information
1 parent
3164244
commit 8db21bf
Showing
10 changed files
with
690 additions
and
210 deletions.
There are no files selected for viewing
146 changes: 106 additions & 40 deletions
146
src/main/java/org/opentripplanner/graph_builder/linking/StreetSplitter.java
Large diffs are not rendered by default.
Oops, something went wrong.
139 changes: 139 additions & 0 deletions
139
src/main/java/org/opentripplanner/routing/edgetype/PartialStreetEdge.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,139 @@ | ||
package org.opentripplanner.routing.edgetype; | ||
|
||
import org.locationtech.jts.geom.Coordinate; | ||
import org.locationtech.jts.geom.LineString; | ||
import org.opentripplanner.common.TurnRestriction; | ||
import org.opentripplanner.routing.graph.Edge; | ||
import org.opentripplanner.routing.graph.Graph; | ||
import org.opentripplanner.routing.util.ElevationUtils; | ||
import org.opentripplanner.routing.vertextype.StreetVertex; | ||
import org.opentripplanner.routing.vertextype.TemporaryVertex; | ||
import org.opentripplanner.util.I18NString; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* This class is used to model a StreetEdge that has been non-destructively split from another StreetEdge. | ||
*/ | ||
public class PartialStreetEdge extends StreetWithElevationEdge { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* The edge on which this lies. | ||
*/ | ||
protected StreetEdge parentEdge; | ||
|
||
|
||
/** | ||
* Create a new partial street edge along the given 'parentEdge' from 'v1' to 'v2'. | ||
* If the length is 0, a new length is calculated from the geometry. | ||
* The elevation data is calculated using the 'parentEdge' and given 'length'. | ||
*/ | ||
public PartialStreetEdge(StreetEdge parentEdge, StreetVertex v1, StreetVertex v2, | ||
LineString geometry, I18NString name, double length) { | ||
super(v1, v2, geometry, name, length, parentEdge.getPermission(), false); | ||
this.parentEdge = parentEdge; | ||
setCarSpeed(parentEdge.getCarSpeed()); | ||
|
||
// If length is 0, use the provided geometry to estimate it | ||
if (length == 0) { | ||
calculateLengthFromGeometry(); | ||
} | ||
|
||
setElevationProfileUsingParents(); | ||
} | ||
|
||
/** | ||
* Partial edges are always partial. | ||
*/ | ||
@Override | ||
public boolean isPartial() { | ||
return true; | ||
} | ||
|
||
/** | ||
* Have the ID of their parent. | ||
*/ | ||
@Override | ||
public int getId() { | ||
return parentEdge.getId(); | ||
} | ||
|
||
/** | ||
* Have the inbound angle of their parent. | ||
*/ | ||
@Override | ||
public int getInAngle() { | ||
return parentEdge.getInAngle(); | ||
} | ||
|
||
/** | ||
* Have the outbound angle of their parent. | ||
*/ | ||
@Override | ||
public int getOutAngle() { | ||
return parentEdge.getInAngle(); | ||
} | ||
|
||
/** | ||
* Have the turn restrictions of their parent. | ||
*/ | ||
@Override | ||
protected List<TurnRestriction> getTurnRestrictions(Graph graph) { | ||
return graph.getTurnRestrictions(parentEdge); | ||
} | ||
|
||
/** | ||
* This implementation makes it so that TurnRestrictions on the parent edge are applied to this edge as well. | ||
*/ | ||
@Override | ||
public boolean isEquivalentTo(Edge e) { | ||
return (e == this || e == parentEdge); | ||
} | ||
|
||
@Override | ||
public boolean isReverseOf(Edge e) { | ||
Edge other = e; | ||
if (e instanceof PartialStreetEdge) { | ||
other = ((PartialStreetEdge) e).parentEdge; | ||
} | ||
|
||
// TODO(flamholz): is there a case where a partial edge has a reverse of its own? | ||
return parentEdge.isReverseOf(other); | ||
} | ||
|
||
@Override | ||
public boolean isRoundabout() { | ||
return parentEdge.isRoundabout(); | ||
} | ||
|
||
/** | ||
* Returns true if this edge is trivial - beginning and ending at the same point. | ||
*/ | ||
public boolean isTrivial() { | ||
Coordinate fromCoord = this.getFromVertex().getCoordinate(); | ||
Coordinate toCoord = this.getToVertex().getCoordinate(); | ||
return fromCoord.equals(toCoord); | ||
} | ||
|
||
public StreetEdge getParentEdge() { | ||
return parentEdge; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PartialStreetEdge(" + this.getName() + ", " + this.getFromVertex() + " -> " | ||
+ this.getToVertex() + " length=" + this.getDistance() + " carSpeed=" | ||
+ this.getCarSpeed() + " parentEdge=" + parentEdge + ")"; | ||
} | ||
|
||
private void setElevationProfileUsingParents() { | ||
setElevationProfile( | ||
ElevationUtils.getPartialElevationProfile( | ||
getParentEdge().getElevationProfile(), 0, getDistance() | ||
), | ||
false | ||
); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/opentripplanner/routing/edgetype/SemiPermanentPartialStreetEdge.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,35 @@ | ||
package org.opentripplanner.routing.edgetype; | ||
|
||
import org.locationtech.jts.geom.LineString; | ||
import org.opentripplanner.routing.core.State; | ||
import org.opentripplanner.routing.vertextype.SplitterVertex; | ||
import org.opentripplanner.routing.vertextype.StreetVertex; | ||
import org.opentripplanner.util.I18NString; | ||
|
||
/** | ||
* This class is used to model a SemiPermanent StreetEdge that was non-destructively split from another StreetEdge. | ||
* These StreetEdges are typically used to model access to things such as bike rental stations that are dynamically | ||
* created from bike rental updaters and could be subsequently removed from the feed. These edges aid in providing | ||
* access only when needed to the desired bike rental stations and also allow for the isolated removal of these edges | ||
* when they are no longer needed. | ||
*/ | ||
public class SemiPermanentPartialStreetEdge extends PartialStreetEdge { | ||
public SemiPermanentPartialStreetEdge( | ||
StreetEdge streetEdge, | ||
StreetVertex v1, | ||
StreetVertex v2, | ||
LineString geometry, | ||
I18NString name | ||
) { | ||
super(streetEdge, v1, v2, geometry, name, 0); | ||
} | ||
|
||
/** | ||
* There can often times be requests that do not need to traverse this edge, such as requests that don't want to | ||
* use a bike rental. In those cases, return null to avoid exploring this edge and any connected vertices further. | ||
*/ | ||
@Override public State traverse(State s0) { | ||
// TODO: add some conditions that would return null to avoid traversal | ||
return super.traverse(s0); | ||
} | ||
} |
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.