Route counting algorithm