Thread Subject: Fitness function

Subject: Fitness function

From: rawan

Date: 22 Apr, 2008 18:27:52

Message: 1 of 1

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

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com