How can i solve this problem?

11 ビュー (過去 30 日間)
Carolina Silva
Carolina Silva 2019 年 11 月 18 日
コメント済み: Rik 2019 年 11 月 18 日
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 件のコメント
Carolina Silva
Carolina Silva 2019 年 11 月 18 日
I already have a function:
funçao.png
Rik
Rik 2019 年 11 月 18 日
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.

サインインしてコメントする。

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by