Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3c5fabc
feat: carpooling skeleton
t2gran Aug 8, 2025
cc39b34
Adds basics of trip and leg contructs for Carpooling, along with a ru…
eibakke Aug 11, 2025
264a933
Factors out the itinerary mapping code into its own class and cleans …
eibakke Aug 19, 2025
c7f4b67
Formatting fix.
eibakke Aug 21, 2025
bbde8b0
Run prettier.
eibakke Sep 10, 2025
eeeac6d
Fixes null pointer exception.
eibakke Sep 12, 2025
5a20682
New carpooling implementation.
eibakke Oct 9, 2025
6ddf015
Expands logic with new filters and adds simpler bee-line routing as a…
eibakke Oct 10, 2025
468fa0a
Refactors and simplifies.
eibakke Oct 17, 2025
78a9267
Small cleanups.
eibakke Oct 21, 2025
d51b5a8
Fixes a stop assignment preference in calls.
eibakke Oct 31, 2025
321dc20
Addresses most comments in PR so far.
eibakke Oct 31, 2025
b919a12
Makes use of the estimatedVehicleJourneyCode for the TripID instead o…
eibakke Nov 3, 2025
84b5b10
Addresses more comments in PR and adds defaults for capacity and devi…
eibakke Nov 3, 2025
8a89905
Addresses more comments in PR.
eibakke Nov 3, 2025
d41b37c
Cleans up the SiriETCarpoolingUpdater.
eibakke Nov 4, 2025
1fc92b3
Cleans up issues in test code.
eibakke Nov 4, 2025
4a16c98
Removes unnecessary Parameters interface from SiriETCarpoolingUpdater.
eibakke Nov 4, 2025
88a4bec
Makes use of DirectionUtils instead of creating a new DirectionalCalc…
eibakke Nov 4, 2025
58bd9ed
Removes all star imports from carpool test code.
eibakke Nov 5, 2025
fcd4aa3
Removes all trailing comments from carpool test code.
eibakke Nov 5, 2025
16cd187
Removes CarpoolStreetRouterTest.
eibakke Nov 5, 2025
62809f3
Removes MockGraphPathFactory.java and makes use of real graph path bu…
eibakke Nov 5, 2025
de0bf24
Removes more mock usage.
eibakke Nov 5, 2025
21b1421
Smaller cleanup of CarpoolSiriMapper.
eibakke Nov 5, 2025
6a220a0
Gets timezone from transitservice for CarpoolItineraryMapper and star…
eibakke Nov 5, 2025
a2a9132
Moves distance calculation into shared geometry package.
eibakke Nov 6, 2025
0d8cc6f
Removes routing from carpooling updater and makes it a 15 minute defa…
eibakke Nov 6, 2025
12c5437
Adds sandbox doc for carpooling.
eibakke Nov 6, 2025
bbf57c1
Merge branch 'dev-2.x' into carpooling_pok
eibakke Nov 6, 2025
eb4bdf1
Formatting.
eibakke Nov 6, 2025
b7811bf
Removes the concepts of origin and destination areas as special place…
eibakke Nov 6, 2025
68a06ab
Merge branch 'dev-2.x' into carpooling_pok
eibakke Nov 7, 2025
83bb9f5
Addresses comments in PR.
eibakke Nov 7, 2025
41db441
Regenerates the Configuration.md
eibakke Nov 7, 2025
0f2f94f
Removes unnecessary sourceParameters method form SiriETLiteUpdaterPar…
eibakke Nov 17, 2025
70ff308
Renames SiriETUpdaterParameters to DefaultSiriETUpdaterParameters.
eibakke Nov 17, 2025
bde81af
Extracts SiriETUpdaterParameters into its own file.
eibakke Nov 17, 2025
095d01f
Removes the SiriETCarpoolingUpdaterConfig.java and SiriETCarpoolingUp…
eibakke Nov 17, 2025
0170a93
Merge branch 'dev-2.x' into carpooling_pok
eibakke Nov 17, 2025
d739459
Adapts to new setup for temporary vertices for use in A* routing.
eibakke Nov 18, 2025
e5a7466
Creates a TemporaryVerticesContainer local to the CarpoolingService's…
eibakke Nov 19, 2025
b61e439
Merge otp/dev-2.x into carpooling_pok
eibakke Nov 19, 2025
0c39245
Update application/src/ext/java/org/opentripplanner/ext/carpooling/se…
eibakke Nov 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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);
}
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);
}
Loading
Loading