Home > other >  Matlab ant colony algorithm to solve TSP indexes exceed the number of array elements (0)
Matlab ant colony algorithm to solve TSP indexes exceed the number of array elements (0)

Time:01-08

In the city the number of minor (less than 200) code can run normally, when a number of cities become bigger, will be an error when a city under the roulette wheel selection:
Index exceeds the number of array elements (0),
Errors occur in the target=allow (target_index (1)); This

Ask you why such as urban larger cannot index number of problem? How to solve it, please?

Space is limited to only shows the section of code where the problem
% of each ant routing
For I=1: m
% for a choice for each ant
For j=2: n
Tabu Table of=(I, 1: (j - 1)); % have visited the city collection
Allow_index=~ ismember (citys_index, tabu); % not visited the city buy 1
Allow=citys_index (allow_index); % to visit the city collection
P=allow;
% to calculate transition probability between city
For k=1: length (allow)
P (k)=Tau (tabu (end), allow (k)) ^ alpha * Eta (tabu (end), allow (k)) ^ beta;
End
P=P/sum (P);
% roulette selection next visit the city
Pc=cumsum (P);
Target_index=find (Pc>=rand);
Target=allow (target_index (1));
The Table (I, j)=target; % down, join the Table, as the next of the cities visited
End
end
  • Related