Skip to content

Commit

Permalink
fix TransitBoardAlight class hierarchy, add some license headers
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjacobs committed Jul 2, 2017
1 parent 40d6dfd commit e27bd2e
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 127 deletions.
Expand Up @@ -19,7 +19,6 @@ the License, or (at your option) any later version.
import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.linearref.LengthIndexedLine; import com.vividsolutions.jts.linearref.LengthIndexedLine;
import org.apache.commons.math3.util.Pair;
import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.gtfs.model.AgencyAndId;
import org.onebusaway.gtfs.model.Stop; import org.onebusaway.gtfs.model.Stop;
import org.opentripplanner.api.resource.CoordinateArrayListSequence; import org.opentripplanner.api.resource.CoordinateArrayListSequence;
Expand All @@ -40,8 +39,7 @@ the License, or (at your option) any later version.
import org.opentripplanner.routing.edgetype.PreBoardEdge; import org.opentripplanner.routing.edgetype.PreBoardEdge;
import org.opentripplanner.routing.edgetype.SimpleTransfer; import org.opentripplanner.routing.edgetype.SimpleTransfer;
import org.opentripplanner.routing.edgetype.StreetEdge; import org.opentripplanner.routing.edgetype.StreetEdge;
import org.opentripplanner.routing.edgetype.TransitBoardAlight; import org.opentripplanner.routing.edgetype.flex.FlexTransitBoardAlight;
import org.opentripplanner.routing.edgetype.TransitBoardAlightAtFlex;
import org.opentripplanner.routing.edgetype.TripPattern; import org.opentripplanner.routing.edgetype.TripPattern;
import org.opentripplanner.routing.graph.Edge; import org.opentripplanner.routing.graph.Edge;
import org.opentripplanner.routing.graph.Graph; import org.opentripplanner.routing.graph.Graph;
Expand All @@ -50,7 +48,6 @@ the License, or (at your option) any later version.
import org.opentripplanner.routing.spt.GraphPath; import org.opentripplanner.routing.spt.GraphPath;
import org.opentripplanner.routing.vertextype.PatternArriveVertex; import org.opentripplanner.routing.vertextype.PatternArriveVertex;
import org.opentripplanner.routing.vertextype.PatternDepartVertex; import org.opentripplanner.routing.vertextype.PatternDepartVertex;
import org.opentripplanner.routing.vertextype.PatternStopVertex;
import org.opentripplanner.routing.vertextype.TransitStop; import org.opentripplanner.routing.vertextype.TransitStop;
import org.opentripplanner.routing.vertextype.TransitStopArrive; import org.opentripplanner.routing.vertextype.TransitStopArrive;
import org.opentripplanner.routing.vertextype.TransitStopDepart; import org.opentripplanner.routing.vertextype.TransitStopDepart;
Expand All @@ -64,7 +61,6 @@ the License, or (at your option) any later version.
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;


/** /**
Expand Down Expand Up @@ -274,15 +270,15 @@ private TransitStop newStopOnPartialHop(Graph graph, PatternHop hop, Vertex vert
PatternArriveVertex patternArriveVertex = new PatternArriveVertex(graph, hop.getPattern(), hop.getStopIndex(), stop); PatternArriveVertex patternArriveVertex = new PatternArriveVertex(graph, hop.getPattern(), hop.getStopIndex(), stop);
TransitStopArrive transitStopArrive = new TransitStopArrive(graph, stop, transferStop); TransitStopArrive transitStopArrive = new TransitStopArrive(graph, stop, transferStop);
PartialPatternHop startHop = PartialPatternHop.startHop(hop, patternArriveVertex, stop); 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); new PreAlightEdge(transitStopArrive, transferStop);


// stop -> hop // stop -> hop
TransitStopDepart transitStopDepart = new TransitStopDepart(graph, stop, transferStop); TransitStopDepart transitStopDepart = new TransitStopDepart(graph, stop, transferStop);
PatternDepartVertex patternDepartVertex = new PatternDepartVertex(graph, hop.getPattern(), hop.getStopIndex(), stop); PatternDepartVertex patternDepartVertex = new PatternDepartVertex(graph, hop.getPattern(), hop.getStopIndex(), stop);
new PreBoardEdge(transferStop, transitStopDepart); new PreBoardEdge(transferStop, transitStopDepart);
PartialPatternHop endHop = PartialPatternHop.endHop(hop, patternDepartVertex, stop); 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; return transferStop;
} }
Expand Down

This file was deleted.

@@ -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() + ")";
}
}
@@ -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 <http://www.gnu.org/licenses/>. */

package org.opentripplanner.routing.edgetype.flex; package org.opentripplanner.routing.edgetype.flex;


import com.vividsolutions.jts.linearref.LengthIndexedLine; import com.vividsolutions.jts.linearref.LengthIndexedLine;
Expand All @@ -11,10 +24,6 @@
import org.opentripplanner.routing.vertextype.PatternDepartVertex; import org.opentripplanner.routing.vertextype.PatternDepartVertex;
import org.opentripplanner.routing.vertextype.PatternStopVertex; 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 class TemporaryPartialPatternHop extends PartialPatternHop implements TemporaryEdge {
public TemporaryPartialPatternHop(PatternHop hop, PatternStopVertex from, PatternStopVertex to, Stop fromStop, Stop toStop, RoutingContext rctx, double startIndex, double endIndex) { 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); super(hop, from, to, fromStop, toStop, startIndex, endIndex);
Expand Down Expand Up @@ -46,10 +55,11 @@ public void dispose() {
tov.removeIncoming(this); 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() { public boolean isTrivial() {
double length = SphericalDistanceLibrary.fastLength(getGeometry()); double length = SphericalDistanceLibrary.fastLength(getGeometry());
double parentLength = SphericalDistanceLibrary.fastLength(getOriginalHop().getGeometry()); double parentLength = SphericalDistanceLibrary.fastLength(getOriginalHop().getGeometry());
return length + 20 >= parentLength; return length + 50 >= parentLength;
} }

} }
@@ -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;
}
} }

0 comments on commit e27bd2e

Please sign in to comment.