I am working on a simulator for a railway that is represented by a undirected graph where the edges are the train tracks and the vertices are the switches.
here is what the railway looks like
There is only one track between each switch which lets the train drive both directions.
For every train I calculate their directions by using Dijkstra single shortest path algorithm. But now I need to be able to detect collision with that result.
For example let's say there are 2 trains A and B
the path of A = (Gt Mx Lg Nm Lg) with current track being Gt
and for B = (Gk Lg Nm Bx A1)
You can easily see these trains will hit each other at a certain point and I am looking for a way to predict and prevent this.
Have looked into union find or maybe Knuth Algorithm x, but I hope any of you has a better idea of solving this.