Skip to content

Commit

Permalink
Merge pull request #5 from ibi-group/vehicle-rental-edge-split-refactor
Browse files Browse the repository at this point in the history
Vehicle rental edge split refactor
  • Loading branch information
evansiroky authored Jul 16, 2019
2 parents 5261851 + e6daec5 commit c9a95d9
Show file tree
Hide file tree
Showing 62 changed files with 2,783 additions and 1,545 deletions.

This file was deleted.

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
import org.opentripplanner.routing.graph.Edge;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.graph.Vertex;
import org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl;
import org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory;
import org.opentripplanner.routing.services.StreetVertexIndexService;
import org.opentripplanner.routing.spt.GraphPath;
import org.opentripplanner.routing.spt.ShortestPathTree;
import org.opentripplanner.routing.vertextype.TransitStop;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* These library functions are used by the streetless and streetful stop linkers, and in profile transfer generation.
Expand Down Expand Up @@ -56,16 +58,8 @@ public class NearbyStopFinder {
* network or straight line distance based on the presence of OSM street data in the graph.
*/
public NearbyStopFinder(Graph graph, double radiusMeters) {
this (graph, radiusMeters, graph.hasStreets);
}

/**
* Construct a NearbyStopFinder for the given graph and search radius.
* @param useStreets if true, search via the street network instead of using straight-line distance.
*/
public NearbyStopFinder(Graph graph, double radiusMeters, boolean useStreets) {
this.graph = graph;
this.useStreets = useStreets;
this.useStreets = graph.hasStreets;
this.radiusMeters = radiusMeters;
if (useStreets) {
earliestArrivalSearch = new EarliestArrivalSearch();
Expand All @@ -74,8 +68,10 @@ public NearbyStopFinder(Graph graph, double radiusMeters, boolean useStreets) {
// but we don't have much of a choice here. Use the default walking speed to convert.
earliestArrivalSearch.maxDuration = (int) (radiusMeters / new RoutingRequest().walkSpeed);
} else {
// FIXME use the vertex index already in the graph if it exists.
streetIndex = new StreetVertexIndexServiceImpl(graph);
if (graph.streetIndex == null) {
graph.index(new DefaultStreetVertexIndexFactory());
}
streetIndex = graph.streetIndex;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package org.opentripplanner.graph_builder.module;

import org.opentripplanner.common.StreetUtils;
import org.opentripplanner.graph_builder.services.GraphBuilderModule;
import org.opentripplanner.routing.graph.Graph;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import org.opentripplanner.common.StreetUtils;
import org.opentripplanner.graph_builder.linking.TransitToStreetNetworkModule;
import org.opentripplanner.graph_builder.services.GraphBuilderModule;
import org.opentripplanner.routing.graph.Graph;
import org.slf4j.*;

/**
* this module is part of the {@link org.opentripplanner.graph_builder.services.GraphBuilderModule} process. it design to remove small isolated
* islands form the graph. Islands are created when there is no connectivity in the map, island
Expand Down Expand Up @@ -40,8 +39,6 @@ public class PruneFloatingIslands implements GraphBuilderModule {
*/
private String islandLogFile;

private StreetLinkerModule transitToStreetNetwork;

public List<String> provides() {
return Collections.emptyList();
}
Expand All @@ -59,14 +56,12 @@ public List<String> getPrerequisites() {
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
LOG.info("Pruning isolated islands in street network");

StreetUtils.pruneFloatingIslands(graph, pruningThresholdIslandWithoutStops,
pruningThresholdIslandWithStops, islandLogFile);
if (transitToStreetNetwork == null) {
LOG.debug("TransitToStreetNetworkGraphBuilder was not provided to PruneFloatingIslands. Not attempting to reconnect stops.");
} else {
//reconnect stops on small islands (that removed)
transitToStreetNetwork.buildGraph(graph,extra);
}
StreetUtils.pruneFloatingIslands(
graph,
pruningThresholdIslandWithoutStops,
pruningThresholdIslandWithStops,
islandLogFile
);
LOG.debug("Done pruning isolated islands");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.opentripplanner.graph_builder.module;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import org.opentripplanner.graph_builder.linking.SimpleStreetSplitter;
import org.opentripplanner.graph_builder.linking.StreetSplitter;
import org.opentripplanner.graph_builder.services.GraphBuilderModule;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
* {@link org.opentripplanner.graph_builder.services.GraphBuilderModule} plugin that links various objects
* in the graph to the street network. It should be run after both the transit network and street network are loaded.
Expand Down Expand Up @@ -44,7 +45,10 @@ public List<String> getPrerequisites() {
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
if(graph.hasStreets) {
LOG.info("Linking transit stops, bike rental stations, bike parking areas, and park-and-rides to graph . . .");
SimpleStreetSplitter linker = new SimpleStreetSplitter(graph);
if (graph.streetIndex == null) {
graph.index(new DefaultStreetVertexIndexFactory());
}
StreetSplitter linker = graph.streetIndex.getStreetSplitter();
linker.setAddExtraEdgesToAreas(this.addExtraEdgesToAreas);
linker.linkAllStationsToGraph();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import org.opentripplanner.routing.graph.Edge;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.graph.Vertex;
import org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl;
import org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory;
import org.opentripplanner.routing.services.StreetVertexIndexService;
import org.opentripplanner.routing.vertextype.TransitStop;
import org.opentripplanner.routing.vertextype.TransitStopStreetVertex;
import org.slf4j.Logger;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class TransitToTaggedStopsModule implements GraphBuilderModule {

private static final Logger LOG = LoggerFactory.getLogger(TransitToTaggedStopsModule.class);

StreetVertexIndexServiceImpl index;
StreetVertexIndexService index;
private double searchRadiusM = 250;
private double searchRadiusLat = SphericalDistanceLibrary.metersToDegrees(searchRadiusM);

Expand All @@ -52,7 +53,10 @@ public List<String> getPrerequisites() {
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
LOG.info("Linking transit stops to tagged bus stops...");

index = new StreetVertexIndexServiceImpl(graph);
if (graph.streetIndex == null) {
graph.index(new DefaultStreetVertexIndexFactory());
}
index = graph.streetIndex;

// iterate over a copy of vertex list because it will be modified
ArrayList<Vertex> vertices = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,13 @@
import javax.xml.bind.annotation.XmlTransient;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.opentripplanner.routing.vehicle_rental.RentalStation;
import org.opentripplanner.util.I18NString;
import org.opentripplanner.util.ResourceBundleSingleton;

public class BikeRentalStation implements Serializable, Cloneable {
public class BikeRentalStation extends RentalStation implements Serializable, Cloneable {
private static final long serialVersionUID = 8311460609708089384L;

@XmlAttribute
@JsonSerialize
public String id;
//Serialized in TranslatedBikeRentalStation
@XmlTransient
@JsonIgnore
public I18NString name;
@XmlAttribute
@JsonSerialize
public double x, y; //longitude, latitude
@XmlAttribute
@JsonSerialize
public int bikesAvailable = Integer.MAX_VALUE;
Expand All @@ -33,20 +24,10 @@ public class BikeRentalStation implements Serializable, Cloneable {
public int spacesAvailable = Integer.MAX_VALUE;
@XmlAttribute
@JsonSerialize
public boolean allowDropoff = true;
@XmlAttribute
@JsonSerialize
public boolean isFloatingBike = false;
@XmlAttribute
@JsonSerialize
public boolean isCarStation = false;

/**
* List of compatible network names. Null (default) to be compatible with all.
*/
@XmlAttribute
@JsonSerialize
public Set<String> networks = null;

/**
* Whether this station is static (usually coming from OSM data) or a real-time source. If no real-time data, users should take
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ the License, or (at your option) any later version.

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.opentripplanner.routing.vehicle_rental.RentalStation;
import org.opentripplanner.util.I18NString;
import org.opentripplanner.util.ResourceBundleSingleton;

Expand All @@ -24,25 +25,13 @@ the License, or (at your option) any later version.
import java.util.Locale;
import java.util.Set;

public class CarRentalStation implements Serializable, Cloneable {
public class CarRentalStation extends RentalStation implements Serializable, Cloneable {
private static final long serialVersionUID = 8311460609708089384L;

@XmlAttribute
@JsonSerialize
public String id;

@XmlTransient
@JsonIgnore
public String licensePlate;

@XmlTransient
@JsonIgnore
public I18NString name;

@XmlAttribute
@JsonSerialize
public double x, y; //longitude, latitude

@XmlAttribute
@JsonSerialize
public int carsAvailable = Integer.MAX_VALUE;
Expand All @@ -51,25 +40,10 @@ public class CarRentalStation implements Serializable, Cloneable {
@JsonSerialize
public int spacesAvailable = Integer.MAX_VALUE;

@XmlAttribute
@JsonSerialize
public boolean allowDropoff = true;

@XmlAttribute
@JsonSerialize
public boolean allowPickup = true;

@XmlAttribute
@JsonSerialize
public boolean isFloatingCar = false;

/**
* List of compatible network names. Null (default) to be compatible with all.
*/
@XmlAttribute
@JsonSerialize
public Set<String> networks = null;

/**
* Fuel type of the car.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private Set<StreetEdge> overlappingStreetEdges(Vertex u, Vertex v) {
for (Edge e : Iterables.concat(u.getIncoming(), u.getOutgoing())) {
uIds.add(e.getId());
}

// Intesection of edge IDs between u and v.
uIds.retainAll(vIds);
Set<Integer> overlappingIds = uIds;
Expand Down Expand Up @@ -229,7 +229,6 @@ private RoutingContext(RoutingRequest routingRequest, Graph graph, Vertex from,
else
this.streetSpeedSnapshot = null;


Edge fromBackEdge = null;
Edge toBackEdge = null;
if (findPlaces) {
Expand Down Expand Up @@ -290,7 +289,7 @@ private RoutingContext(RoutingRequest routingRequest, Graph graph, Vertex from,
makePartialEdgeAlong(pse, fromStreetVertex, toStreetVertex);
}
}

if (opt.startingTransitStopId != null) {
Stop stop = graph.index.stopForId.get(opt.startingTransitStopId);
TransitStop tstop = graph.index.stopVertexForStop.get(stop);
Expand Down Expand Up @@ -399,10 +398,12 @@ public boolean isWheelchairAccessible(Vertex v) {
}

/**
* Tear down this routing context, removing any temporary edges.
* Tear down this routing context, removing any temporary edges from
* the "permanent" graph objects. This enables all temporary objects
* for garbage collection.
*/
public void destroy() {
if (origin instanceof TemporaryVertex) ((TemporaryVertex) origin).dispose();
if (target instanceof TemporaryVertex) ((TemporaryVertex) target).dispose();
TemporaryVertex.dispose(fromVertex);
TemporaryVertex.dispose(toVertex);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.opentripplanner.routing.core;

import com.google.common.base.Objects;
import org.opentripplanner.api.common.RoutingResource;
import org.opentripplanner.graph_builder.linking.StreetSplitter;
import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.model.Route;
import org.opentripplanner.api.parameter.QualifiedModeSet;
import org.opentripplanner.common.MavenVersion;
import org.opentripplanner.common.model.GenericLocation;
Expand All @@ -26,6 +28,7 @@
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
Expand Down Expand Up @@ -1457,7 +1460,7 @@ public ShortestPathTree getNewShortestPathTree() {
*
* But throws TrivialPathException if same edge is split in origin/destination search.
*
* used in {@link org.opentripplanner.graph_builder.linking.SimpleStreetSplitter} in {@link org.opentripplanner.graph_builder.linking.SimpleStreetSplitter#link(Vertex, StreetEdge, double, RoutingRequest)}
* used in {@link StreetSplitter} in {@link StreetSplitter#link(Vertex, StreetEdge, double, RoutingRequest)}
* @param edge
*/
public void canSplitEdge(StreetEdge edge) {
Expand Down
Loading

0 comments on commit c9a95d9

Please sign in to comment.