diff --git a/src/main/java/org/opentripplanner/graph_builder/module/FlexDirectTransferGenerator.java b/src/main/java/org/opentripplanner/graph_builder/module/FlexDirectTransferGenerator.java index 28eaedb5de1..082e7249701 100644 --- a/src/main/java/org/opentripplanner/graph_builder/module/FlexDirectTransferGenerator.java +++ b/src/main/java/org/opentripplanner/graph_builder/module/FlexDirectTransferGenerator.java @@ -19,7 +19,6 @@ the License, or (at your option) any later version. import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.linearref.LengthIndexedLine; -import org.apache.commons.math3.util.Pair; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.gtfs.model.Stop; import org.opentripplanner.api.resource.CoordinateArrayListSequence; @@ -40,8 +39,7 @@ the License, or (at your option) any later version. import org.opentripplanner.routing.edgetype.PreBoardEdge; import org.opentripplanner.routing.edgetype.SimpleTransfer; import org.opentripplanner.routing.edgetype.StreetEdge; -import org.opentripplanner.routing.edgetype.TransitBoardAlight; -import org.opentripplanner.routing.edgetype.TransitBoardAlightAtFlex; +import org.opentripplanner.routing.edgetype.flex.FlexTransitBoardAlight; import org.opentripplanner.routing.edgetype.TripPattern; import org.opentripplanner.routing.graph.Edge; import org.opentripplanner.routing.graph.Graph; @@ -50,7 +48,6 @@ the License, or (at your option) any later version. import org.opentripplanner.routing.spt.GraphPath; import org.opentripplanner.routing.vertextype.PatternArriveVertex; import org.opentripplanner.routing.vertextype.PatternDepartVertex; -import org.opentripplanner.routing.vertextype.PatternStopVertex; import org.opentripplanner.routing.vertextype.TransitStop; import org.opentripplanner.routing.vertextype.TransitStopArrive; import org.opentripplanner.routing.vertextype.TransitStopDepart; @@ -64,7 +61,6 @@ the License, or (at your option) any later version. import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; /** @@ -274,7 +270,7 @@ private TransitStop newStopOnPartialHop(Graph graph, PatternHop hop, Vertex vert PatternArriveVertex patternArriveVertex = new PatternArriveVertex(graph, hop.getPattern(), hop.getStopIndex(), stop); TransitStopArrive transitStopArrive = new TransitStopArrive(graph, stop, transferStop); PartialPatternHop startHop = PartialPatternHop.startHop(hop, patternArriveVertex, stop); - new TransitBoardAlightAtFlex(patternArriveVertex, transitStopArrive, hop.getStopIndex(), hop.getPattern().mode, startHop.getPercentageOfHop()); + new FlexTransitBoardAlight(patternArriveVertex, transitStopArrive, hop.getStopIndex() + 1, startHop); new PreAlightEdge(transitStopArrive, transferStop); // stop -> hop @@ -282,7 +278,7 @@ private TransitStop newStopOnPartialHop(Graph graph, PatternHop hop, Vertex vert PatternDepartVertex patternDepartVertex = new PatternDepartVertex(graph, hop.getPattern(), hop.getStopIndex(), stop); new PreBoardEdge(transferStop, transitStopDepart); PartialPatternHop endHop = PartialPatternHop.endHop(hop, patternDepartVertex, stop); - new TransitBoardAlightAtFlex(transitStopDepart, patternDepartVertex, hop.getStopIndex(), hop.getPattern().mode, endHop.getPercentageOfHop()); + new FlexTransitBoardAlight(transitStopDepart, patternDepartVertex, hop.getStopIndex(), endHop); return transferStop; } diff --git a/src/main/java/org/opentripplanner/routing/edgetype/TransitBoardAlightAtFlex.java b/src/main/java/org/opentripplanner/routing/edgetype/TransitBoardAlightAtFlex.java deleted file mode 100644 index ac36749808c..00000000000 --- a/src/main/java/org/opentripplanner/routing/edgetype/TransitBoardAlightAtFlex.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.opentripplanner.routing.edgetype; - -import org.opentripplanner.routing.core.RoutingRequest; -import org.opentripplanner.routing.core.ServiceDay; -import org.opentripplanner.routing.core.State; -import org.opentripplanner.routing.core.TraverseMode; -import org.opentripplanner.routing.trippattern.TripTimes; -import org.opentripplanner.routing.vertextype.PatternStopVertex; -import org.opentripplanner.routing.vertextype.TransitStopArrive; -import org.opentripplanner.routing.vertextype.TransitStopDepart; - -/** - * Created by sjacobs on 2/17/17. - */ -public class TransitBoardAlightAtFlex extends TransitBoardAlight { - - private final double percentageOfHop; - - /** Boarding constructor (TransitStopDepart --> PatternStopVertex) */ - public TransitBoardAlightAtFlex (TransitStopDepart fromStopVertex, PatternStopVertex toPatternVertex, - int stopIndex, TraverseMode mode, double percentageOfHop) { - super(fromStopVertex, toPatternVertex, stopIndex, mode); - this.percentageOfHop = 1 - percentageOfHop; - } - - /** Alighting constructor (PatternStopVertex --> TransitStopArrive) */ - public TransitBoardAlightAtFlex (PatternStopVertex fromPatternStop, TransitStopArrive toStationVertex, - int stopIndex, TraverseMode mode, double percentageOfHop) { - super(fromPatternStop, toStationVertex, stopIndex, mode); - this.percentageOfHop = percentageOfHop; - } - - @Override - public TripTimes getNextTrip(State s0, ServiceDay sd) { - RoutingRequest options = s0.getOptions(); - Timetable timetable = getPattern().getUpdatedTimetable(options, sd); - TripTimes tripTimes = timetable.getNextTrip(s0, sd, getStopIndex(), boarding, percentageOfHop); - return tripTimes; - } - - @Override - public int calculateWait(State s0, ServiceDay sd, TripTimes tripTimes) { - int stopIndex = getStopIndex(); - int adjustment = (int) (percentageOfHop * (tripTimes.getRunningTime(stopIndex))); - // we need to fudge this by two seconds so that we can optimize later on. - return boarding ? - (int)(sd.time(tripTimes.getDepartureTime(stopIndex) + adjustment) - s0.getTimeSeconds()) + 2: - (int)(s0.getTimeSeconds() - sd.time(tripTimes.getArrivalTime(stopIndex) + adjustment)); - } - - @Override - public String toString() { - return "TransitBoardAlightAtFlex(" + - (boarding ? "boarding " : "alighting ") + - getFromVertex() + " to " + getToVertex() + ")"; - } -} diff --git a/src/main/java/org/opentripplanner/routing/edgetype/flex/FlexTransitBoardAlight.java b/src/main/java/org/opentripplanner/routing/edgetype/flex/FlexTransitBoardAlight.java new file mode 100644 index 00000000000..cbb21022d70 --- /dev/null +++ b/src/main/java/org/opentripplanner/routing/edgetype/flex/FlexTransitBoardAlight.java @@ -0,0 +1,88 @@ +/* This program is free software: you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License + as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +package org.opentripplanner.routing.edgetype.flex; + +import org.onebusaway.gtfs.model.Trip; +import org.opentripplanner.routing.core.RoutingRequest; +import org.opentripplanner.routing.core.ServiceDay; +import org.opentripplanner.routing.core.State; +import org.opentripplanner.routing.edgetype.PartialPatternHop; +import org.opentripplanner.routing.edgetype.Timetable; +import org.opentripplanner.routing.edgetype.TransitBoardAlight; +import org.opentripplanner.routing.trippattern.TripTimes; +import org.opentripplanner.routing.vertextype.PatternStopVertex; +import org.opentripplanner.routing.vertextype.TransitStopArrive; +import org.opentripplanner.routing.vertextype.TransitStopDepart; + +public class FlexTransitBoardAlight extends TransitBoardAlight { + + // normalized to [0, 1] + private double startIndex; + private double endIndex; + private PartialPatternHop hop; + + public FlexTransitBoardAlight(TransitStopDepart fromStopVertex, PatternStopVertex toPatternVertex, + int stopIndex, PartialPatternHop hop) { + super(fromStopVertex, toPatternVertex, stopIndex, hop.getMode()); + setIndices(hop); + } + + public FlexTransitBoardAlight(PatternStopVertex fromPatternStop, TransitStopArrive toStationVertex, + int stopIndex, PartialPatternHop hop) { + super(fromPatternStop, toStationVertex, stopIndex, hop.getMode()); + setIndices(hop); + } + + private void setIndices(PartialPatternHop hop) { + this.startIndex = hop.getStartIndex() / hop.getOriginalHopLength(); + this.endIndex = hop.getEndIndex() / hop.getOriginalHopLength(); + this.hop = hop; + } + + + @Override + public TripTimes getNextTrip(State s0, ServiceDay sd) { + double adjustment = boarding ? startIndex : -1 * (1 - endIndex); + RoutingRequest options = s0.getOptions(); + Timetable timetable = getPattern().getUpdatedTimetable(options, sd); + TripTimes tripTimes = timetable.getNextTrip(s0, sd, getStopIndex(), boarding, adjustment); + return tripTimes; + } + + @Override + public int calculateWait(State s0, ServiceDay sd, TripTimes tripTimes) { + int stopIndex = getStopIndex(); + if (boarding) { + // we need to fudge this by two seconds so that we can optimize later on. + int offset = (int) Math.round(startIndex * (tripTimes.getRunningTime(stopIndex))); + return (int)(sd.time(tripTimes.getDepartureTime(stopIndex) + offset) - s0.getTimeSeconds()); + } + else { + int offset = (int) Math.round((1-endIndex) * (tripTimes.getRunningTime(stopIndex - 1))); + return (int)(s0.getTimeSeconds() - sd.time(tripTimes.getArrivalTime(stopIndex) - offset)); + } + } + + @Override + public long getPenaltyWeight(State s0, RoutingRequest options, Trip trip) { + return super.getPenaltyWeight(s0, options, trip) + options.flagStopExtraPenalty; + } + + @Override + public String toString() { + return "FlexTransitBoardAlight(" + + (boarding ? "boarding " : "alighting ") + + getFromVertex() + " to " + getToVertex() + ")"; + } +} diff --git a/src/main/java/org/opentripplanner/routing/edgetype/flex/TemporaryPartialPatternHop.java b/src/main/java/org/opentripplanner/routing/edgetype/flex/TemporaryPartialPatternHop.java index 0ac94532603..7bf9b807464 100644 --- a/src/main/java/org/opentripplanner/routing/edgetype/flex/TemporaryPartialPatternHop.java +++ b/src/main/java/org/opentripplanner/routing/edgetype/flex/TemporaryPartialPatternHop.java @@ -1,3 +1,16 @@ +/* This program is free software: you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License + as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + package org.opentripplanner.routing.edgetype.flex; import com.vividsolutions.jts.linearref.LengthIndexedLine; @@ -11,10 +24,6 @@ import org.opentripplanner.routing.vertextype.PatternDepartVertex; import org.opentripplanner.routing.vertextype.PatternStopVertex; -/** - * Created by simon on 6/13/17. - */ -// this may replace TemporaryPatternHop. the problem I want to solve is multiple possible hops. public class TemporaryPartialPatternHop extends PartialPatternHop implements TemporaryEdge { public TemporaryPartialPatternHop(PatternHop hop, PatternStopVertex from, PatternStopVertex to, Stop fromStop, Stop toStop, RoutingContext rctx, double startIndex, double endIndex) { super(hop, from, to, fromStop, toStop, startIndex, endIndex); @@ -46,10 +55,11 @@ public void dispose() { tov.removeIncoming(this); } - // is this hop too not-different to care about? for now lets say should be > 20 m shorter than original hop + // is this hop too not-different to care about? for now lets say should be > 50 m shorter than original hop public boolean isTrivial() { - double length = SphericalDistanceLibrary.fastLength(getGeometry()); - double parentLength = SphericalDistanceLibrary.fastLength(getOriginalHop().getGeometry()); - return length + 20 >= parentLength; + double length = SphericalDistanceLibrary.fastLength(getGeometry()); + double parentLength = SphericalDistanceLibrary.fastLength(getOriginalHop().getGeometry()); + return length + 50 >= parentLength; } + } diff --git a/src/main/java/org/opentripplanner/routing/edgetype/flex/TemporaryTransitBoardAlight.java b/src/main/java/org/opentripplanner/routing/edgetype/flex/TemporaryTransitBoardAlight.java index a0dad956a9e..b5569d28513 100644 --- a/src/main/java/org/opentripplanner/routing/edgetype/flex/TemporaryTransitBoardAlight.java +++ b/src/main/java/org/opentripplanner/routing/edgetype/flex/TemporaryTransitBoardAlight.java @@ -1,44 +1,34 @@ +/* This program is free software: you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License + as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + package org.opentripplanner.routing.edgetype.flex; -import org.onebusaway.gtfs.model.Trip; -import org.opentripplanner.routing.core.RoutingRequest; -import org.opentripplanner.routing.core.ServiceDay; -import org.opentripplanner.routing.core.State; import org.opentripplanner.routing.edgetype.PartialPatternHop; import org.opentripplanner.routing.edgetype.TemporaryEdge; -import org.opentripplanner.routing.edgetype.Timetable; -import org.opentripplanner.routing.edgetype.TransitBoardAlight; -import org.opentripplanner.routing.trippattern.TripTimes; import org.opentripplanner.routing.vertextype.PatternStopVertex; import org.opentripplanner.routing.vertextype.TransitStopArrive; import org.opentripplanner.routing.vertextype.TransitStopDepart; -/** - * Created by dbenoff on 2/10/17. - */ -public class TemporaryTransitBoardAlight extends TransitBoardAlight implements TemporaryEdge { - - // normalized to [0, 1] - private double startIndex; - private double endIndex; - private PartialPatternHop hop; +public class TemporaryTransitBoardAlight extends FlexTransitBoardAlight implements TemporaryEdge { public TemporaryTransitBoardAlight(TransitStopDepart fromStopVertex, PatternStopVertex toPatternVertex, int stopIndex, PartialPatternHop hop) { - super(fromStopVertex, toPatternVertex, stopIndex, hop.getMode()); - setIndices(hop); + super(fromStopVertex, toPatternVertex, stopIndex, hop); } public TemporaryTransitBoardAlight(PatternStopVertex fromPatternStop, TransitStopArrive toStationVertex, int stopIndex, PartialPatternHop hop) { - super(fromPatternStop, toStationVertex, stopIndex, hop.getMode()); - setIndices(hop); - } - - private void setIndices(PartialPatternHop hop) { - this.startIndex = hop.getStartIndex() / hop.getOriginalHopLength(); - this.endIndex = hop.getEndIndex() / hop.getOriginalHopLength(); - this.hop = hop; + super(fromPatternStop, toStationVertex, stopIndex, hop); } @Override @@ -46,33 +36,4 @@ public void dispose() { fromv.removeOutgoing(this); tov.removeIncoming(this); } - - - @Override - public TripTimes getNextTrip(State s0, ServiceDay sd) { - double adjustment = boarding ? startIndex : -1 * (1 - endIndex); - RoutingRequest options = s0.getOptions(); - Timetable timetable = getPattern().getUpdatedTimetable(options, sd); - TripTimes tripTimes = timetable.getNextTrip(s0, sd, getStopIndex(), boarding, adjustment); - return tripTimes; - } - - @Override - public int calculateWait(State s0, ServiceDay sd, TripTimes tripTimes) { - int stopIndex = getStopIndex(); - if (boarding) { - // we need to fudge this by two seconds so that we can optimize later on. - int offset = (int) Math.round(startIndex * (tripTimes.getRunningTime(stopIndex))); - return (int)(sd.time(tripTimes.getDepartureTime(stopIndex) + offset) - s0.getTimeSeconds()); - } - else { - int offset = (int) Math.round((1-endIndex) * (tripTimes.getRunningTime(stopIndex - 1))); - return (int)(s0.getTimeSeconds() - sd.time(tripTimes.getArrivalTime(stopIndex) - offset)); - } - } - - @Override - public long getPenaltyWeight(State s0, RoutingRequest options, Trip trip) { - return super.getPenaltyWeight(s0, options, trip) + options.flagStopExtraPenalty; - } }