Skip to content

Commit

Permalink
Change continuous pickup/dropoff to continuous stops
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjacobs committed Jun 27, 2017
1 parent 03ca5b6 commit d4d8b41
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 37 deletions.
Expand Up @@ -117,7 +117,7 @@ public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
}

// for each hop, find nearby stops and hops. create transfers.
if (hop.getContinuousDropoff() > 0 || hop.getContinuousPickup() > 0) {
if (hop.hasFlagStopService()) {
if (++nLinkableHops % 1000 == 0) {
LOG.info("Linked {} hops, skipped {} hops", nLinkableHops, nSkippedHops);
}
Expand Down Expand Up @@ -194,7 +194,7 @@ public void visitVertex(State state) {
if (flexPatternsToIgnore.get(hop.getPattern()).contains(h.getPattern())) {
continue;
}
if (h.getContinuousPickup() > 0 || h.getContinuousDropoff() > 0) {
if (h.hasFlagStopService()) {
TripPattern pattern = h.getPattern();
TransferPointAtDistance pt = new TransferPointAtDistance(hop, state, h, state.getVertex());
closestTransferPointForTripPattern.put(pattern, pt);
Expand Down
25 changes: 8 additions & 17 deletions src/main/java/org/opentripplanner/model/StopPattern.java
Expand Up @@ -7,7 +7,6 @@
import com.google.common.hash.HashCode;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hasher;
import com.google.common.hash.Hashing;
import org.onebusaway.gtfs.model.Stop;
import org.onebusaway.gtfs.model.StopTime;
import org.slf4j.Logger;
Expand Down Expand Up @@ -52,17 +51,15 @@ public class StopPattern implements Serializable {
public final Stop[] stops;
public final int[] pickups;
public final int[] dropoffs;
public final int[] continuousPickups;
public final int[] continuousDropoffs;
public final int[] continuousStops;

public boolean equals(Object other) {
if (other instanceof StopPattern) {
StopPattern that = (StopPattern) other;
return Arrays.equals(this.stops, that.stops) &&
Arrays.equals(this.pickups, that.pickups) &&
Arrays.equals(this.dropoffs, that.dropoffs) &&
Arrays.equals(this.continuousPickups, that.continuousPickups) &&
Arrays.equals(this.continuousDropoffs, that.continuousDropoffs);
Arrays.equals(this.continuousStops, that.continuousStops);
} else {
return false;
}
Expand All @@ -76,9 +73,7 @@ public int hashCode() {
hash *= 31;
hash += Arrays.hashCode(this.dropoffs);
hash *= 31;
hash += Arrays.hashCode(this.continuousPickups);
hash *= 31;
hash += Arrays.hashCode(this.continuousDropoffs);
hash += Arrays.hashCode(this.continuousStops);
return hash;
}

Expand All @@ -96,8 +91,7 @@ private StopPattern (int size) {
stops = new Stop[size];
pickups = new int[size];
dropoffs = new int[size];
continuousPickups = new int[size];
continuousDropoffs = new int[size];
continuousStops = new int[size];
}

/** Assumes that stopTimes are already sorted by time. */
Expand All @@ -112,13 +106,11 @@ public StopPattern (List<StopTime> stopTimes) {
pickups[i] = stopTime.getPickupType();
dropoffs[i] = stopTime.getDropOffType();

// continuous pickup/dropoff can be empty (-1), which means 0 for the first stoptime, and the previous value for subsequent stop times.
// continuous stops can be empty (-1), which means 0 for the first stoptime, and the previous value for subsequent stop times.
if (i == 0) {
continuousPickups[i] = stopTime.getContinuousPickup() == -1 ? 0 : stopTime.getContinuousPickup();
continuousDropoffs[i] = stopTime.getContinuousDropOff() == -1 ? 0 : stopTime.getContinuousDropOff();
continuousStops[i] = stopTime.getContinuousStops() == -1 ? 0 : stopTime.getContinuousStops();
} else {
continuousPickups[i] = stopTime.getContinuousPickup() == -1 ? continuousPickups[i-1] : stopTime.getContinuousPickup();
continuousDropoffs[i] = stopTime.getContinuousDropOff() == -1 ? continuousDropoffs[i-1] : stopTime.getContinuousDropOff();
continuousStops[i] = stopTime.getContinuousStops() == -1 ? continuousStops[i-1] : stopTime.getContinuousStops();
}
}
/*
Expand Down Expand Up @@ -163,8 +155,7 @@ public HashCode semanticHash(HashFunction hashFunction) {
for (int hop = 0; hop < size - 1; hop++) {
hasher.putInt(pickups[hop]);
hasher.putInt(dropoffs[hop + 1]);
hasher.putInt(continuousPickups[hop]);
hasher.putInt(continuousDropoffs[hop + 1]);
hasher.putInt(continuousStops[hop]);
}
return hasher.hash();
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public class PartialPatternHop extends PatternHop {
private PatternHop originalHop;

public PartialPatternHop(PatternHop hop, PatternStopVertex from, PatternStopVertex to, Stop fromStop, Stop toStop, double startIndex, double endIndex) {
super(from, to, fromStop, toStop, hop.getStopIndex(), hop.getContinuousPickup(), hop.getContinuousDropoff(), false);
super(from, to, fromStop, toStop, hop.getStopIndex(), hop.getContinuousStops(), false);
LengthIndexedLine line = new LengthIndexedLine(hop.getGeometry());
this.startIndex = startIndex;
this.endIndex = endIndex;
Expand Down
23 changes: 9 additions & 14 deletions src/main/java/org/opentripplanner/routing/edgetype/PatternHop.java
Expand Up @@ -41,28 +41,27 @@ public class PatternHop extends TablePatternEdge implements OnboardEdge, HopEdge

private Stop begin, end;

private int continuousPickup, continuousDropoff;
private int continuousStops;

public int stopIndex;

private LineString geometry = null;

protected PatternHop(PatternStopVertex from, PatternStopVertex to, Stop begin, Stop end, int stopIndex, int continuousPickup, int continuousDropoff, boolean setInPattern) {
protected PatternHop(PatternStopVertex from, PatternStopVertex to, Stop begin, Stop end, int stopIndex, int continuousStops, boolean setInPattern) {
super(from, to);
this.begin = begin;
this.end = end;
this.stopIndex = stopIndex;
if (setInPattern)
getPattern().setPatternHop(stopIndex, this);
this.continuousPickup = continuousPickup;
this.continuousDropoff = continuousDropoff;
this.continuousStops = continuousStops;
}

public PatternHop(PatternStopVertex from, PatternStopVertex to, Stop begin, Stop end, int stopIndex, int continuousPickup, int continuousDropoff) {
this(from, to, begin, end, stopIndex, continuousPickup, continuousDropoff, true);
public PatternHop(PatternStopVertex from, PatternStopVertex to, Stop begin, Stop end, int stopIndex, int continuousStops) {
this(from, to, begin, end, stopIndex, continuousStops, true);
}
public PatternHop(PatternStopVertex from, PatternStopVertex to, Stop begin, Stop end, int stopIndex) {
this(from, to, begin, end, stopIndex, 0, 0);
this(from, to, begin, end, stopIndex, 0);
}

// made more accurate
Expand Down Expand Up @@ -211,16 +210,12 @@ public int getStopIndex() {
return stopIndex;
}

public int getContinuousPickup() {
return continuousPickup;
}

public int getContinuousDropoff() {
return continuousDropoff;
public int getContinuousStops() {
return continuousStops;
}

public boolean hasFlagStopService() {
return continuousPickup > 0 || continuousDropoff > 0;
return continuousStops > 0;
}

}
Expand Up @@ -521,7 +521,7 @@ public void makePatternVerticesAndEdges(Graph graph, Map<Stop, ? extends Transit
}
pav1 = new PatternArriveVertex(graph, this, stop + 1);
arriveVertices[stop + 1] = pav1;
hopEdges[stop] = new PatternHop(pdv0, pav1, s0, s1, stop, stopPattern.continuousPickups[stop], stopPattern.continuousDropoffs[stop]);
hopEdges[stop] = new PatternHop(pdv0, pav1, s0, s1, stop, stopPattern.continuousStops[stop]);

/* Get the arrive and depart vertices for the current stop (not pattern stop). */
TransitStopDepart stopDepart = ((TransitStop) transitStops.get(s0)).departVertex;
Expand Down
Expand Up @@ -150,7 +150,7 @@ public void visitEnqueue(State state) {
List<PatternHop> patternHops = graph.index.getHopsForEdge(s.getBackEdge())
.stream()
.filter(e -> e.getPattern() == originalTripPattern)
.filter(e -> e.getContinuousDropoff() > 0)
.filter(PatternHop::hasFlagStopService)
.collect(Collectors.toList());

for(PatternHop originalPatternHop : patternHops) {
Expand Down Expand Up @@ -206,7 +206,7 @@ public void visitEnqueue(State state) {
List<PatternHop> patternHops = graph.index.getHopsForEdge(s.getBackEdge())
.stream()
.filter(e -> e.getPattern() == originalTripPattern)
.filter(e -> e.getContinuousPickup() > 0)
.filter(PatternHop::hasFlagStopService)
.collect(Collectors.toList());

for(PatternHop originalPatternHop : patternHops) {
Expand Down

0 comments on commit d4d8b41

Please sign in to comment.