entur / r5

Rapid Realistic Routing on Real-world and Reimagined networks
MIT License
2 stars 2 forks source link

Improve Pattern - TripSchedule model #1

Open t2gran opened 6 years ago

t2gran commented 6 years ago

Today ruffly 1/3 of the time spent in the routing() search (worker route()) is spent searching for trips. The data structure is not optimal and can be optimized/simplified for the purpose.

Current Model The model looks more or less like this:

Stop
+-> * Pattern
      +-> * stopIndex : int[]
      +-> * TripSchedule
            - arrivals : int[]
            - departures : int[]

But this is not how the data is accessed, restructuring them would improve the performance and simplify the code:

Stop
+-> * Pattern
      - * trip ids/indexes/refs  
      +-> * PatternStop              <-- Name is up for discussion
            - stop index/id/ref
            +-> * StopVisit             <-- Name is up for discussion
                  - arrival
                  - departure

Also if we could duplicate the structure for every service day (next N supported days) and only have scheduled trips for that particular day. Then we could get rid of the following call - witch is done to check if a trip is running - this check is done for every trip we try to board:

     trip.headwaySeconds != null || transit.skipCalendarService(trip.serviceCode);
    (RangeRaptorWorker @line 296)

Keeping trips de-normalized pr day will also simplify realtime updates, because only today and tomorrow is likely to be affected by the updates.