资源简介
回溯搜索算法,回溯算法也叫试探法,它是一种系统地搜索问题的解的方法。回溯算法的基本思想是:从一条路往前走,能进则进,不能进则退回来,换一条路再试。
代码片段和文件信息
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 回溯搜索(BSA)进行函数优化,
% 输入:popsize 种群个数,Dimsize 变量维数,pop=【pop1pop2...popi...popN】为种群集合,Maxgen 最大迭代次数,
% lowerboundary upperboundary分别为变量上下界,
% 输出: globalminimizerglobalminimum
function BSA()
clc;
clear all;
format long;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%% 给定初始化条件 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
popsize = 10; % 种群数目
Dimsize = 30; % 变量维数
Maxgen = 1000; % 最大的迭代次数
mixrate = 1; % 最大交叉概率
constant_F = 3;
lowerboundary = -100.*ones(1Dimsize) ;
upperboundary = 100.*ones(1Dimsize) ;
globalminimum = Inf;
%%%%%%%%%%%%%%%%%%%%%%%% 种群初始化 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1:popsize
pop( i:) = lowerboundary + rand(1Dimsize) .* (upperboundary - lowerboundary); % 初始化种群
oldpop( i:) = lowerboundary + rand(1Dimsize) .* (upperboundary - lowerboundary);
Fitpop(i) = fitness( pop(i:)Dimsize );
end
%%%%%%%%%%%%%%%%%%%%%%%%% 选择第一阶段 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for t = 1:Maxgen
for i =1:popsize
rand_a = rand;
rand_b = rand;
if rand_a < rand_b
oldpop(i:) = pop(i:);
else
oldpop = oldpop(randperm(popsize):);
oldpop = oldpop(:randperm(Dimsize));
end
end
%%%%%%%%%%%%%%%%%%%%% 变异 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1:popsize
trialpop(i:) = pop(i:) + constant_F .* randn .* (oldpop(i:)-pop(i:));
end
%%%%%%%%%%%%%%%%%%%%% 交叉 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
integer_matrix = ones(popsizeDimsize);
rand_c = rand;
rand_d = rand;
if rand_c < rand_d
number = ceil(mixrate * rand * Dimsize);
sequence = randperm(Dimsize);
for i = 1:popsize
for u = 1:number
j = sequence(u);
integer_matrix( ij ) = 0;
end
end
else
sequence = randperm(Dimsize);
for i = 1:popsize
j = sequence(1);
integer_matrix( ij ) = 0;
end
end
for i = 1:popsize
for j = 1:Dimsize
if integer_matrix( ij ) == 1
trialpop(ij) = pop(ij);
end
end
end
%%%%%%%%%%%%%%%%%%%% 边界检测 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1:popsize
for j = 1:Dimsize
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4490 2020-03-26 10:56 回溯搜索算法 matlab BSA.m.m
相关资源
- 度中心性算法
- EM算法在高斯混合模型中的应用有ma
- threeD_svpwm.mdl
- chan算法代码1234.m
- RRT、RRT-Connect、LazyRRT、RRTextend、RRT*的
- 这是一个用matlab实现的RBF神经网络手
- 基于MATLAB的KNN算法实现多分类.rar
- MATLAB遗传算法解决旅行商问题TSP、多
- 机器人避障算法的matlab仿真代码
- 蚁群算法进行二维路径规划.zip
- 基于粒子群算法的投影寻踪法matlab代
- 基于遗传模拟退火算法的模糊C均值聚
- 粒子群算法优化3-5-3多项式工业机器人
- NSGA-II算法实现
- kalmanfilter_fuben.slx
- 依据卫星星历计算坐标(含代码、数
- Matlab强化学习_网格迷宫问题_SarsaLam
- 粒子群算法应用在路径规划matlab
- 投影寻踪-遗传算法MATLAB程序
- GA遗传算法matlab程序
- 基于ATO的列车速度曲线优化
- BFGS算法的Matlab实现
- 模拟退火算法解决0-1背包问题
- 蚁群算法MATLAB代码287131
- TOPSIS的MATLAB算法实现
- census算法matlab程序
- 遗传算法对于模糊控制规则的优化用
- SVM分类器的相关算法和matlab源码
- 人工萤火虫算法
- 细菌觅食算法的函数优化-matlab
评论
共有 条评论