Hi everyone!

I've been thinking a lot but couldn't find the best way (if it's possible) to accomplish it. Maybe someone can point me in the right direction.

Ok, the thing is that I'm trying to find a route for a train but there are so many possibilities that I can't find the way to do it.

Imagine we have a list of two columns:
TRAIN LINE WAYPOINT (STATION)
3 A
3 B
3 C
1 D
1 E
4 B
4 F
4 G
5 H
5 J
5 F
5 Z

If we want to go from A to Z, the system should know that:
  • "A" starts in line 3
  • "Z" destination is in line 5
  • "B" is the connection between line 3 (the beginning of the route) and line 4, where "F" is the connection between line 4 (the intersect) and line 5 (destination).


So, does anybody have any ideas on how to find "B" and "F" as the waypoints needed to make the route, passing throw the diffent lines to reach the destination?

Thanks!