-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6215 from HSLdevcom/car-transferrequest-filtering
Add 'transferParametersForMode' build config field
- Loading branch information
Showing
10 changed files
with
1,046 additions
and
203 deletions.
There are no files selected for viewing
338 changes: 256 additions & 82 deletions
338
...ation/src/main/java/org/opentripplanner/graph_builder/module/DirectTransferGenerator.java
Large diffs are not rendered by default.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
application/src/main/java/org/opentripplanner/graph_builder/module/TransferParameters.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,68 @@ | ||
package org.opentripplanner.graph_builder.module; | ||
|
||
import java.time.Duration; | ||
import org.opentripplanner.utils.tostring.ToStringBuilder; | ||
|
||
/** | ||
* Mode-specific parameters for transfers. | ||
*/ | ||
public record TransferParameters( | ||
Duration maxTransferDuration, | ||
Duration carsAllowedStopMaxTransferDuration, | ||
boolean disableDefaultTransfers | ||
) { | ||
public static final Duration DEFAULT_MAX_TRANSFER_DURATION = null; | ||
public static final Duration DEFAULT_CARS_ALLOWED_STOP_MAX_TRANSFER_DURATION = null; | ||
public static final boolean DEFAULT_DISABLE_DEFAULT_TRANSFERS = false; | ||
|
||
TransferParameters(Builder builder) { | ||
this( | ||
builder.maxTransferDuration, | ||
builder.carsAllowedStopMaxTransferDuration, | ||
builder.disableDefaultTransfers | ||
); | ||
} | ||
|
||
public String toString() { | ||
return ToStringBuilder | ||
.of(getClass()) | ||
.addDuration("maxTransferDuration", maxTransferDuration) | ||
.addDuration("carsAllowedStopMaxTransferDuration", carsAllowedStopMaxTransferDuration) | ||
.addBool("disableDefaultTransfers", disableDefaultTransfers) | ||
.toString(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private Duration maxTransferDuration; | ||
private Duration carsAllowedStopMaxTransferDuration; | ||
private boolean disableDefaultTransfers; | ||
|
||
public Builder() { | ||
this.maxTransferDuration = DEFAULT_MAX_TRANSFER_DURATION; | ||
this.carsAllowedStopMaxTransferDuration = DEFAULT_CARS_ALLOWED_STOP_MAX_TRANSFER_DURATION; | ||
this.disableDefaultTransfers = DEFAULT_DISABLE_DEFAULT_TRANSFERS; | ||
} | ||
|
||
public Builder withMaxTransferDuration(Duration maxTransferDuration) { | ||
this.maxTransferDuration = maxTransferDuration; | ||
return this; | ||
} | ||
|
||
public Builder withCarsAllowedStopMaxTransferDuration( | ||
Duration carsAllowedStopMaxTransferDuration | ||
) { | ||
this.carsAllowedStopMaxTransferDuration = carsAllowedStopMaxTransferDuration; | ||
return this; | ||
} | ||
|
||
public Builder withDisableDefaultTransfers(boolean disableDefaultTransfers) { | ||
this.disableDefaultTransfers = disableDefaultTransfers; | ||
return this; | ||
} | ||
|
||
public TransferParameters build() { | ||
return new TransferParameters(this); | ||
} | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
...ation/src/main/java/org/opentripplanner/standalone/config/buildconfig/TransferConfig.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,44 @@ | ||
package org.opentripplanner.standalone.config.buildconfig; | ||
|
||
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_7; | ||
|
||
import java.util.EnumMap; | ||
import java.util.Map; | ||
import org.opentripplanner.graph_builder.module.TransferParameters; | ||
import org.opentripplanner.routing.api.request.StreetMode; | ||
import org.opentripplanner.standalone.config.framework.json.NodeAdapter; | ||
|
||
public class TransferConfig { | ||
|
||
public static Map<StreetMode, TransferParameters> map(NodeAdapter root, String parameterName) { | ||
return root | ||
.of(parameterName) | ||
.since(V2_7) | ||
.summary("Configures mode-specific properties for transfer calculations.") | ||
.description( | ||
""" | ||
This field enables configuring mode-specific parameters for transfer calculations. | ||
To configure mode-specific parameters, the modes should also be used in the `transferRequests` field in the build config. | ||
**Example** | ||
```JSON | ||
// build-config.json | ||
{ | ||
"transferParametersForMode": { | ||
"CAR": { | ||
"disableDefaultTransfers": true, | ||
"carsAllowedStopMaxTransferDuration": "3h" | ||
}, | ||
"BIKE": { | ||
"maxTransferDuration": "30m", | ||
"carsAllowedStopMaxTransferDuration": "3h" | ||
} | ||
} | ||
} | ||
``` | ||
""" | ||
) | ||
.asEnumMap(StreetMode.class, TransferParametersMapper::map, new EnumMap<>(StreetMode.class)); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...main/java/org/opentripplanner/standalone/config/buildconfig/TransferParametersMapper.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,67 @@ | ||
package org.opentripplanner.standalone.config.buildconfig; | ||
|
||
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_7; | ||
|
||
import org.opentripplanner.graph_builder.module.TransferParameters; | ||
import org.opentripplanner.standalone.config.framework.json.NodeAdapter; | ||
|
||
public class TransferParametersMapper { | ||
|
||
public static TransferParameters map(NodeAdapter c) { | ||
TransferParameters.Builder builder = new TransferParameters.Builder(); | ||
builder.withMaxTransferDuration( | ||
c | ||
.of("maxTransferDuration") | ||
.summary("This overwrites the default `maxTransferDuration` for the given mode.") | ||
.since(V2_7) | ||
.asDuration(TransferParameters.DEFAULT_MAX_TRANSFER_DURATION) | ||
); | ||
builder.withCarsAllowedStopMaxTransferDuration( | ||
c | ||
.of("carsAllowedStopMaxTransferDuration") | ||
.summary( | ||
"This is used for specifying a `maxTransferDuration` value to use with transfers between stops which are visited by trips that allow cars." | ||
) | ||
.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 unless specified for a mode with this field. | ||
Calculating transfers only between stops that have trips with cars can be useful with car ferries, for example. | ||
Using transit with cars can only occur between certain stops. | ||
These kinds of stops require support for loading cars into ferries, for example. | ||
The default transfers are calculated based on a configurable range (configurable by using the `maxTransferDuration` field) | ||
which limits transfers from stops to only be calculated to other stops that are in range. | ||
When compared to walking, using a car can cover larger distances within the same duration specified in the `maxTransferDuration` field. | ||
This can lead to large amounts of transfers calculated between stops that do not require car transfers between them. | ||
This in turn can lead to a large increase in memory for the stored graph, depending on the data used in the graph. | ||
For cars, using this parameter in conjunction with `disableDefaultTransfers` allows calculating transfers only between relevant stops. | ||
For bikes, using this parameter can enable transfers between ferry stops that would normally not be in range. | ||
In Finland this is useful for bike routes that use ferries near the Turku archipelago, for example. | ||
""" | ||
) | ||
.since(V2_7) | ||
.asDuration(TransferParameters.DEFAULT_CARS_ALLOWED_STOP_MAX_TRANSFER_DURATION) | ||
); | ||
builder.withDisableDefaultTransfers( | ||
c | ||
.of("disableDefaultTransfers") | ||
.summary("This disables default transfer calculations.") | ||
.description( | ||
""" | ||
The default transfers are calculated based on a configurable range (configurable by using the `maxTransferDuration` field) | ||
which limits transfers from stops to only be calculated to other stops that are in range. | ||
This parameter disables these transfers. | ||
A motivation to disable default transfers could be related to using the `carsAllowedStopMaxTransferDuration` field which only | ||
calculates transfers between stops that have trips with cars. | ||
For example, when using the `carsAllowedStopMaxTransferDuration` field with cars, the default transfers can be redundant. | ||
""" | ||
) | ||
.since(V2_7) | ||
.asBoolean(TransferParameters.DEFAULT_DISABLE_DEFAULT_TRANSFERS) | ||
); | ||
return builder.build(); | ||
} | ||
} |
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
Oops, something went wrong.