Here is an example of a program that implements a traveling salesman problem solution in C# using brute-force method which checks all possible permutations of cities to determine the shortest travel distance:
main.cs3214 chars101 lines
The program prompts the user to enter the number of cities and the distances between them, and then checks all permutations of cities to find the shortest travel distance. The permuteCities()
method implements the recursive permutation algorithm, and the calculateDistance()
method calculates the total travel distance for a given route. The swap()
method is a helper method for swapping array elements. Finally, the program outputs the shortest route and distance found, as well as the number of permutations checked.
gistlibby LogSnag