Skip to content

Commit

Permalink
Added support for empty transfer allowance in R5RTransferAllowance;
Browse files Browse the repository at this point in the history
Setting fare type for first leg of trip.
  • Loading branch information
mvpsaraiva committed Jan 29, 2024
1 parent d8f699e commit a2fcdca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 9 additions & 0 deletions java-r5rcore/src/org/ipea/r5r/Fares/R5RTransferAllowance.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public R5RTransferAllowance(int fareType, int value, int number, int expirationT
this.fareType = fareType;
}

public R5RTransferAllowance() {
super();
this.fareType = -1;
}

public R5RTransferAllowance tightenExpiration(int maxClockTime){
// cap expiration time of transfer at max clock time of search, so that transfer slips that technically have more time
// remaining, but that time cannot be used within the constraints of this search, can be pruned.
Expand All @@ -34,7 +39,11 @@ public R5RTransferAllowance tightenExpiration(int maxClockTime){
* comparable.
*/
public boolean atLeastAsGoodForAllFutureRedemptions(R5RTransferAllowance other){
// for empty transfer allowances, this is always true
if (other.fareType == -1) return true;
// if this transfer allowance is for a different fare type, it is not comparable
if (fareType != other.fareType) return false;
// otherwise, compare value, expiration time, and number of transfers remaining
return value >= other.value && expirationTime >= other.expirationTime && number >= other.number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public FareBounds calculateFare(McRaptorSuboptimalPathProfileRouter.McRaptorStat
fareForState = getFullFareForRoute(currentPatternIndex);

previousPatternIndex = currentPatternIndex;
lastFareType = faresPerRoute[currentPatternIndex].getTypeIndex();
}

// subsequent legs
Expand Down Expand Up @@ -162,7 +163,7 @@ public FareBounds calculateFare(McRaptorSuboptimalPathProfileRouter.McRaptorStat

// fares are limited by the maxFare parameter
if (fareStructure.getFareCap() > 0) {
fareForState = Math.min(fareForState, Math.round(fareStructure.getIntegerFareCap()));
fareForState = Math.min(fareForState, fareStructure.getIntegerFareCap());
}

// initialize transfer allowance
Expand All @@ -173,20 +174,20 @@ public FareBounds calculateFare(McRaptorSuboptimalPathProfileRouter.McRaptorStat
// if transfer allowances are inactive (for debugging purposes), just use and empty transfer allowance and
// quit the function
if (!ParetoItineraryPlanner.travelAllowanceActive) {
return new FareBounds(fareForState, new TransferAllowance());
return new FareBounds(fareForState, new R5RTransferAllowance());
}

// pattern is valid?
if (currentPatternIndex == -1) {
// no public transport patterns - return empty transfer allowance
return new FareBounds(fareForState, new TransferAllowance());
return new FareBounds(fareForState, new R5RTransferAllowance());
}

// remaining transfers
int numberOfRemainingTransfers = fareStructure.getMaxDiscountedTransfers() - discountsApplied;
if (numberOfRemainingTransfers <= 0) {
// no remaining available transfers - return empty transfer allowance
return new FareBounds(fareForState, new TransferAllowance());
return new FareBounds(fareForState, new R5RTransferAllowance());
}

// get max benefit from possible transfers
Expand All @@ -210,7 +211,7 @@ public FareBounds calculateFare(McRaptorSuboptimalPathProfileRouter.McRaptorStat
int expirationTime = currentBoardTime + fareStructure.getTransferTimeAllowanceSeconds();

// build transfer allowance considering constraints above
TransferAllowance transferAllowance = new R5RTransferAllowance(lastFareType, maxAllowanceValue, numberOfRemainingTransfers, expirationTime);
R5RTransferAllowance transferAllowance = new R5RTransferAllowance(lastFareType, maxAllowanceValue, numberOfRemainingTransfers, expirationTime);
return new FareBounds(fareForState, transferAllowance);

}
Expand Down

0 comments on commit a2fcdca

Please sign in to comment.