优化算法晶体结构算法含Matlab源码 1800期

Posted 紫极神光

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了优化算法晶体结构算法含Matlab源码 1800期相关的知识,希望对你有一定的参考价值。

一、获取代码方式

获取代码方式1:
完整代码已上传我的资源:【优化算法】晶体结构算法【含Matlab源码 1800期】

二、部分源代码

% ----------------------------------------------------------------------- %
%% CryStAl for Unconstrained Benchmark Problems

%%
clc;clear all;                                                              
%% Get Required Problem Information
ObjFuncName = @(x) Sphere(x); % @CostFunction ;
Var_Number = 100 ; % Number of variables ;
LB = -10 *ones(1,Var_Number) ;  % Lower bound of variable ;
UB = 10 *ones(1,Var_Number) ;  % Upper bound of variable ;
%% Get Required Algorithm Parameters
MaxIteation = 1000 ; % Maximum number of Iterations ;
Cr_Number = 10 ; % Maximum number of initial Crystals ;
%% Outputs:
% BestCr        (Best solution)
% BestFitness     (final Best fitness)
% Conv_History    (Convergence History Curve)
%% Updating the Size of ProblemParameters
if length(LB)==1
    LB=repmat(LB,1,Var_Number);
end
if length(UB)==1
    UB=repmat(UB,1,Var_Number);
end
%% Initialization
% Initializing the Position of first probs
for i=1:Cr_Number
    Crystal(i,:)=unifrnd(LB,UB);
    % Evaluating the initial probs
    Fun_eval(i)=feval(ObjFuncName,Crystal(i,:));
end
% The best Crystal
[BestFitness,idbest]=min(Fun_eval);
Crb=Crystal(idbest,:);
% Number of Function Evaluations
Eval_Number=Cr_Number;
%% Search Process
Iter=1;
while Iter<MaxIteation
    for i=1:Cr_Number
        %% Generate New Crystals
        % Main Crystal
        Crmain=Crystal(randperm(Cr_Number,1),:);
        % Random-selected Crystals
        RandNumber=randperm(Cr_Number,1);
        RandSelectCrystal=randperm(Cr_Number,RandNumber);
        % Mean of randomly-selected Crystals
        Fc=mean(Crystal(RandSelectCrystal,:)).*(length(RandSelectCrystal)~=1)...
            +Crystal(RandSelectCrystal(1,1),:)*(length(RandSelectCrystal)==1);   
        % Random numbers (-1,1)
       r=2*rand-1;       r1=2*rand-1;
       r2=2*rand-1;     r3=2*rand-1;        
        % New Crystals
       NewCrystal(1,:)=Crystal(i,:)+r*Crmain;
       NewCrystal(2,:)=Crystal(i,:)+r1*Crmain+r2*Crb;
       NewCrystal(3,:)=Crystal(i,:)+r1*Crmain+r2*Fc;
       NewCrystal(4,:)=Crystal(i,:)+r1*Crmain+r2*Crb+r3*Fc;

        for i2=1:4
            % Checking/Updating the boundary limits for Crystals
            NewCrystal(i2,:)=bound(NewCrystal(i2,:),UB,LB);
            % Evaluating New Crystals
            Fun_evalNew(i2)=feval(ObjFuncName, NewCrystal(i2,:));
            % Updating the Crystals
            if Fun_evalNew(i2)<Fun_eval(i)
                Fun_eval(i)=Fun_evalNew(i2);
                Crystal(i,:)=NewCrystal(i2,:);
            end
            % Updation the Number of Function Evalutions
            Eval_Number=Eval_Number+1;
        end
    end % End of One Iteration
    Iter=Iter+1;
   % The best Crystal
    [BestFitness,idbest]=min(Fun_eval);
    Crb=Crystal(idbest,:);
    BestCr=Crb;
    Conv_History(Iter)=BestFitness;
    % Show Iteration Information
    disp(['Iteration ' num2str(Iter) ': Best Cost = ' num2str(Conv_History(Iter))]);
end % End of Main Looping
semilogy(Conv_History)



三、运行结果

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.

以上是关于优化算法晶体结构算法含Matlab源码 1800期的主要内容,如果未能解决你的问题,请参考以下文章

优化预测基于matlab遗传算法优化GRNN数据回归拟合含Matlab源码 1401期

优化算法蚱蜢优化算法(GOA)含Matlab源码 1070期

优化算法正弦余弦算法(SCA)含Matlab源码 1308期

优化算法粒子群工具箱函数优化算法含Matlab源码 1126期

优化算法龙格-库塔优化算法含Matlab源码 1799期

优化分类基于matlab粒子群算法优化SVM分类含Matlab源码 1588期