Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn restriction when edges are split #262

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ public static void main(String[] commandArguments) {
LOG.info("Loading transit networks from: {}", dir);
TransportNetwork transportNetwork = TransportNetwork.read(new File(dir, "network.dat"));
transportNetwork.readOSM(new File(dir, "osm.mapdb"));
int invalidTrs = 0;
for (int i=0; i < transportNetwork.streetLayer.turnRestrictions.size(); i++) {
TurnRestriction tr = transportNetwork.streetLayer.turnRestrictions.get(i);
if (tr.viaEdges.length > 0) {
continue;
}
EdgeStore.Edge fromEdge = transportNetwork.streetLayer.edgeStore.getCursor(tr.fromEdge);
EdgeStore.Edge toEdge = transportNetwork.streetLayer.edgeStore.getCursor(tr.toEdge);

int viaVertex = fromEdge.getToVertex();
if(!transportNetwork.streetLayer.outgoingEdges.get(viaVertex).contains(tr.toEdge)) {
invalidTrs++;
LOG.info("TR:{} -> {}, {}", fromEdge.getOSMID(), toEdge.getOSMID(), tr);
}
}
LOG.info("Invalid trs:{}", invalidTrs);
run(transportNetwork);
} catch (Exception e) {
LOG.error("An error occurred during the reading or decoding of transit networks", e);
Expand Down Expand Up @@ -723,7 +739,6 @@ private static void run(TransportNetwork transportNetwork) {
edgeIdx++;
makeTurnEdge(transportNetwork, both, features, cursor, offsetBuilder,
distance, edgeIdx);

return true;
} catch (Exception e) {
response.status(500);
Expand Down Expand Up @@ -1068,6 +1083,15 @@ private static void makeTurnEdge(TransportNetwork transportNetwork, boolean both
for (int i=0; i < edge_restricion_idxs.size(); i++) {
int turnRestrictionIdx = edge_restricion_idxs.get(i);
TurnRestriction turnRestriction = transportNetwork.streetLayer.turnRestrictions.get(turnRestrictionIdx);
if (turnRestriction.viaEdges.length > 0) {
continue;
}
EdgeStore.Edge fromEdge = transportNetwork.streetLayer.edgeStore.getCursor(turnRestriction.fromEdge);

int viaVertex = fromEdge.getToVertex();
if(transportNetwork.streetLayer.outgoingEdges.get(viaVertex).contains(turnRestriction.toEdge)) {
continue;
}

//TurnRestriction.fromEdge isn't necessary correct
//If edge on which from is is splitted then fromEdge is different but isn't updated in TurnRestriction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.common.annotations.VisibleForTesting;

import java.io.File;

Expand Down Expand Up @@ -84,6 +85,11 @@ public class TNBuilderConfig {
*/
public final boolean fetchElevationUS;

/**
* If non accessible islands should be removed (default true)
*/
public final boolean removeIslands;

/** If specified, download NED elevation tiles from the given AWS S3 bucket. */
//public final S3BucketConfig elevationBucket;

Expand Down Expand Up @@ -144,6 +150,30 @@ public TNBuilderConfig() {
bikeRentalFile = null;
speeds = SpeedConfig.defaultConfig();
analysisFareCalculator = null;
removeIslands = true;
}

@VisibleForTesting
public TNBuilderConfig(boolean removeIslands) {
htmlAnnotations = false;
maxHtmlAnnotationsPerFile = 1000;
transit = true;
useTransfersTxt = false;
parentStopLinking = false;
stationTransfers = false;
subwayAccessTime = DEFAULT_SUBWAY_ACCESS_TIME;
streets = true;
embedRouterConfig = true;
areaVisibility = false;
matchBusRoutesToStreets = false;
fetchElevationUS = false;
staticBikeRental = false;
staticParkAndRide = true;
staticBikeParkAndRide = false;
bikeRentalFile = null;
speeds = SpeedConfig.defaultConfig();
analysisFareCalculator = null;
this.removeIslands = removeIslands;
}

public static TNBuilderConfig defaultConfig() {
Expand Down
45 changes: 41 additions & 4 deletions src/main/java/com/conveyal/r5/streets/EdgeStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,39 @@ public boolean isExtendOnlyCopy() {
}


/** Turn restrictions for turning _out of_ each edge */
/** Turn restrictions for turning _out of_ each edge
*
* FROM edges of all turn restrictions
* */
public TIntIntMultimap turnRestrictions;

/** Turn restrictions for turning _in of_ each edge */
/** Turn restrictions for turning _in of_ each edge in reverse search
*
* TO edges of NO TURN restrictions
* and TO edges of NO TURN restrictions remapped from ONLY TURN restrictions
*
* Also used when splitting edges
* */
public TIntIntMultimap turnRestrictionsReverse;

/**
* TO edges of ONLY TURN restrictions. (They aren't in turnRestrictionsReverse since reverse search
* doesn't support ONLY TURNS)
* Used only when splitting edges
* */
public TIntIntMultimap turnRestrictionsToEdges;

/**
* Here are FROM edges of NO TURN restriction which are remapped ONLY turn restrictions to NO turn restrictions
* Used only when splitting edges
*/
public TIntIntMultimap turnRestrictionsFromEdges;

/** Via edges to turn restrictions link. Used only when splitting edges
* FIXME: Can be probably transient since it's used only when building graph in getOrCreateVertexNear
* But I'm not sure what is with scenarios (materializeOne function)*/
public TIntIntMultimap turnRestrictionsVia;

public StreetLayer layer;

public static final transient EnumSet<EdgeFlag> PERMISSION_FLAGS = EnumSet
Expand All @@ -170,6 +197,9 @@ public EdgeStore (VertexStore vertexStore, StreetLayer layer, int initialSize) {
outAngles = new TByteArrayList(initialEdgePairs);
turnRestrictions = new TIntIntHashMultimap();
turnRestrictionsReverse = new TIntIntHashMultimap();
turnRestrictionsToEdges = new TIntIntHashMultimap();
turnRestrictionsFromEdges = new TIntIntHashMultimap();
turnRestrictionsVia = new TIntIntHashMultimap();
}

/**
Expand Down Expand Up @@ -1065,8 +1095,15 @@ public EdgeStore extendOnlyCopy(StreetLayer copiedStreetLayer) {
copy.inAngles = new TByteArrayList(inAngles);
copy.outAngles = new TByteArrayList(outAngles);
// We don't expect to add/change any turn restrictions.
copy.turnRestrictions = turnRestrictions;
copy.turnRestrictionsReverse = turnRestrictionsReverse;
copy.turnRestrictions = new TIntIntHashMultimap((TIntIntHashMultimap) turnRestrictions);
copy.turnRestrictionsReverse = new TIntIntHashMultimap(
(TIntIntHashMultimap) turnRestrictionsReverse);
copy.turnRestrictionsVia = new TIntIntHashMultimap(
(TIntIntHashMultimap) turnRestrictionsVia);
copy.turnRestrictionsToEdges = new TIntIntHashMultimap(
(TIntIntHashMultimap) turnRestrictionsToEdges);
copy.turnRestrictionsFromEdges = new TIntIntHashMultimap(
(TIntIntHashMultimap) turnRestrictionsFromEdges);
return copy;
}

Expand Down
Loading