Skip to content

Add 'transferParametersForMode' build config field#6215

Merged
optionsome merged 35 commits into
opentripplanner:dev-2.xfrom
HSLdevcom:car-transferrequest-filtering
Jan 23, 2025
Merged

Add 'transferParametersForMode' build config field#6215
optionsome merged 35 commits into
opentripplanner:dev-2.xfrom
HSLdevcom:car-transferrequest-filtering

Conversation

@VillePihlava

@VillePihlava VillePihlava commented Nov 1, 2024

Copy link
Copy Markdown
Contributor

Summary

This PR adds the transferParametersForMode build config field for configuring transfers. These parameters can be configured for all transfer modes:

  • disableDefaultTransfers: allows disabling default transfer calculations
  • maxTransferDuration: allows configuring a mode-specific maxTransferDuration
  • carsAllowedStopMaxTransferDuration: allows changing max transfer durations between stops that allow cars

This is a follow-up PR related to #5966. Example configuration:

  "transferParametersForMode": {
    "CAR": {
      "disableDefaultTransfers": true,
      "carsAllowedStopMaxTransferDuration": "3h"
    },
    "BIKE": {
      "maxTransferDuration": "30m",
      "carsAllowedStopMaxTransferDuration": "3h"
    }
  },

Issue

This is a follow-up PR related to issue #5875.

Unit tests

I created new unit tests for testing the changes to the DirectTransferGenerator

Documentation

Changes to BuildConfiguration.md

Bumping the serialization version id

This change affects how transfers are calculated and adds a new field to the build-config.json file.

@VillePihlava
VillePihlava requested a review from a team as a code owner November 1, 2024 11:15
@codecov

codecov Bot commented Nov 1, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 91.76471% with 14 lines in your changes missing coverage. Please review.

Project coverage is 69.76%. Comparing base (448ad8f) to head (186d20c).
Report is 50 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
.../graph_builder/module/DirectTransferGenerator.java 89.83% 6 Missing and 6 partials ⚠️
.../standalone/config/buildconfig/TransferConfig.java 85.71% 1 Missing ⚠️
...e/config/buildconfig/TransferParametersMapper.java 95.23% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6215      +/-   ##
=============================================
+ Coverage      69.72%   69.76%   +0.04%     
- Complexity     18016    18045      +29     
=============================================
  Files           2057     2060       +3     
  Lines          76967    77097     +130     
  Branches        7844     7854      +10     
=============================================
+ Hits           53666    53788     +122     
- Misses         20550    20556       +6     
- Partials        2751     2753       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@habrahamsson-skanetrafiken

Copy link
Copy Markdown
Contributor

There are some conflicts

@optionsome optionsome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had too many reviews today already so I didn't go properly through this. However, inspired by some concerns from @t2gran, I think to avoid issues we should do a couple of things:

  1. Introduce carsAllowedStopMaxAccessEgressDurationsForMode. This is to prevent weird back-and-forth transfers to avoid access and egress duration limitations.
  2. Prevent these transfers from being used by other street modes. I don't know if this is already done or not but I think at least previously all the transfers were in the same collection. This could again lead to weird back and forth travel by walking for example to escape some other restrictions.

mBuilder.withEgressMode(StreetMode.WALK);
mBuilder.withDirectMode(StreetMode.CAR);
// This is used in transfer cache request calculations.
mBuilder.withAllStreetModes(StreetMode.CAR);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this builder method wasn't introduced in this pr but this name is really confusing. Idk what we call Access+Transfer+Egress+Direct. It's difficult to come up with a name that doesn't confuse you into thinking that all modes are enabled. Just making this singular would maybe make it less confusing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to set each mode separately for more clarity

this.issueStore = issueStore;
this.radiusByDuration = radiusByDuration;
this.transferRequests = transferRequests;
this.carsAllowedStopMaxTransferDurationsForMode = DurationForEnum.of(StreetMode.class).build();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should always include this with some default value that is the same as the normal transfer duration limit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has changed quite a lot, but you can look at how I handle an empty parameter

.stream()
.map(StopLocation::getId)
.map(graph::getStopVertexForStopId)
.filter(TransitStopVertex.class::isInstance) // filter out null values if no TransitStopVertex is found for ID

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline comments are not allowed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@VillePihlava

Copy link
Copy Markdown
Contributor Author

I'm changing this to a draft for now. I'll return to this once the work on the separate transfer request collections for modes has been completed.

@VillePihlava
VillePihlava marked this pull request as draft November 12, 2024 11:14
@VillePihlava VillePihlava changed the title Add carsAllowedStopMaxTransferDurationsForMode build config parameter Add 'transfers build config field Dec 3, 2024
@VillePihlava VillePihlava changed the title Add 'transfers build config field Add 'transfers' build config field Dec 3, 2024
Comment thread doc/user/BuildConfiguration.md Outdated
| [maxDataImportIssuesPerFile](#maxDataImportIssuesPerFile) | `integer` | When to split the import report. | *Optional* | `1000` | 2.0 |
| maxElevationPropagationMeters | `integer` | The maximum distance to propagate elevation to vertices which have no elevation. | *Optional* | `2000` | 1.5 |
| [maxStopToShapeSnapDistance](#maxStopToShapeSnapDistance) | `double` | Maximum distance between route shapes and their stops. | *Optional* | `150.0` | 2.1 |
| maxTransferDuration | `duration` | Transfers up to this duration with the default walk speed value will be pre-calculated and included in the Graph. | *Optional* | `"PT30M"` | 2.1 |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this parameter be moved to be inside transferParameters? Also, I think the description is wrong since this can be used for other types of transfers as well. There might be one or two other parameters that could be moved to be under transferParameters such as discardMinTransferTimes and maybe stationTransferPreference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the OTP meeting discussion, I renamed transferParameters to transferParametersForMode. I also changed the summary for maxTransferDuration to Transfers up to this duration with a mode-specific speed value will be pre-calculated and included in the Graph.

Duration carsAllowedStopMaxTransferDuration,
boolean disableDefaultTransfers
) {
public static final Duration DEFAULT_MAX_TRANSFER_DURATION = Duration.ZERO;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the default 30 minutes? I think the default should be set only in one place and then used from there elsewhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set both of the Duration.ZERO to null

boolean disableDefaultTransfers
) {
public static final Duration DEFAULT_MAX_TRANSFER_DURATION = Duration.ZERO;
public static final Duration DEFAULT_CARS_ALLOWED_STOP_MAX_TRANSFER_DURATION = Duration.ZERO;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if the default value for this should be the same as the normal default or null.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set both of the Duration.ZERO to null

"Transfers up to this duration with the default walk speed value will be pre-calculated and included in the Graph."
)
.asDuration(Duration.ofMinutes(30));
transferParametersForMode = TransferConfig.map(root, "transferParameters");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable should be renamed if we decide to make the transferParameters used for other transfer parameters as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the OTP meeting discussion, I renamed transferParameters to transferParametersForMode

import org.opentripplanner.graph_builder.module.TransferParameters;
import org.opentripplanner.standalone.config.framework.json.NodeAdapter;

public class TransferParametersMapper {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added changes to both files

Comment on lines +25 to +31
.description(
"""
This parameter configures additional transfers to be calculated for the specified mode only between stops that have trips with cars.
The transfers are calculated for the mode in a range based on the given duration.
By default, these transfers are not calculated for the specified mode.
"""
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this parameter is rather odd on the first glance, you could explain a bit here that this might be useful when there are ferries that sort of extend the road network.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a difficult concepts so needs a bit more docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added more documentation

builder.withDisableDefaultTransfers(
c
.of("disableDefaultTransfers")
.summary("This disables default transfer calculations.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a bit more descriptive description for what the default transfer calculations means and why you might want to do this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added more documentation

@leonardehrenfried leonardehrenfried left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you fix @optionsome 's points I can approve this.

@VillePihlava

Copy link
Copy Markdown
Contributor Author

Should this bump the serialization id since the path transfers are now mode dependent?

The mode-dependency for PathTransfers was added in another PR. Because this PR changes how transfer calculations can be configured, I think the serialization id should be bumped.

@VillePihlava VillePihlava changed the title Add 'transferParameters' build config field Add 'transferParametersForMode' build config field Jan 14, 2025
@optionsome optionsome added +Bump Serialization Id Add this label if you want the serialization id automatically bumped after merging the PR +Config Change This PR might require the configuration to be updated. !Improvement A functional improvement or micro feature labels Jan 14, 2025

// Calculate default transfers.
for (RouteRequest transferProfile : transferRequests) {
for (RouteRequest transferProfile : transferConfiguration.defaultTransferRequests) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better if you use the record fields through the getters instead of accessing the fields directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has now been changed

List<RouteRequest> carsAllowedStopTransferRequests = new ArrayList<>();
List<RouteRequest> flexTransferRequests = new ArrayList<>();
HashMap<StreetMode, NearbyStopFinder> defaultNearbyStopFinderForMode = new HashMap<>();
/* These are used for calculating transfers only between carsAllowedStops. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use normal comments inside methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were from a previous commit. I changed them in this file everywhere I could find them

```


<h3 id="tpfm_BIKE_carsAllowedStopMaxTransferDuration">carsAllowedStopMaxTransferDuration</h3>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the same fields are documented for all modes (specified in the example build-config.json) which is not what we want since I doubt we will have mode specific parameters. I don't know what is the best way to get rid of this. One option would be to have a structure like:

{
  "transferParametersForModes": [
    {"mode": "CAR", "maxTransferDuration": "30m"}
  ]
}

instead of having this kind of an enum map.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed this has been left as is. I added a topic discussion in the dev meeting thread

createPathTransfer(sd.stop, stop, sd, distinctTransfers, mode);
}
}
// Calculate transfers between stops that are visited by trips that allow cars, if configured.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is getting too long. Please split it up into the various phases (default, flex, cars allowed) and then convert these line comments into javadoc.

Afterwards I'm satisfied and will approve.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split this into three functions

@optionsome

Copy link
Copy Markdown
Member

I think the issue with the documentation getting generated in a wrong way still exists. I think we should investigate fixing it in the scope of this pr.

@optionsome
optionsome merged commit 0c2ed2d into opentripplanner:dev-2.x Jan 23, 2025
@optionsome
optionsome deleted the car-transferrequest-filtering branch January 23, 2025 13:00
t2gran pushed a commit that referenced this pull request Jan 23, 2025
t2gran pushed a commit that referenced this pull request Jan 23, 2025
@t2gran t2gran added this to the 2.7 (next release) milestone Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

+Bump Serialization Id Add this label if you want the serialization id automatically bumped after merging the PR +Config Change This PR might require the configuration to be updated. !Improvement A functional improvement or micro feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants