An optimal adaptive routing algorithm