clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
model=SelectModel(); % Select Model
CostFunction=@(xhat) MyCost(xhat,model); % Cost Function
VarSize=[model.N model.N]; % Decision Variables Matrix Size
nVar=prod(VarSize); % Number of Decision Variables
VarMin=0; % Lower Bound of Decision Variables
VarMax=1; % Upper Bound of Decision Variables
% Harmony Search
MaxIt = 300; % Maximum Number of Iterations
HMS = 60; % Harmony Memory Size
nNew = 20; % Number of New Harmonies
HMCR = 0.9; % Harmony Memory Consideration Rate
PAR = 0.1; % Pitch Adjustment Rate
FW = 0.02*(VarMax-VarMin); % Fret Width (Bandwidth)
FW_damp = 0.995; % Fret Width Damp Ratio
% Initial
% Empty Harmony Structure
empty_harmony.Position = [];
empty_harmony.Cost = [];
empty_harmony.Sol = [];
% Initialize Harmony Memory
HM = repmat(empty_harmony, HMS, 1);
% Create Initial Harmonies
for i = 1:HMS
HM(i).Position = unifrnd(VarMin, VarMax, VarSize);
[HM(i).Cost HM(i).Sol]= CostFunction(HM(i).Position);
end
% Sort Harmony Memory
[~, SortOrder] = sort([HM.Cost]);
HM = HM(SortOrder);
% Update Best Solution Ever Found
BestSol = HM(1);
% Array to Hold Best Cost Values
BestCost = zeros(MaxIt, 1);
% Harmony Search Body
for it = 1:MaxIt
% Initialize Array for New Harmonies
NEW = repmat(empty_harmony, nNew, 1);
% Create New Harmonies
for k = 1:nNew
% Create New Harmony Position
NEW(k).Position = unifrnd(VarMin, VarMax, VarSize);
for j = 1:nVar
if rand <= HMCR
% Use Harmony Memory
i = randi([1 HMS]);
NEW(k).Position(j) = HM(i).Position(j);
end
% Pitch Adjustment
if rand <= PAR
%DELTA = FW*unifrnd(-1, +1); % Uniform
DELTA = FW*randn(); % Gaussian (Normal)
NEW(k).Position(j) = NEW(k).Position(j)+DELTA;
end
end
% Apply Variable Limits
NEW(k).Position = max(NEW(k).Position, VarMin);
NEW(k).Position = min(NEW(k).Position, VarMax);
% Evaluation
[NEW(k).Cost NEW(k).Sol]= CostFunction(NEW(k).Position);
end
% Merge Harmony Memory and New Harmonies
HM = [HM
NEW]; %#ok
% Sort Harmony Memory
[~, SortOrder] = sort([HM.Cost]);
HM = HM(SortOrder);
% Truncate Extra Harmonies
HM = HM(1:HMS);
% Update Best Solution Ever Found
BestSol = HM(1);
% Store Best Cost Ever Found
BestCost(it) = BestSol.Cost;
% Show Iteration Information
disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(BestCost(it))]);
% Damp Fret Width
FW = FW*FW_damp;
% Plot it
figure(1);
PlotSol(BestSol.Sol,model);
pause(0.01);
grid on;
end
title('HS Res');
% Plot itr
figure;
plot(BestCost,'k','LineWidth', 2);
xlabel('No of Iteration');
ylabel('HS Best Cost');
grid on;
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1.版本:matlab2021a,包含仿真操作录像,操作录像使用windows media player播放。 2.领域:多中心点选址优化 3.内容:基于和声搜索算法的多中心点选址优化matlab仿真 4.运行注意事项:注意MATLAB左侧当前文件夹路径,必须是程序所在文件夹位置,具体可以参考视频录。 5.适用人群:本硕博等科研学习参考使用。
资源推荐
资源详情
资源评论
收起资源包目录
基于和声搜索算法的多中心点选址优化matlab仿真.rar (10个子文件)
基于和声搜索算法的多中心点选址优化matlab仿真
matlab
func
PlotSol.m 563B
MyCost.m 120B
CreateRandomSolution.m 75B
SelectModel.m 280B
ParseSolution.m 913B
Runme.m 3KB
dat.mat 7KB
11.jpg 25KB
22.jpg 43KB
操作录像0038.avi 13.36MB
共 10 条
- 1
资源评论
fpga和matlab
- 粉丝: 16w+
- 资源: 2561
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功