In order to solve the problem of how to choose the shortest route and the corresponding capital consumption during the transportation of goods, this paper uses mathematical modeling competition data to analyze and calculate, which has authenticity and simulates the display situation to a great extent. The shortest path is calculated by the Floyd algorithm, and the optimization model is established by the Matlab. It provides not only solutions for the capital savings, but also the choice of the shortest path in the transportation of goods. Besides this paper proposes a more practical strategy of the shortest path problem, which has significance meanings for researching.