资源简介
matlab写的教学优化算法(teaching learning based optimization),测试过,很好用!
代码片段和文件信息
%
% Copyright (c) 2015 Yarpiz (www.yarpiz.com)
% All rights reserved. Please read the “license.txt“ for license terms.
%
% Project Code: YPEA111
% Project title: Implementation of TLBO in MATLAB
% Publisher: Yarpiz (www.yarpiz.com)
%
% Developer: S. Mostapha Kalami Heris (Member of Yarpiz Team)
%
% Contact Info: sm.kalami@gmail.com info@yarpiz.com
%
clc;
clear;
close all;
%% Problem Definition
% Cost Function
CostFunction = @(x) Sphere(x);
nVar = 10; % Number of Unknown Variables
VarSize = [1 nVar]; % Unknown Variables Matrix Size
VarMin = -10; % Unknown Variables Lower Bound
VarMax = 10; % Unknown Variables Upper Bound
%% TLBO Parameters
MaxIt = 1000; % Maximum Number of Iterations
nPop = 50; % Population Size
%% Initialization
% Empty Structure for Individuals
empty_individual.Position = [];
empty_individual.Cost = [];
% Initialize Population Array
pop = repmat(empty_individual nPop 1);
% Initialize Best Solution
BestSol.Cost = inf;
% Initialize Population Members
for i=1:nPop
pop(i).Position = unifrnd(VarMin VarMax VarSize);
pop(i).Cost = CostFunction(pop(i).Position);
if pop(i).Cost < BestSol.Cost
BestSol = pop(i);
end
end
% Initialize Best Cost Record
BestCosts = zeros(MaxIt1);
%% TLBO Main Loop
for it=1:MaxIt
% Calculate Population Mean
Mean = 0;
for i=1:nPop
Mean = Mean + pop(i).Position;
end
Mean = Mean/nPop;
% Select Teacher
Teacher = pop(1);
for i=2:nPop
if pop(i).Cost < Teacher.Cost
Teacher = pop(i);
end
end
% Teacher Phase
for i=1:nPop
% Create Empty Solution
newsol = empty_individual;
% Teaching Factor
TF = randi([1 2]);
评论
共有 条评论