use topsort to determine order of stops