Comparison of power flow calculation based on genetic algorithm and particle swarm algorithm (Matlab code implementation)

Table of contents

1 Overview

2 Particle Swarm Algorithm

3 Genetic Algorithm

4 Running results of power flow calculation

5 References

6 Matlab code implementation


1 Overview

Power system power flow refers to the totality of all operating parameters in the system, including the power and current of each generator and load, the magnitude and phase of each bus voltage, the current, power and loss of each line and transformer.
The power flow calculation is based on the known grid structure and operating conditions to determine the system's operating form and analyze the system's steady-state operation. It is an important subject of long-term research in electrical engineering.

This article explains the comparison of power flow calculation based on genetic algorithm and particle swarm algorithm (Matlab code implementation)

2 Particle Swarm Algorithm

Inspired by the model of Reynols and Heppner, in 1995, Russell Eherhart, Ph.D. of Electronic Engineering, and James Kennedy, Ph.D. of Social Psychology, proposed the particle swarm algorithm [3-4]. The behavior of finding the food position to solve the problem. In this algorithm, the position of the bird’s food corresponds to the position of the problem space solution, and the bird corresponds to a “particle” without mass and volume. The information sharing of the bird during the foraging process Corresponding to the information sharing and mutual cooperation between particles, the particles adjust the direction and speed of motion while sharing information, so as to quickly search for the optimal solution.    

                                         Figure 1 Flow chart of particle swarm optimization algorithm

3 Genetic Algorithm

The genetic algorithm has many advantages: (1) It can be searched globally, and it is not easy to fall into a local optimal solution; (2) The coding is diversified, and many problems can be solved by the genetic algorithm; (3) It can be searched randomly in parallel, and the search range is gradually reduced; (4) The fitness function is very flexible, it can be discrete or continuous, and there is no limit to the derivative and differentiation; (5) Genetic algorithm can also be used for very complex problems, and the results are reliable; (6) Compatibility and scalability are strong , can be used in combination with many other algorithms. With the advancement of technology and the deepening of the research on various algorithms, the defects of many algorithms are more obvious to a certain extent. If you want to avoid the defects of a certain algorithm, it can be combined with other algorithms to form a new Algorithm is a good method, and genetic algorithm is a better cooperative algorithm.

4 Running results of power flow calculation


Part of the code:

%% 基于遗传算法和粒子群算法的潮流计算比较(Matlab代码实现)
clc;
clear;
close all;
%% 随机数种子
rng('default')
rng(1)
%%
addpath(genpath('matpower7.0'))
%%
data.mpc=case9;
data.numBranch=length(data.mpc.branch(:,1));
data.distance=xlsread('线型.xlsx',2);
data.Line=xlsread('线型.xlsx',1);
data.numLine=length(data.Line(:,1));
data.base=100;
data.lamdaLoss=25; %损耗成本系数
%% 算法参数设置
dim=data.numBranch;
%%
lb=zeros(1,dim);
ub=ones(1,dim);
fobj=@aimFcn_1;
option.lb=lb; %下限
option.ub=ub; %上限
option.dim=dim;%决策变量个数
if length(option.lb)==1 %判断是否成立,如果成立就往下进行
    option.lb=ones(1,option.dim)*option.lb; %统一长度,每个决策变量对应一个lb和ub
    option.ub=ones(1,option.dim)*option.ub; %统一长度,每个决策变量对应一个lb和ub
end
option.fobj=fobj;
option.showIter=0;
%% 算法参数设置
% 基本参数
option.numAgent=20;        %初始解个体数 越大越好
option.maxIteration=20;    %最大迭代次数 越大越好
option.popSize=option.numAgent;
option.lenTS=option.numAgent*5;  %禁忌长度
% 遗传算法
option.p1_GA=0.85;
option.p2_GA=0.1;
% 粒子群算法
option.w_pso=0.1;
option.c1_pso=1;
option.c2_pso=1;
str_legend=[{'GA'},{'PSO'}];
%% 初始化种群个体
x=ones(option.numAgent,option.dim);
y=ones(option.numAgent,1);
for i=1:option.numAgent
    x(i,:)=option.lb+rand(1,option.dim).*(option.ub-option.lb);
    [y(i),~,x(i,:)]=option.fobj(x(i,:),option,data);
end
% 使用算法求解
rng(1)
[bestY(1,:),bestX(1,:),recording(1)]=GA(x,y,option,data);
rng(1)
[bestY(2,:),bestX(2,:),recording(2)]=PSO(x,y,option,data);
%%
figure
hold on
for i=1:length(recording)
    plot((recording(i).bestFit),'LineWidth',2)
end
xlabel('迭代次数')
ylabel('适应度值')
legend(str_legend)
title('适应度函数曲线')

%% 输出结果
str='GA算法优化结果'
[~,result1]=option.fobj(bestX(1,:),option,data);
str='PSO算法优化结果'
[~,result2]=option.fobj(bestX(2,:),option,data);
str='随机方案'
[~,result5]=option.fobj(bestX(2,:)*0+1,option,data);

5 References

Part of the theoretical literature comes from online literature, if there is any infringement, please contact to delete.

[1] Liu Jianhua. The basic theory and improvement research of particle swarm algorithm [D]. Changsha: Central South University, 2009.

[2] Sun Ruxiang. Hybrid Research of Particle Swarm and Genetic Algorithm [D]. Nanning: Guangxi University, 2014.

[3] Pang Feilong. Fuzzy control wire feeding system based on genetic algorithm [D]. Beijing: China University of Geosciences, 2015.

6 Matlab code implementation

Reply: Comparison of Power Flow Calculation Based on Genetic Algorithm and Particle Swarm Optimization

Guess you like

Origin blog.csdn.net/weixin_61181717/article/details/127962498