Routing and timetabling by topological search