142k views
2 votes
In EXCEL VBA, Extend the traveling salesman problem so that each of the cities is used as a starting city for the nearest neighbor algorithm. The optimal tour will be the tour that starts the nearest-neighbor algorithm in one city that results in the shortest total distance traveled. You can safely assume that the anchor cell will be cell A3 (as in the example we worked in class). Your expanded code should work for any number of cities and should show at the end of the run the optimal tour (sequence of cities visited) and the length of the total distance. Your code should work such that if the minimal total distance of the optimal tour is equal for several starting cities, the selected tour will be the one with earliest city in the list. For instance, in the 5-city example, if the tours 2-5-3-4-1 and 4-3-1-2-5 have total distance of 19 and there are no other tours with a total distance less than 19, then the selected tour would be 2-5-3-4-1. Notice that all tours visit all cities and return to the starting city and the actual tour can start in any of the cities of the tour.

User Amar Syla
by
8.1k points

1 Answer

4 votes

Final answer:

The expanded Excel VBA solution to the Traveling Salesman Problem entails using each city as a starting point and implementing the nearest neighbor algorithm, to compute the shortest tour, prioritizing the earliest city in the event of distance ties.

Step-by-step explanation:

The Traveling Salesman Problem (TSP) in Excel VBA is an optimization problem which aims to find the shortest possible route that visits a set of cities and returns to the origin city. The challenge involves extending the problem so that each city is used as a starting point for the nearest neighbor algorithm to determine the optimal tour.

The requirement is to execute the algorithm for all possible starting points and identify the tour with the least total distance. Additionally, if multiple tours have the same minimal distance, the one starting with the earliest city in the list should be selected.

Implementing this in VBA would require looping over all cities as starting points, running the nearest neighbor algorithm for each, tracking the total distances of the tours, and then comparing them to find the optimal solution. The code should dynamically adapt to any number of cities and display both the optimal sequence of cities visited and the total distance of the optimal tour.

User Fpietka
by
7.6k points