|
I have a problem with my fitness function in matlab,
i want to generate a round trip of 30 cities but when i run the program it does not close the loop it only makes 29 lines and does not continue to the 30th city.
I know that the problem is with the fitness function, this is the code:
function scores = traveling_salesman_fitness(x,distances)
scores = zeros(size(x,1),1);
for j = 1:size(x,1)
% here is where the special knowledge that the population is a cell
% array is used. Normally, this would be pop(j,:);
p = x{j};
f = ceil(distances(p(end),p(1)));
for i = 2:length(p)
f = f + distances(p(i),p(i-1));
end
scores(j) = f ;
end
|