optimise-services-and-exceptions: analyse distribution of service dates -> truncate/expand time span
derhuerst opened this issue · comments
As of gtfs-utils@5.1.0
, optimise-services-and-exceptions.js
implements a very rudimental optimisation strategy:
- it calculates all service dates (both "regular" &
exception_type=1
-based) of a service, and then - checks if there are more "regular" than exception-based dates (in this case, it sets the respective daw of the week (DoW) flag to
1
), or vice versa.
There is a lot of potential in changing the time span (start_date
/end_date
) of the service, so that the number of exceptions necessary to express it is minimised. To do this, we must consider the distribution of the service's dates, so that rare outliers – e.g. Christmas with a service that only runs during summer & on Christmas – are expressed as exceptions, whereas the majority of the dates is express using DoW flags.
Consider this example:
service:
2022-05-01 - 2022-05-31
monday: 1
exceptions:
ADDED 2022-05-03 tuesday
ADDED 2022-05-10 tuesday
ADDED 2022-05-17 tuesday
ADDED 2022-05-31 tuesday
ADDED 2022-05-18 wednesday
ADDED 2022-05-07 saturday
REMOVED 2022-05-09 monday
REMOVED 2022-05-30 monday
By changing the service's time span to 20220501
/20220523
, we can reduce the number of expressions:
service:
2022-05-01 - 2022-05-23
monday: 1
tuesday: 1
exceptions:
ADDED 2022-05-31 tuesday
ADDED 2022-05-18 wednesday
ADDED 2022-05-07 saturday
REMOVED 2022-05-09 monday
REMOVED 2022-05-30 monday