怎样用matlab 遗传算法 计算出来的? 请资深人士帮忙写一下程序。这是怎么出来的?
来源:百度知道 编辑:UC知道 时间:2024/09/21 17:40:44
ID x轴坐标(km) y轴坐标(km) 需求量(T) ID x轴坐标(km) y轴坐标(km) 需求量(T)
1 12.8 8.5 0.1 11 6.7 16.9 0.9
2 18.4 3.4 0.4 12 14.8 2.6 1.3
3 15.4 16.6 1.2 13 1.8 8.7 1.3
4 18.9 15.2 1.5 14 17.1 11.0 1.9
5 15.5 11.6 0.8 15 7.4 1.0 1.7
6 3.9 10.6 1.3 16 0.2 2.8 1.1
7 10.6 7.6 1.7 17 11.9 19.8 1.5
8 8.6 8.4 0.6 18 13.2 15.1 1.6
9 12.5 2.1 1.2 19 6.4 5.6 1.7
10 13.8 5.2 0.4 20 9.6 14.8 1.5
表3 客户位置坐标及货物需求量
我们计算10次的结果如下:
次序 1 2 3 4 5 6 7 8 9 10
总距离 113.0 109.6 110.2 111.7 110.4 111.2 109.1 109.6 107.8 110.4
表4 计算结果及具体方案
%建立m文件create_permutations.m
%------------------------------------------
function pop = create_permutations(NVARS,FitnessFcn,options)
totalPopulationSize = sum(options.PopulationSize);
n = NVARS;
pop = cell(totalPopulationSize,1);
for i = 1:totalPopulationSize
pop{i} = randperm(n);
end
%------------------------------------------
%crossover_permutation.m
function xoverKids = crossover_permutation(parents,options,NVARS, ...
FitnessFcn,thisScore,thisPopulation)
nKids = length(parents)/2;
xoverKids = cell(nKids,1); % Normally zeros(nKids,NVARS);
index = 1;
for i=1:nKids
% here is where the special knowledge that the population is a cell
% array is used. Normally, this would be thisPopulation(parents(index),:);
parent = thisPopulation{parents(index)};
index = index + 2;
% Flip a section of parent1.
p1 = ceil((len