Integer Permutation GA Fitness Function

2 views (last 30 days)
John Kandwe
John Kandwe on 15 Apr 2014
After developing an initial population of random integers, I am now facing the problem of linking the individual of each population to the fitness function and also the arguments to give to the fitness function. I have the following creation and fitness functions, but when I run the GA from the workspace it is giving the following error "Failure in initial user-supplied fitness function evaluation. GA cannot continue":
function pop = facilities_arrangement(NVARS,FitnessFcn,options)
%Creates a population of facility arrangement permutations.
totalPopulationSize = 50;
n = NVARS;
pop = cell(totalPopulationSize,1);
for i = 1:totalPopulationSize
pop{i} = randperm(n);
end
function scores = facility_layout_fitness(CR,distances)
% Custom fitness function for the facility layout problem.
% Calculates the fitness of an individual. The fitness is the total product
% between the closeness rating of the facilities and the distances
% travelled from one facility to another from their centroids
% by using the rectilinear distance.
pop = cell(totalPopulationSize,1);
scores = zeros(size(pop,1),1);
totalPopulationSize = 50;
for i = 1:totalPopulationSize
order = pop{i};
A = CR(order,order);
TCF = sum(A(:).*distances(:));
scores(i) = TCF;
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!