This repository has been archived by the owner on Mar 3, 2025. It is now read-only.
forked from HSLdevcom/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Use decorators to apply time-penalty in Raptor
- Loading branch information
Showing
7 changed files
with
202 additions
and
3 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
src/main/java/org/opentripplanner/raptor/api/model/AbstractAccessEgressDelegator.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package org.opentripplanner.raptor.api.model; | ||
|
||
import java.util.Objects; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Using delegation to extend the {@link RaptorAccessEgress} functionality is common, so we provide | ||
* a base delegation implementation here. This implementation delegates all operations to the | ||
* delegate. | ||
*/ | ||
public class AbstractAccessEgressDelegator implements RaptorAccessEgress { | ||
|
||
private final RaptorAccessEgress delegate; | ||
|
||
public AbstractAccessEgressDelegator(RaptorAccessEgress delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
protected RaptorAccessEgress delegate() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public int stop() { | ||
return delegate.stop(); | ||
} | ||
|
||
@Override | ||
public int c1() { | ||
return delegate.c1(); | ||
} | ||
|
||
@Override | ||
public int durationInSeconds() { | ||
return delegate.durationInSeconds(); | ||
} | ||
|
||
@Override | ||
public int timePenalty() { | ||
return delegate.timePenalty(); | ||
} | ||
|
||
@Override | ||
public int earliestDepartureTime(int requestedDepartureTime) { | ||
return delegate.earliestDepartureTime(requestedDepartureTime); | ||
} | ||
|
||
@Override | ||
public int latestArrivalTime(int requestedArrivalTime) { | ||
return delegate.latestArrivalTime(requestedArrivalTime); | ||
} | ||
|
||
@Override | ||
public boolean hasOpeningHours() { | ||
return delegate.hasOpeningHours(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String openingHoursToString() { | ||
return delegate.openingHoursToString(); | ||
} | ||
|
||
@Override | ||
public int numberOfRides() { | ||
return delegate.numberOfRides(); | ||
} | ||
|
||
@Override | ||
public boolean hasRides() { | ||
return delegate.hasRides(); | ||
} | ||
|
||
@Override | ||
public boolean stopReachedOnBoard() { | ||
return delegate.stopReachedOnBoard(); | ||
} | ||
|
||
@Override | ||
public boolean stopReachedByWalking() { | ||
return delegate.stopReachedByWalking(); | ||
} | ||
|
||
@Override | ||
public boolean isFree() { | ||
return delegate.isFree(); | ||
} | ||
|
||
@Override | ||
public String defaultToString() { | ||
return delegate.defaultToString(); | ||
} | ||
|
||
@Override | ||
public String asString(boolean includeStop, boolean includeCost, @Nullable String summary) { | ||
return delegate.asString(includeStop, includeCost, summary); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
AbstractAccessEgressDelegator that = (AbstractAccessEgressDelegator) o; | ||
return Objects.equals(delegate, that.delegate); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(delegate); | ||
} | ||
} |
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
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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/opentripplanner/raptor/rangeraptor/transit/AccessWithPenalty.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.opentripplanner.raptor.rangeraptor.transit; | ||
|
||
import org.opentripplanner.raptor.api.model.AbstractAccessEgressDelegator; | ||
import org.opentripplanner.raptor.api.model.RaptorAccessEgress; | ||
|
||
/** | ||
* This decorator will add the time penalty to the duration of the access and adjust the | ||
* `requestedDepartureTime` when time-shifting the access according to opening-hours. | ||
* | ||
* TODO PEN - Write more | ||
*/ | ||
public class AccessWithPenalty extends AbstractAccessEgressDelegator { | ||
|
||
public AccessWithPenalty(RaptorAccessEgress delegate) { | ||
super(delegate); | ||
} | ||
|
||
@Override | ||
public int durationInSeconds() { | ||
return delegate().durationInSeconds() + delegate().timePenalty(); | ||
} | ||
|
||
@Override | ||
public int earliestDepartureTime(int requestedDepartureTime) { | ||
return delegate().earliestDepartureTime(requestedDepartureTime + delegate().timePenalty()); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/opentripplanner/raptor/rangeraptor/transit/EgressWithPenalty.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.opentripplanner.raptor.rangeraptor.transit; | ||
|
||
import org.opentripplanner.raptor.api.model.AbstractAccessEgressDelegator; | ||
import org.opentripplanner.raptor.api.model.RaptorAccessEgress; | ||
|
||
/** | ||
* This decorator will add the time penalty to the duration of the egress and adjust the | ||
* `requestedDepartureTime` when time-shifting the egress according to opening-hours. | ||
* | ||
* TODO PEN - Write more | ||
*/ | ||
public class EgressWithPenalty extends AbstractAccessEgressDelegator { | ||
|
||
public EgressWithPenalty(RaptorAccessEgress delegate) { | ||
super(delegate); | ||
} | ||
|
||
@Override | ||
public int durationInSeconds() { | ||
return delegate().durationInSeconds() + delegate().timePenalty(); | ||
} | ||
|
||
@Override | ||
public int latestArrivalTime(int requestedArrivalTime) { | ||
return delegate().latestArrivalTime(requestedArrivalTime - delegate().timePenalty()); | ||
} | ||
} |
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