遗传算法求解迷宫问题的matlab代码——greatji_1994
来源:互联网 发布:怎么在淘宝头条上发帖 编辑:程序博客网 时间:2024/06/06 02:16
转载请说明出处,尊重原创
function []=untitled()
global ifthrough sample waysign
sample = 20;
ifthrough = zeros(1,sample);
waysign = zeros(100,sample);
Mazz = [0 1 0 0 1 0 0 1 1 0 1;
0 0 0 0 0 1 0 0 1 1 0;
0 0 0 0 0 0 0 1 0 0 0;
0 1 0 0 1 0 0 0 0 1 1;
0 0 1 0 0 0 0 1 1 1 0;
1 0 0 0 1 0 0 0 1 0 1;
0 0 1 0 0 0 0 0 1 0 1;
1 0 0 0 0 1 0 0 0 0 1;
1 1 0 0 1 1 0 1 0 1 0;
1 1 1 0 0 0 0 0 0 0 0]
initx=1;
inity=1;
termx=10;
termy=10;
pc = 0.4;
pm = 0.3;
Generation = zeros(100,sample);
for k=1:1:sample
Generation(:,k) = fix(4*rand(100,1));
end
fitness = Cal_fitness(Mazz,initx,inity,termx,termy,Generation)
for t=0:1:1000
if(rand(1,1) < pc)
Generation = Crossover(Generation,fitness);
end
fitness = Cal_fitness(Mazz,initx,inity,termx,termy,Generation);
if(rand(1,1) < pm)
Generation = Mutation(Generation);
end
fitness = Cal_fitness(Mazz,initx,inity,termx,termy,Generation);
end
Generation;
fitness
for t=1:1:sample
if fitness(1,t) == 10*sqrt(2)
Generation(:,t)'
end
end
end
function f = Cal_fitness(Mazz,initx,inity,termx,termy,Generation)
global ifthrough sample
f = zeros(1,sample);
for s=1:1:sample
posx=initx;
posy=inity;
expresslength=1;
while posy <= 10 && posy >=1 && posx <= 10 && posx >= 1 && Mazz(posy,posx) == 0
if Generation(expresslength,s) == 0
posy = posy + 1;
elseif Generation(expresslength,s) == 1
posy = posy - 1;
elseif Generation(expresslength,s) == 2
posx = posx + 1;
elseif Generation(expresslength,s) == 3
posx = posx - 1;
end
expresslength = expresslength + 1;
end
if(posx == termx && posy == termy)
f(1,s) = 10*sqrt(2);
ifthrough(1,s) = 1;
Generation(:,s)'
Generation(:,s) = fix(4 * rand(1,100));
else
f(1,s) = 10*sqrt(2) - sqrt((10 - posx)^2 + (10 - posx)^2);
end
end
end
function r = Round_choose(fitness)
total = sum(fitness,2);
Possibility = fitness ./ total;
m = 0;
ran = rand(1,1);
i = 0;
while ran > m
i = i + 1;
m = m + Possibility(1,i);
end
r = i;
end
function c = Crossover(Generation,fitness)
global sample
c = Generation;
for k=1:1:sample
Choice = [Round_choose(fitness),Round_choose(fitness)];
if(fitness(1,Choice(1)) <= 100)
head = fix(100*rand(1,1)+1);
tail = fix((100-head)*rand(1,1))+head;
temp2 = Generation(:,Choice(2));
temp2 = temp2(head:tail,:);
c(:,k) = Generation(:,Choice(1));
c(head:tail,k) = temp2;
else
c(:,k) = Generation(:,Choice(1));
end
end
end
function m = Mutation(Generation)
global sample
m = Generation;
for s=1:1:sample
m(fix(100 * rand(1,1)) + 1, s) = fix(4 * rand(1,1));
end
end
- 遗传算法求解迷宫问题的matlab代码——greatji_1994
- Matlab遗传算法优化问题求解的示例代码
- 遗传算法的应用(求解迷宫问题)
- 遗传算法 求解旅行商 TSP 问题,matlab代码
- Matlab 遗传算法求解TSP问题
- 遗传算法求解带非线性约束的单目标问题,matlab代码,基于K Deb的论文
- 遗传算法求解TSP问题的总结
- 遗传算法解迷宫问题
- 【人工智能】遗传算法(GA)入门—以求解一元函数最大值的优化问题为例
- 遗传算法求解TSP问题
- 遗传算法求解one_max问题
- 遗传算法求解TSP问题
- 遗传算法求解TSP问题
- 如何在matlab下是用遗传算法求解
- 最小费用最大流问题——greatji_1994
- 基于边缘重组的遗传算法求解TSP问题
- 迷宫问题的求解
- 遗传算法Java实现以及TSP问题遗传算法求解
- Shell学习一(基础知识)
- pb 直连sql anywhere数据库
- POJ 1852 Ants (思维技巧 + 贪心)
- c算法 ->递归函数
- [jenkins][git]jenkins CI初探
- 遗传算法求解迷宫问题的matlab代码——greatji_1994
- 工作周报030
- window 7下tomcat服务自启动
- Codeforces Round #289 Div. 2 解题报告 A.B.C.E
- TextView的省略号不显示 小bug解决
- CWR Mobile简介
- android获取传感器列表
- Android 图片高斯模糊处理
- Undefined symbols for architecture x86_64: