In this paper, cost function for routing is studied. By introduction of improved cost function, an improved algorithm is proposed. Compared with the original algorithm, the improved algorithm is more stable and the feasible solution obtained is closer to the upper bound of optimal solution. The optimal solution lies between the upper bound and the feasible solution, so the feasible solution is even closer to the optimal solution. Therefore, algorithm with new cost function has better performance than the original algorithm.