Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ipeaGIT/r5r
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Mar 11, 2024
2 parents ccfde8a + 286c7b8 commit 6202d2c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ You can install `r5r`:

```

Please bear in mind that you need to have *Java SE Development Kit 21* installed
on your computer to use `r5r`. No worries, you don't have to pay for it. The jdk
21 is freely available from the options below:
- [OpenJDK](https://jdk.java.net/java-se-ri/21)
- [Oracle](https://docs.oracle.com/en/java/javase/21/install/index.html)

If you don't know what version of Java you have installed on your computer, you
Please bear in mind that you need to have *Java Development Kit (JDK) 21* installed
on your computer to use `r5r`. No worries, you don't have to pay for it. There are
numerous open-source JDK implementations, any of which should work with `r5r`. If you don't
already have a preferred JDK, we recommend [Adoptium/Eclipse Temurin](https://adoptium.net/).
Other open-source JDK implementations include [Amazon Corretto](https://aws.amazon.com/corretto/),
and [Oracle OpenJDK](https://jdk.java.net/21/). You only need to install one JDK.

If you don't know what version of Java you have installed on your computer,
can check it by running this on R console.

```R
Expand Down
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
Binary file modified r-package/inst/jar/r5r.jar
Binary file not shown.

0 comments on commit 6202d2c

Please sign in to comment.