Skip to content
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

Question: How does Motis CSA handle splitting and joining trains? #431

Open
McToel opened this issue Jan 22, 2024 · 2 comments
Open

Question: How does Motis CSA handle splitting and joining trains? #431

McToel opened this issue Jan 22, 2024 · 2 comments

Comments

@McToel
Copy link

McToel commented Jan 22, 2024

I am working on a new routing engine for https://bahnvorhersage.de/ that is able to perform a search for alternatives connections if a connection not work, so that a passanger can plan for journeys with reliable alternatives.

Currently I'm trying to figure out how i might handle splitting an joining trains in my CSA implementation. If I understand correctly, motis implements a CSA that can handle these types of trains. Could you give me some details on how motis is handeling this or where I can find it in the code?

@felixguendling
Copy link
Member

felixguendling commented Jan 22, 2024

Hey! 😄 👋

We call the following services "rule services":

  • merge + split ("Flügelung" / "Vereinigung")
  • through services ("Durchbindung" / GTFS block_id)

In our approach, we need to consider both of them together to provide correct results (regarding Pareto-optimality).

Let's consider the following services, rules and their connection. Services are the nodes at the bottom, rules the top nodes where MS indicates "merge/split" and T indicates through-services.

image

Note that those rules apply to specific days. For simplicity, I assume that all rules active on the same days and no service is "cut". This means there's no case where another service outside the timetable period would be required to have all trains of the rule operating and no rule service participant is missing a matching partner.

Let's assume the trains visit the following stations:

image

From this network, we can derive something we call expanded services: these expanded services represent all ways a rider could travel and are used only for routing purposes. So when it comes to generating departure tables, or plot trains on a map, won't have duplicates.

For our example, the set of expanded services looks like this:

image

These services allow for all travel options a traveler would have considering that a interchange between two merged trains is not counted as a real interchange. The same is true for the change between services for through trains. Those expanded services can be collected using a repeated depth search from nodes with in-degree of zero.

Code that handles rule services:

If you want to handle this topic correctly (in terms of preserving Pareto-optimality), it escalates quickly. Especially the part that I omitted before (generating rule service constructs with uniform traffic days) can be tricky. The basic idea is that you iterate through the first graph (with MS and T nodes) and intersect bitfields until all bits are zero or there's no further service (graph traversal with early termination if bitfields became zero). Each time the component that was traversed is cut out of the graph (bits set to zero) and written as rule service construct with uniform traffic days).

Feel free to ask more questions.

@felixguendling
Copy link
Member

felixguendling commented Jan 22, 2024

Ah.. and to answer your actual question: the CSA algorithm stays the same, just the connections array, etc. are derived from those expanded trips instead of the raw trips from the source timetable.

The new core (nigiri) currently does not expand merge/split trains in the loading procedure. But this (or another solution with similar effect for the search results) will probably be implemented this year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants