1 Star 6 Fork 2

wanglei1896 / 机械臂运动规划

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
trajectory_planningf_GA.m 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
Wang Lei 提交于 2019-08-07 20:34 . 总之好久没提交了。。。
function [x_result,f_result,cost_time,it] = trajectory_planningf_GA(para,pops,maxgen,fitnessf,interplot,sumplot)
%GA需解耦部分:
%解向量编码
%适应函数 fitnessf
%绘图展示数据部分
global bound rng
if nargin==5
sumplot=interplot;
end
%GA parameters
% pops=50;
crossprop=0.90;
mutprop=0.05;
% maxgen=200;
%initialization
numvar=size(bound,1);
rng=(bound(:,2)-bound(:,1))';
pop=zeros(pops,numvar);
% pop = ones(pops,1)*[-0.929115748796937,1.51672911292210,1.99474036827404,0.785398163397448,-0.0904302695568150,-0.143345191582938,2.57246342182134,1.87165628967900,0.0727427807745007,0.602902333253355];
pop(:,1:numvar)=(ones(pops,1)*rng).*(rand(pops,numvar))+...
(ones(pops,1)*bound(:,1)');
% bsol_store=zeros(maxgen,numvar);
tic
it=1;
while it<5 || (norm(bsol_store(it-1,:)-bsol_store(it-2,:))+norm(bsol_store(it-2,:)-bsol_store(it-3,:))...
+norm(bsol_store(it-3,:)-bsol_store(it-4,:)))/(3*norm(bsol_store(it-1,:)))>0.0001
fpop=fitnessf(pop, para);
[bfit,inds]=max(fpop);
maxf(it)=bfit;
bsol=pop(inds,:); % best solution.
bsol_store(it,:)=bsol;
% tournament selection
toursize=5;
players=ceil(pops*rand(pops,toursize));
scores=fpop(players);
[a,m]=max(scores');
pind=zeros(1,pops);
for ii=1:pops
pind(ii)=players(ii,m(ii));
parent(ii,:)=pop(pind(ii),:);
end
%arithmatic crossover
offs=cross_singlepoint(parent,crossprop);
% offs=cross1(parent,crossprop);
%mutate1=uniform mutation.
moffs=mutate1(offs,mutprop);
pop=moffs;
%*************************plot results
if nargin==6
feval(interplot,para,bsol,1/bfit,it,maxgen);
pause(0)
end
it=it+1;
end
toc
if nargin>4
sumplot(it-1,maxf,bsol_store);
end
x_result = bsol;
f_result = 1/maxf(it-1);
cost_time = toc;
it=it-1;
end
1
https://gitee.com/wanglei1896/manipulator_motion_planning.git
git@gitee.com:wanglei1896/manipulator_motion_planning.git
wanglei1896
manipulator_motion_planning
机械臂运动规划
master

搜索帮助