solve the traveling salesman problem using the farest neighbour heuristic
1 view (last 30 days)
Show older comments
Hello, I'm trying to implement the solution for the traveling salesman problem, using farest neighbour heuristic. This is what I have at this moment:
function v = far(matrix)
v = [];
begin = [0,0,0];
while size(v,2) ~= size(matrix,1)
BiggestDistance = 0;
for i = matrix(1):matrix(size(matrix,1))
a = distance(begin(1),matrix(i),matrix); %This is another function to search the distance between two points.
if a > biggestDistance
a = biggestDistance;
end
begin = [matrix(i),matrix(size(matrix)+i,matrix(2*size(matrix)+i))];
v = [v,matrix(i)];
matrix([i],:) = [];
end
end
The input for this funcion is a matrix with 3 columns and i rows. This is my idea for this implementation: as long as v doesn't have all the numbers, the while-lus will continue to run. In the second and thirt column, the x and y-coordinate of the cities are present. I search the biggest distance between the begin and another city. That other city will be the next begin and the city will be appended in v. At least, the row where this city is present will be deleted.
But this program doesn't work at all. Does someone knows what I did wrong?
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!