Calculates the least-cost path from a source to a destination.