This sounds essentially like a graph theory problem. Have a track segments be arcs and the places where they connect be nodes. I don't know exactly what the criteria are for a "connecting, valid layout", but I'll assume it's at least planarity (no tracks crossing one another) and that there always exists a non-zero-length path from a node to itself. The presence of cross-over bridges permit a special case of track-crossing, so graphs with a c.o.b. would be allowed to be non-planar only for the c.o.b. arcs. Switches are just two arcs going to/coming from the same node.
Once you've got the graph designed, you can start tackling the problem of laying it out spatially so that it fits with the pieces.