MATLAB Answers

How can i solve this problem?

4 views (last 30 days)
Carolina Silva
Carolina Silva on 18 Nov 2019
Commented: Rik on 18 Nov 2019
The problem: a traveling salesman wants to visit all cities of a given together, and route distances between the various cities are known. Consider now the problem, starting and ending in a given city, determining the route to be taken by the traveling salesman who, once passing through the remaining cities, minimizes the total distance to be traveled. This problem will be developed using the neighbor's heuristic closest to go by choosing how next city to visit that that, among the cities not yet visited, is closest to the city where you are. This heuristic can be used in the traveling salesman problem. last city visited to the city of origin. The project consists of developing a menu application that allows the any user to use the resolution of this problem.
One of the menu options is' Show Affections' and for that we have to perform a function called 'prints? to show in the command window the allocations with their costs and the total cost. What is shown should respect this format:
route.png

  5 Comments

Show 2 older comments
Carolina Silva
Carolina Silva on 18 Nov 2019
I choose 5 citys and here it is the matrix
route.png
Carolina Silva
Carolina Silva on 18 Nov 2019
I already have a function:
funçao.png
Rik
Rik on 18 Nov 2019
We can't run an image, so please post the code (use the tools explained here to format your code properly).
The code you posted seems to generate a list of city IDs, without the distances. It also will result in a random order, not the shortest distance. Another remark about this code: using length on a matrix is almost always a bad idea. In this case the matrix should be square, but this is not guaranteed. Never use length, either use numel if you need the number of elements in a vector, or use size(___,dim) if you want the size of an array along a specific dimension.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by