Possible "Traveling Salesman" function in Matlab? -
To solve the problem of a travel vendor using the matrix to find the least amount of time between the transit Seeing. The matrix looks like something:
A = [inf 4 3 5; 1 Inf 3 5; 4 5 Info3; 6 7 1 INF] represents the node "from y-axis" and shows the node "from the x-axis" I try to find the optimum time from node 1 to node 4 I am doing I was told that there is a MetLab function called "TravelingSallemen" is it true, and if not, how would I have to go about solving this matrix?
Thank you!
1 Here is a framework for brute-force algorithm to solve TSP for path from pre> . For each permutation of nodes, C = inf P = zeros (1, n-2) [2..n-1] // path always starts with node 1 and node n c = a (1, p (1 ) + A (P (1), P (2)) + A (P (2), P (3)) + ... + A (P3), P (N -2) + A (P-2, N) If C & LT; MinCost minCost = C minPath = P elseif C == minCost // You only need this part if you want minpath = [minpath; p] // most All paths with a short distance end Note that the first and last factors in the amount are different because you already know that the last and the last What are the nodes, so you have to include them in the permutations, so in the example, with the n = 4 , in fact, only 2! = 2 are possible paths. The list of permutations can be approximated by using perms (2: n-1) , but there is a large matrix ( n! Xn ) storage in it Or you can calculate the cost while generating each permutation. There are many files on the Mathworks File Exchange, such as With the name nextPerm , which should work for you. Either way, as n grows, you are going to create a large number of permutations and your calculation will take a very long time.
Comments
Post a Comment