matlab - Integer Permutation GA Fitness Function -
after developing initial population of random integers, facing problem of linking individual of each population fitness function , arguments give fitness function. have following creation , fitness functions, when run ga workspace giving following error "failure in initial user-supplied fitness function evaluation. ga cannot continue":
function pop = facilities_arrangement(nvars,fitnessfcn,options) %creates population of facility arrangement permutations. totalpopulationsize = 50; n = nvars; pop = cell(totalpopulationsize,1); = 1:totalpopulationsize pop{i} = randperm(n); end function scores = facility_layout_fitness(cr,distances) % custom fitness function facility layout problem. % calculates fitness of individual. fitness total product % between closeness rating of facilities , distances % travelled 1 facility centroids % using rectilinear distance. pop = cell(totalpopulationsize,1); scores = zeros(size(pop,1),1); totalpopulationsize = 50; = 1:totalpopulationsize order = pop{i}; = cr(order,order); tcf = sum(a(:).*distances(:)); scores(i) = tcf; end
you can call ga function without giving intial population.
but, if want use 1 (and agree it's idea) have sure initial population satisfies problem constraints, , it's enough solution start. way doing it, generating random population, bring solver.
you can call:
x = ga(fitnessfcn,nvars) if facility location problem, seems, should use kind of greedy algorithm try generate feasible solution feed genetic algorithm.
Comments
Post a Comment