clc;
clear;
close all;
%导入数据
load maydata.mat
%% Problem Definition
CostFunction=@(x,x1) fun(x,x1); % 适应度函数
nVar=24; % Number of Decision Variables
VarSize=[1 nVar]; % Size of Decision Variables Matrix
ct = [0.4 0.4 0.4 0.4 0.4 0.4 0.4 2 2 2 2 1.2 1.2 1.2 2 2 2 2 2 1.2 1.2 1.2 1.2 1.2];
ita = (max(ct)-min(ct))/max(ct);
VarMin= -3000*ones(1,24);
VarMax = 3000*ones(1,24);
% VarMin=[56 8 23 800 6 4 14];%下限r1 h1 h2 N r2 r3 r4
% VarMax=[65 12 27 3200 12 8 18]; % 上限
%% MOPSO Parameters
MaxIt=300; %最大迭代次数
nPop=200; % 种群数目
nRep=50; % 帕累托解集数目
w=0.5; % 惯性权重
wdamp=0.99; % 权重变化率
c1=2; %个体学习因子
c2=2; % 群体学习因子
nGrid=7; % 每维网格数目
alpha=0.2; % 边界扩展系数
beta=2; % Leader Selection Pressure
gamma=2; % Deletion Selection Pressure
mu=0.1; % Mutation Rate
%% 初始化
empty_particle.Position=[];
empty_particle.Velocity=[];
empty_particle.Cost=[];
empty_particle.Best.Position=[];
empty_particle.Best.Cost=[];
empty_particle.IsDominated=[];
empty_particle.GridIndex=[];
empty_particle.GridSubIndex=[];
pop=repmat(empty_particle,nPop,1);
p1 = [];
for ii=1:nPop
pop(ii).Position=unifrnd(VarMin,VarMax,VarSize);%粒子位置
pop(ii).Velocity=zeros(VarSize);%粒子速度
% pop(ii).Cost=CostFunction(pop(ii).Position);%适应度值
p1 = [p1;pop(ii).Position];
pop(ii).Best.Position=pop(ii).Position;
end
pcost1 = CostFunction(p1,x1);%适应度值
for ii = 1:nPop
pop(ii).Cost=pcost1(:,ii);%适应度值
pop(ii).Best.Cost=pop(ii).Cost;
end
% 支配解集
pop=DetermineDomination(pop);
rep=pop(~[pop.IsDominated]);
Grid=CreateGrid(rep,nGrid,alpha);
for ii=1:numel(rep)
rep(ii)=FindGridIndex(rep(ii),Grid);
end
%% 主循环
for it=1:MaxIt
p2 = [];
p3 = [];
p4 = [];
p5 = [];
p6 = [];
pcost2 = [];
for ii=1:nPop
leader=SelectLeader(rep,beta);%
pop(ii).Velocity = w*pop(ii).Velocity ...
+c1*rand(VarSize).*(pop(ii).Best.Position-pop(ii).Position) ...
+c2*rand(VarSize).*(leader.Position-pop(ii).Position);
pop(ii).Position = pop(ii).Position + pop(ii).Velocity;
pop(ii).Position = max(pop(ii).Position, VarMin);
pop(ii).Position = min(pop(ii).Position, VarMax);
% pop(ii).Cost = CostFunction(pop(ii).Position);
p2 = [p2;pop(ii).Position];
% Apply Mutation
pm=(1-(it-1)/(MaxIt-1))^(1/mu);
if rand<pm
NewSol.Position=Mutate(pop(ii).Position,pm,VarMin,VarMax);
p3 = [p3; NewSol.Position];
p4 = [p4;ii];
NewSol.Cost=CostFunction(NewSol.Position,x1);
if Dominates(NewSol,pop(ii))
pop(ii).Position=NewSol.Position;
pop(ii).Cost=NewSol.Cost;
elseif Dominates(pop(ii),NewSol)
% Do Nothing
else
if rand<0.5
pop(ii).Position=NewSol.Position;
pop(ii).Cost=NewSol.Cost;
end
end
end
end
p5 = [p2;p3];
pcost2 = CostFunction(p5,x1);%适应度值
for ii = 1:nPop
pop(ii).Cost=pcost2(:,ii);%适应度值
end
p6 = pcost2(:,nPop+1:end);
% isempty(p6)
pan = 1;
for ii = 1:nPop
if ~isempty(p6) && ii == p6(pan)
NewSol.Position=Mutate(pop(ii).Position,pm,VarMin,VarMax);
NewSol.Cost=p6(:,pan);
pan = pan + 1;
if Dominates(pop(ii),pop(ii).Best)
pop(ii).Best.Position=pop(ii).Position;
pop(ii).Best.Cost=pop(ii).Cost;
elseif Dominates(pop(ii).Best,pop(ii))
% Do Nothing
else
if rand<0.5
pop(ii).Best.Position=pop(ii).Position;
pop(ii).Best.Cost=pop(ii).Cost;
end
end
end
end
% 将非支配粒子添加到储存库中
rep=[rep;pop(~[pop.IsDominated])]; %#ok
% 确定新的非劣解解集
rep=DetermineDomination(rep);
% Keep only Non-Dminated Memebrs in the Repository
rep=rep(~[rep.IsDominated]);
% Update Grid
Grid=CreateGrid(rep,nGrid,alpha);
% Update Grid Indices
for ii=1:numel(rep)
rep(ii)=FindGridIndex(rep(ii),Grid);
end
% Check if Repository is Full
if numel(rep)>nRep
Extra=numel(rep)-nRep;
for e=1:Extra
rep=DeleteOneRepMemebr(rep,gamma);
end
end
% if it==MaxIt
figure(1);
PlotCosts(pop,rep);
pause(0.01);
% end
%
% Show Iteration Information
disp(['Iteration ' num2str(it) ': Number of Rep Members = ' num2str(numel(rep))]);
% Damping Inertia Weight
w=w*wdamp;
% if it == MaxIt
% % hold on
% plot3(T_test(1,:),T_test(2,:),T_test(3,:),'ko')
% end
end
![avatar](https://profile-avatar.csdnimg.cn/3165706ad4e540aeb062dd5ebcf069a7_abc991835105.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
神经网络机器学习智能算法画图绘图
- 粉丝: 2857
- 资源: 660
最新资源
- 基于Java和Shell开发的作物智慧检测全国管理系统后端设计源码
- 非线性磁链观测器源码详解:VESC无感观测器与PLL结合,附详细注释、文献出处及仿真模型,非线性磁链观测器源码详解:VESC无感观测器与PLL结合,含详细注释、参考文献及Simulink仿真模型,非线
- 基于Java开发的MV架构设计源码
- 基于SVM代理模型的电机多目标优化:平均转矩、转矩脉动及推力径向优化的高精度实现,基于SVM代理模型的电机多目标优化:平均转矩、转矩脉动及推力径向优化的高精度实现,基于支持向量机(SVM)代理模型的
- 基于深度神经网络DNN多输出回归预测系统的优化与实践:一份适合新手的程序开发与调试指南,基于深度神经网络DNN的多输出回归预测模型:程序调试完成,轻松替换数据运行源程序,DNN多输出回归 基于深度神经
- 基于Vue与TypeScript的东智智慧网格设计源码演示项目
- 基于ThinkPHP5.0框架的学员答疑系统设计源码
- 三菱FX3U PLC与台达DT330温控器通讯控制启停功能的实用解决方案,三菱FX3U PLC与台达DT330温控器通讯控制系统的设计与实现-基于昆仑通态触摸屏的输出启停(SL3U-2)功能应用,三
- 基于Python、HTML、JavaScript、CSS的Estimation项目设计源码
- 基于TypeScript、Vue、CSS、HTML的前端管理端比赛设计源码
- 基于Springboot+Mybatis+MySQL的在线书店管理系统设计源码
- COMSOL模拟沸腾水中气泡运动的两相流流体传热与蒸汽冷凝案例研究,COMSOL多物理场模拟:沸腾水中气泡运动两相流流体传热与蒸汽冷凝的案例研究,COMSOL案例模拟沸腾水中气泡运动两相流流体传热蒸汽
- 基于Vue框架的学生就业画像分析前端设计源码
- PatchTST模型:自监督时间序列预测的革新与高精度应用,PatchTST模型:基于Transformer的自监督时间序列预测模型,单多输入输出兼顾,局部特征与多维序列的精确表征,PatchTST模
- 基于公式法的永磁同步电机弱磁与MTPA结合控制研究:电流环仿真步骤及参数影响分析 ,永磁同步电机公式法计算:MTPA与弱磁结合,从内环到外环的仿真解析及参数影响分析(结合MATLAB工具及特定电机参数
- 基于CSS、PHP、JavaScript、HTML的陕西省无人机协会网站设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)