1 模型简介

【优化求解】基于NSGA2算法求解多目标优化问题4matlab代码_路径规划

【优化求解】基于NSGA2算法求解多目标优化问题4matlab代码_路径规划_02

2 部分代码


clc;

clear;

close all;


%% Problem Definition


data=load('mydata');

R=data.R;


model.R=R;

model.method='cvar';

model.alpha=0.95;


CostFunction=@(x) PortMOC(x,model);   % Cost Function


nVar=size(R,2);       % Number of Decision Variables


VarSize=[1 nVar];  % Size of Decision Variables Matrix


VarMin=0;     % Lower Bound of Variables

VarMax=1;     % Upper Bound of Variables


% Number of Objective Functions

nObj=numel(CostFunction(unifrnd(VarMin,VarMax,VarSize)));



%% NSGA-II Parameters


MaxIt=100;   % Maximum Number of Iterations


nPop=50;    % Population Size


pCrossover=0.7;             % Crossover Percentage

nCrossover=2round(pCrossovernPop/2); % Number of Parnets (Offsprings)


pMutation=0.4;             % Mutation Percentage

nMutation=round(pMutation*nPop);    % Number of Mutants


mu=0.02;          % Mutation Rate


sigma=0.1*(VarMax-VarMin); % Mutation Step Size



%% Initialization


empty_individual.Position=[];

empty_individual.Cost=[];

empty_individual.Out=[];

empty_individual.Rank=[];

empty_individual.DominationSet=[];

empty_individual.DominatedCount=[];

empty_individual.CrowdingDistance=[];


pop=repmat(empty_individual,nPop,1);


for i=1:nPop


 pop(i).Position=unifrnd(VarMin,VarMax,VarSize);


 [pop(i).Cost, pop(i).Out]=CostFunction(pop(i).Position);


end


% Non-Dominated Sorting

[pop, F]=NonDominatedSorting(pop);


% Calculate Crowding Distance

pop=CalcCrowdingDistance(pop,F);


% Sort Population

[pop, F]=SortPopulation(pop);



%% NSGA-II Main Loop


for it=1:MaxIt


 % Crossover

 popc=repmat(empty_individual,nCrossover/2,2);

 for k=1:nCrossover/2


   i1=randi([1 nPop]);

   p1=pop(i1);


   i2=randi([1 nPop]);

   p2=pop(i2);


   [popc(k,1).Position, popc(k,2).Position]=Crossover(p1.Position,p2.Position,VarMin,VarMax);


   [popc(k,1).Cost, popc(k,1).Out]=CostFunction(popc(k,1).Position);

   [popc(k,2).Cost, popc(k,2).Out]=CostFunction(popc(k,2).Position);


 end

 popc=popc(:);


 % Mutation

 popm=repmat(empty_individual,nMutation,1);

 for k=1:nMutation


   i=randi([1 nPop]);

   p=pop(i);


   popm(k).Position=Mutate(p.Position,mu,sigma,VarMin,VarMax);


   [popm(k).Cost, popm(k).Out]=CostFunction(popm(k).Position);


 end


 % Merge

 pop=[pop

    popc

    popm]; %#ok


 % Non-Dominated Sorting

 [pop, F]=NonDominatedSorting(pop);


 % Calculate Crowding Distance

 pop=CalcCrowdingDistance(pop,F);


 % Sort Population

 pop=SortPopulation(pop);


 % Truncate

 pop=pop(1:nPop);


 % Non-Dominated Sorting

 [pop, F]=NonDominatedSorting(pop);


 % Calculate Crowding Distance

 pop=CalcCrowdingDistance(pop,F);


 % Sort Population

 [pop, F]=SortPopulation(pop);


 % Store F1

 F1=pop(F{1});


 % Show Iteration Information

 disp(['Iteration ' num2str(it) ': Number of F1 Members = ' num2str(numel(F1))]);


 % Plot F1 Costs

 figure(1);

 PlotCosts(F1);

 pause(0.01);


end


%% Results

3 仿真结果

【优化求解】基于NSGA2算法求解多目标优化问题4matlab代码_参考文献_03

4 参考文献

[1]张利. NSGA2算法及其在电力系统稳定器参数优化中的应用[D]. 西南交通大学, 2013.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,有科研问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

【优化求解】基于NSGA2算法求解多目标优化问题4matlab代码_参考文献_04