Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix TransitBoardAlight class hierarchy, add some license headers
- Loading branch information
Showing
5 changed files
with
125 additions
and
127 deletions.
There are no files selected for viewing
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
57 changes: 0 additions & 57 deletions
57
src/main/java/org/opentripplanner/routing/edgetype/TransitBoardAlightAtFlex.java
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
src/main/java/org/opentripplanner/routing/edgetype/flex/FlexTransitBoardAlight.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. */ | |||
|
|||
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() + ")"; | |||
} | |||
} |
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
71 changes: 16 additions & 55 deletions
71
src/main/java/org/opentripplanner/routing/edgetype/flex/TemporaryTransitBoardAlight.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,78 +1,39 @@ | |||
/* 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 <http://www.gnu.org/licenses/>. */ | |||
|
|||
package org.opentripplanner.routing.edgetype.flex; | 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.PartialPatternHop; | ||
import org.opentripplanner.routing.edgetype.TemporaryEdge; | 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.PatternStopVertex; | ||
import org.opentripplanner.routing.vertextype.TransitStopArrive; | import org.opentripplanner.routing.vertextype.TransitStopArrive; | ||
import org.opentripplanner.routing.vertextype.TransitStopDepart; | import org.opentripplanner.routing.vertextype.TransitStopDepart; | ||
|
|
||
/** | public class TemporaryTransitBoardAlight extends FlexTransitBoardAlight implements TemporaryEdge { | ||
* 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 TemporaryTransitBoardAlight(TransitStopDepart fromStopVertex, PatternStopVertex toPatternVertex, | public TemporaryTransitBoardAlight(TransitStopDepart fromStopVertex, PatternStopVertex toPatternVertex, | ||
int stopIndex, PartialPatternHop hop) { | int stopIndex, PartialPatternHop hop) { | ||
super(fromStopVertex, toPatternVertex, stopIndex, hop.getMode()); | super(fromStopVertex, toPatternVertex, stopIndex, hop); | ||
setIndices(hop); | |||
} | } | ||
|
|
||
public TemporaryTransitBoardAlight(PatternStopVertex fromPatternStop, TransitStopArrive toStationVertex, | public TemporaryTransitBoardAlight(PatternStopVertex fromPatternStop, TransitStopArrive toStationVertex, | ||
int stopIndex, PartialPatternHop hop) { | int stopIndex, PartialPatternHop hop) { | ||
super(fromPatternStop, toStationVertex, stopIndex, hop.getMode()); | super(fromPatternStop, toStationVertex, stopIndex, hop); | ||
setIndices(hop); | |||
} | |||
|
|||
private void setIndices(PartialPatternHop hop) { | |||
this.startIndex = hop.getStartIndex() / hop.getOriginalHopLength(); | |||
this.endIndex = hop.getEndIndex() / hop.getOriginalHopLength(); | |||
this.hop = hop; | |||
} | } | ||
|
|
||
@Override | @Override | ||
public void dispose() { | public void dispose() { | ||
fromv.removeOutgoing(this); | fromv.removeOutgoing(this); | ||
tov.removeIncoming(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; | |||
} | |||
} | } |