-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Carpooling POC #6791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+7,876
−57
Merged
Carpooling POC #6791
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
3c5fabc
feat: carpooling skeleton
t2gran cc39b34
Adds basics of trip and leg contructs for Carpooling, along with a ru…
eibakke 264a933
Factors out the itinerary mapping code into its own class and cleans …
eibakke c7f4b67
Formatting fix.
eibakke bbde8b0
Run prettier.
eibakke eeeac6d
Fixes null pointer exception.
eibakke 5a20682
New carpooling implementation.
eibakke 6ddf015
Expands logic with new filters and adds simpler bee-line routing as a…
eibakke 468fa0a
Refactors and simplifies.
eibakke 78a9267
Small cleanups.
eibakke d51b5a8
Fixes a stop assignment preference in calls.
eibakke 321dc20
Addresses most comments in PR so far.
eibakke b919a12
Makes use of the estimatedVehicleJourneyCode for the TripID instead o…
eibakke 84b5b10
Addresses more comments in PR and adds defaults for capacity and devi…
eibakke 8a89905
Addresses more comments in PR.
eibakke d41b37c
Cleans up the SiriETCarpoolingUpdater.
eibakke 1fc92b3
Cleans up issues in test code.
eibakke 4a16c98
Removes unnecessary Parameters interface from SiriETCarpoolingUpdater.
eibakke 88a4bec
Makes use of DirectionUtils instead of creating a new DirectionalCalc…
eibakke 58bd9ed
Removes all star imports from carpool test code.
eibakke fcd4aa3
Removes all trailing comments from carpool test code.
eibakke 16cd187
Removes CarpoolStreetRouterTest.
eibakke 62809f3
Removes MockGraphPathFactory.java and makes use of real graph path bu…
eibakke de0bf24
Removes more mock usage.
eibakke 21b1421
Smaller cleanup of CarpoolSiriMapper.
eibakke 6a220a0
Gets timezone from transitservice for CarpoolItineraryMapper and star…
eibakke a2a9132
Moves distance calculation into shared geometry package.
eibakke 0d8cc6f
Removes routing from carpooling updater and makes it a 15 minute defa…
eibakke 12c5437
Adds sandbox doc for carpooling.
eibakke bbf57c1
Merge branch 'dev-2.x' into carpooling_pok
eibakke eb4bdf1
Formatting.
eibakke b7811bf
Removes the concepts of origin and destination areas as special place…
eibakke 68a06ab
Merge branch 'dev-2.x' into carpooling_pok
eibakke 83bb9f5
Addresses comments in PR.
eibakke 41db441
Regenerates the Configuration.md
eibakke 0f2f94f
Removes unnecessary sourceParameters method form SiriETLiteUpdaterPar…
eibakke 70ff308
Renames SiriETUpdaterParameters to DefaultSiriETUpdaterParameters.
eibakke bde81af
Extracts SiriETUpdaterParameters into its own file.
eibakke 095d01f
Removes the SiriETCarpoolingUpdaterConfig.java and SiriETCarpoolingUp…
eibakke 0170a93
Merge branch 'dev-2.x' into carpooling_pok
eibakke d739459
Adapts to new setup for temporary vertices for use in A* routing.
eibakke e5a7466
Creates a TemporaryVerticesContainer local to the CarpoolingService's…
eibakke b61e439
Merge otp/dev-2.x into carpooling_pok
eibakke 0c39245
Update application/src/ext/java/org/opentripplanner/ext/carpooling/se…
eibakke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
application/src/ext/java/org/opentripplanner/ext/carpooling/Architecture.md
This file contains hidden or 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,89 @@ | ||
| # Carpooling Extension Architecture | ||
|
|
||
| ## Overview | ||
|
|
||
| The carpooling extension enables passengers to join existing driver journeys by being picked up and dropped off along the driver's route. The system finds optimal insertion points for new passengers while respecting capacity constraints, time windows, and route deviation budgets. | ||
|
|
||
| ## Package Structure | ||
|
|
||
| ``` | ||
| org.opentripplanner.ext.carpooling/ | ||
| ├── model/ # Domain models | ||
| │ ├── CarpoolTrip # Represents a carpool trip offer | ||
| │ ├── CarpoolStop # Intermediate stops with passenger delta | ||
| │ └── CarpoolLeg # Carpool segment in an itinerary | ||
| ├── routing/ # Routing and insertion algorithms | ||
| │ ├── InsertionEvaluator # Finds optimal passenger insertion | ||
| │ ├── InsertionCandidate # Represents a viable insertion | ||
| │ └── CarpoolStreetRouter # Street routing for carpooling | ||
| ├── filter/ # Trip pre-filtering | ||
| │ ├── TripFilter # Filter interface | ||
| │ ├── CapacityFilter # Checks available capacity | ||
| │ ├── TimeBasedFilter # Time window filtering | ||
| │ ├── DistanceBasedFilter # Geographic distance checks | ||
| │ └── DirectionalCompatibilityFilter # Directional alignment | ||
| ├── constraints/ # Post-routing constraints | ||
| │ └── PassengerDelayConstraints # Protects existing passengers | ||
| ├── util/ # Utilities | ||
| │ ├── BeelineEstimator # Fast travel time estimates | ||
| │ └── DirectionalCalculator # Geographic bearing calculations | ||
| ├── updater/ # Real-time updates | ||
| │ ├── SiriETCarpoolingUpdater # SIRI-ET integration | ||
| │ └── CarpoolSiriMapper # Maps SIRI to domain model | ||
| └── service/ # Service layer | ||
| ├── CarpoolingService # Main service interface | ||
| └── DefaultCarpoolingService # Service implementation | ||
| ``` | ||
|
|
||
| ## Trip Matching Algorithm | ||
|
|
||
| The carpooling service uses a multi-phase algorithm to match passengers with compatible carpool trips: | ||
|
|
||
| ### 1. Filter Phase | ||
| Fast pre-screening to eliminate incompatible trips: | ||
| - **Capacity Filter**: Checks if any seats are available | ||
| - **Time-Based Filter**: Ensures departure time compatibility | ||
| - **Distance-Based Filter**: Validates pickup/dropoff are within 50km of driver's route | ||
| - **Directional Compatibility Filter**: Verifies passenger direction aligns with trip route | ||
|
|
||
| ### 2. Routing Phase | ||
| Optimal insertion point calculation: | ||
| - Uses beeline estimates for early rejection | ||
| - Routes baseline segments once and caches results | ||
| - Evaluates all viable insertion positions | ||
| - Selects position with minimum additional travel time | ||
|
|
||
| ### 3. Constraint Validation | ||
| - **Capacity constraints**: Ensures vehicle capacity is not exceeded | ||
| - **Directional constraints**: Prevents backtracking (90° tolerance) | ||
| - **Passenger delay constraints**: Protects existing passengers (max 5 minutes additional delay) | ||
| - **Deviation budget**: Respects driver's maximum acceptable detour time | ||
|
|
||
| ## Multi-Stop Support | ||
|
|
||
| The system handles trips with multiple existing passengers: | ||
| - Each stop tracks passenger count changes (pickups and dropoffs) | ||
| - Capacity validation ensures vehicle is never over capacity | ||
| - Route optimization considers all existing stops when inserting new passengers | ||
| - Passenger delay constraints protect all existing passengers from excessive delays | ||
|
|
||
| ## Integration Points | ||
|
|
||
| ### GraphQL API | ||
| Carpooling results are integrated into the standard OTP GraphQL API. Carpool legs appear as a distinct leg mode (`CARPOOL`) in multi-modal itineraries, similar to how transit, walking, and biking legs are represented. | ||
|
|
||
| ### SIRI-ET Updater | ||
| The `SiriETCarpoolingUpdater` receives real-time updates about carpool trips via SIRI-ET (Estimated Timetable) messages. The `CarpoolSiriMapper` maps SIRI-ET data to the internal domain model: | ||
| - `EstimatedVehicleJourneyCode` → Trip ID | ||
| - `EstimatedCalls` → Stops on the carpooling trip | ||
|
|
||
| ## Design Decisions | ||
|
|
||
| ### Static Deviation Budget | ||
| Currently assumes a 15 minute budget for carpooling. Future versions will support configurable or dynamically negotiated deviation budgets. | ||
|
|
||
| ### Static Capacity | ||
| Available seats are static trip properties. There is no reservation system yet. | ||
|
|
||
| ### Basic Time Windows | ||
| Only simple departure time compatibility is implemented. "Arrive by" constraints are planned for future versions. |
42 changes: 42 additions & 0 deletions
42
application/src/ext/java/org/opentripplanner/ext/carpooling/CarpoolingRepository.java
This file contains hidden or 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,42 @@ | ||
| package org.opentripplanner.ext.carpooling; | ||
|
|
||
| import java.util.Collection; | ||
| import org.opentripplanner.ext.carpooling.model.CarpoolTrip; | ||
|
|
||
| /** | ||
| * Repository for managing carpooling trip ({@link CarpoolTrip}) data. | ||
| * <p> | ||
| * This repository maintains an in-memory index of driver trips. | ||
| * | ||
| * @see CarpoolTrip for trip data model | ||
| * @see org.opentripplanner.ext.carpooling.updater.SiriETCarpoolingUpdater for real-time updates | ||
| */ | ||
| public interface CarpoolingRepository { | ||
| /** | ||
| * Returns all currently carpooling trips. | ||
| * <p> | ||
| * The returned collection includes all driver trips that have been added via {@link #upsertCarpoolTrip} | ||
| * and not yet removed or expired. The collection is typically used by the routing service to find | ||
| * compatible trips for passengers. | ||
| */ | ||
| Collection<CarpoolTrip> getCarpoolTrips(); | ||
|
|
||
| /** | ||
| * Inserts a new carpooling trip or updates an existing trip with the same ID. | ||
| * <p> | ||
| * This method is the primary mechanism for adding driver trip data to the repository. It is | ||
| * typically called by real-time updaters when receiving trip information from external systems, | ||
| * or when passenger bookings modify trip capacity. | ||
| * | ||
| * <h3>Validation</h3> | ||
| * <p> | ||
| * The method does not validate trip data beyond basic null checks. It is the caller's | ||
| * responsibility to ensure the trip is valid (has stops, positive capacity, etc.). Invalid | ||
| * trips may cause routing failures later. | ||
| * | ||
| * @param trip the carpool trip to insert or update, must not be null. If a trip with the same | ||
| * ID exists, it will be completely replaced. | ||
| * @throws IllegalArgumentException if trip is null | ||
| */ | ||
| void upsertCarpoolTrip(CarpoolTrip trip); | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
application/src/ext/java/org/opentripplanner/ext/carpooling/CarpoolingService.java
This file contains hidden or 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.ext.carpooling; | ||
|
|
||
| import java.util.List; | ||
| import org.opentripplanner.model.plan.Itinerary; | ||
| import org.opentripplanner.routing.api.request.RouteRequest; | ||
| import org.opentripplanner.routing.linking.LinkingContext; | ||
|
|
||
| /** | ||
| * Service for finding carpooling options by matching passenger requests with available driver trips. | ||
| * <p> | ||
| * Carpooling enables passengers to join existing driver journeys by being picked up and dropped off | ||
| * along the driver's route. The service finds optimal insertion points for new passengers while | ||
| * respecting capacity constraints, time windows, and route deviation budgets. | ||
| */ | ||
| public interface CarpoolingService { | ||
| /** | ||
| * Finds carpooling itineraries matching the passenger's routing request. | ||
| * <p> | ||
| * | ||
| * @param request the routing request containing passenger origin, destination, and preferences | ||
| * @param linkingContext linking context with pre-linked vertices for the request | ||
| * @return list of carpool itineraries, sorted by quality (additional travel time), may be empty | ||
| * if no compatible trips found. Results are limited to avoid overwhelming users. | ||
| * @throws IllegalArgumentException if request is null | ||
| */ | ||
| List<Itinerary> route(RouteRequest request, LinkingContext linkingContext); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.