Microgrid optimal dispatching based on particle swarm optimization algorithm, whale algorithm, and improved camel model algorithm (PSO/SSA/tGSSA) (Matlab code implementation)

Welcome to this blog

Advantages of bloggers:Blog content should be as thoughtful and logical as possible for the convenience of readers.

Motto:He who travels a hundred miles is half as good as ninety.

The directory of this article is as follows:

Table of Contents

1 Overview

2 Operation results

2.1 PSO operation results

2.2 tGSSA running results

2.3 SSA running results

3 References

4 Matlab code implementation


1 Overview

Microgrid is a small power system composed of multiple different energy resources and loads. Its optimal dispatch is to achieve reliable, efficient and economical energy management. Intelligent algorithms such as Particle Swarm Optimization (PSO), Whale Algorithm (SSA), and Improved Shading Camel Model Algorithm (tGSSA) can be used for optimal dispatching problems in microgrids.

These intelligent algorithms solve complex optimization problems by simulating certain behaviors in nature. In microgrid optimization dispatch, these algorithms can be used to locate the optimal configuration of each energy resource in the microgrid, optimize energy distribution, and load scheduling.

The PSO algorithm is based on simulating the foraging behavior of a flock of birds and finds the optimal solution through continuous search and iteration. It can be used to optimize energy resource allocation in microgrids, such as optimal placement of solar energy, wind energy, batteries, etc. and optimization of power generation plans.

The SSA algorithm is an optimization algorithm proposed based on whale foraging behavior and can be used for microgrid optimization scheduling problems. It simulates the whale’s foraging process and gradually adjusts the whale’s position to approximate the optimal solution. In microgrids, SSA can be used to optimize the power generation and load dispatch of each energy source in the microgrid to achieve efficient energy utilization and balance of supply and demand.

The tGSSA algorithm is an improvement and optimization of the GSSA algorithm, which improves search efficiency by introducing time transformation. In the optimal dispatch of microgrid, the tGSSA algorithm can be used to optimize the energy configuration and dispatch strategy of microgrid to achieve the best economy and reliability.

We use the improved particle swarm optimization (PSO) algorithm to solve the established mathematical model based on typical daily load parameters and natural parameters. Through this optimization process, we can formulate a time-based optimal dispatch plan and determine the output of the microgrid in the three stages of peak, valley and flat.

In addition, we also compared the comprehensive benefits of using conventional dispatch strategies and optimized dispatch strategies in microgrids. Through analysis and comparison, we are able to quantitatively evaluate the improvement effect of the optimized dispatch strategy in terms of economy, reliability and sustainability.

At the same time, based on the original PSO algorithm, we also introduced the whale algorithm (SSA) and the improved sand-sand camel model algorithm (tGSSA) for comparative research. By comparing with the PSO algorithm, we can evaluate the performance and effect of the SSA and tGSSA algorithms on the microgrid optimal dispatch problem.

During the verification process, we verified the correctness of the algorithm and the feasibility of the optimized scheduling solution. Through the processing of real data and simulation experiments, we can draw accurate conclusions and prove the effectiveness and feasibility of the optimized scheduling scheme.

Overall, this study provides a powerful solution for optimal dispatch of microgrids. By combining the improved PSO algorithm, SSA algorithm and tGSSA algorithm, and comprehensively analyzing the comprehensive benefits of micropower under different dispatch strategies, we can find the best dispatch plan to improve the economy, reliability and sustainability of microgrids. This research result will help promote the development of the microgrid field and provide strong support for practical applications.

In summary, microgrid optimal dispatch based on intelligent algorithms (such as PSO, SSA and tGSSA) can help achieve efficient utilization of microgrid energy, optimized energy distribution and reasonable load dispatching, thereby improving the reliability, economy and load of microgrids. Sustainability.

2 Running results

2.1 PSO operation results

2.2 tGSSA running results

2.3 SSA running results

Part of the code:

clc;
clear;
close all;
global costp Ppv Pwt
%% algorithm parameters
parameter;
nVar=4*24; % Number of Decision Variables
VarMin=[ones(1,24)*Pmt_min, ones(1,24)*Pfc_min, ones(1,24)*Px_min, ones(1,24)*Pb_min];
VarMax=[ones(1,24)*Pmt_max, ones(1,24)*Pfc_max, ones(1,24)*Px_max, ones(1,24)*Pb_max];
MaxIt=100; % Maximum Number of Iterations
nPop=500; % Population Size (Swarm Size)

%% calculate
[ bestPosition, fitValue ] = tGSSAFUN(@objective,nVar,VarMin,VarMax,MaxIt,nPop);
x=bestPosition;
Pmt = x(1:24); % gas turbine power
Pfc = x(25:48); % fuel cell power
Px = x(49:72); % can be unloaded
Pb = x(73:96); % battery power
t=1:24;

%% Output photovoltaic output forecast
figure
plot(t,Ppv,'-')
title('Photovoltaic power generation curve');
xlabel('time/hour')
ylabel('power/kw')
%% Output wind power output forecast
figure
plot(t,Pwt,'-')
title('Wind power generation curve');
xlabel('time/hour')
ylabel('power/kw')
%% Output electrical balance results
figure
hold on
Pb_po=max(Pb,0);
Pb_ne=min(Pb,0);
positive=[Pmt', Pfc', Pb_po',Px',Ppv',Pwt'];
negative=[ Pb_ne'];
bar(positive,'stack');
bar(negative,'stack');
plot(t, Pl, 'ok-');
title('Electrical Balance');
legend('Pmt gas turbine','Pfc fuel cell','Pbdis battery discharge','Px load shedding','Ppv photovoltaic power generation','Pwt wind power','Pbch battery charging','Pl total load') ;
grid on
hold off
xlabel('time/hour')
ylabel('power/kw')

%% Output the output results of each part
figure
plot(t,Pmt,'ok-')
hold on
plot(t,Pfc,'-*')
hold on
plot(t,Px,'-')
hold on
plot(t,Pb,'-.')
legend('Pmt gas turbine output', 'Pfc fuel cell output', 'Px can load off', 'Pb battery output');
title('Output Chart');
xlabel('time/hour')
ylabel('power/kw')
%% Calculate hourly running costs
% pre-allocated
eta_mt = zeros(1,24);
eta_fc = zeros(1,24);
Pmth = zeros(1,24);
Umt = zeros(1,24);
Ufc = zeros(1,24);


%% Run the model
fort=1:24
    % gas turbine thermal power
    %The following is the formula for calculating the efficiency of micro gas turbine
    eta_mt(t) = 0.0753*(Pmt(t)/65)^3 - 0.3095*(Pmt(t)/65)^2 + 0.4174*(Pmt(t)/65) + 0.1068;
    Pmth(t) = ((Pmt(t)*(1-eta_mt(t)-eta_l))/eta_mt(t))*eta_h*Coph;
     % fuel cell power
    eta_fc(t) = -0.0023*Pfc(t) + 0.674;
end

%% start and stop
fort=1:24
    if Pmt(t)>0
        Umt(t) = 1;
    end
   
    if Pfc(t)>0
        Ufc(t) = 1;
    end
end

fort=1:24
    if t==1
        Cst(t) = Cst_mt*max(0, Umt(t)-Uinit) + Cst_fc*max(0, Ufc(t)-Uinit);
    else
        Cst(t) = Cst_mt*max(0, Umt(t)-Umt(t-1)) + Cst_fc*max(0, Ufc(t)-Ufc(t-1));
    end
end
%% Hourly running cost of the objective function
cost=[];
fort=1:24
    cost(t)= Cch4*( (Pmt(t)/(L_gas*eta_mt(t))) + (Pfc(t)/(L_gas*eta_fc(t))) ) ... % fuel cost
                      + Cm_mt*Pmt(t) + Cm_fc*Pfc(t) + Cm_pv*Ppv(t)... % maintenance cost
                      + Cm_wt*Pwt(t) + Cst(t) + (Crb(t) + 1.5)*Px(t) + Cm_Eb*Pb(t);
end
figure
plot(1:24,cost)
hold on
plot(1:24,costp)
title('Operating cost per hour');
legend('This article's scheduling method','Conventional scheduling method');
xlabel('time/hour')
ylabel('cost/yuan')

clc;
clear;
close all;
global costp Ppv Pwt
%% algorithm parameters
parameter;
nVar=4*24; % Number of Decision Variables
VarMin=[ones(1,24)*Pmt_min, ones(1,24)*Pfc_min, ones(1,24)*Px_min, ones(1,24)*Pb_min];
VarMax=[ones(1,24)*Pmt_max, ones(1,24)*Pfc_max, ones(1,24)*Px_max, ones(1,24)*Pb_max];
MaxIt=100; % Maximum Number of Iterations
nPop=500; % Population Size (Swarm Size)

%% calculate
[ bestPosition, fitValue ] = tGSSAFUN(@objective,nVar,VarMin,VarMax,MaxIt,nPop);
x=bestPosition;
Pmt = x(1:24); % gas turbine power
Pfc = x(25:48); % fuel cell power
Px = x(49:72); % can be unloaded
Pb = x(73:96); % battery power
t=1:24;

%% Output photovoltaic output forecast
figure
plot(t,Ppv,’-‘)
title(‘Photovoltaic power generation curve’);
xlabel(‘time/hour’)
ylabel(‘power/kw’)
%% Output wind power output forecast
figure
plot(t,Pwt,’-‘)
title(‘Wind power generation curve’);
xlabel(‘time/hour’)
ylabel(‘power/kw’)
%% Output electrical balance results
figure
hold on
Pb_po=max(Pb,0);
Pb_ne=min(Pb,0);
positive=[Pmt’, Pfc’, Pb_po’,Px’,Ppv’,Pwt’];
negative=[ Pb_ne’];
bar(positive,’stack’);
bar(negative,’stack’);
plot(t, Pl, ‘ok-‘);
title(‘Electrical Balance’);
legend(‘Pmt gas turbine’,’Pfc fuel cell’,’Pbdis battery discharge’,’Px load shedding’,’Ppv photovoltaic power generation’,’Pwt wind power’,’Pbch battery charging’,’Pl total load’) ;
grid on
hold off
xlabel(‘time/hour’)
ylabel(‘power/kw’)

%% Output the output results of each part
figure
plot(t,Pmt,’ok-‘)
hold on
plot(t,Pfc,’-*’)
hold on
plot(t,Px,’-‘)
hold on
plot(t,Pb,’-.’)
legend(‘Pmt gas turbine output’, ‘Pfc fuel cell output’, ‘Px can load off’, ‘Pb battery output’);
title(‘Output Chart’);
xlabel(‘time/hour’)
ylabel(‘power/kw’)
%% Calculate hourly running costs
% pre-allocated
eta_mt = zeros(1,24);
eta_fc = zeros(1,24);
Pmth = zeros(1,24);
Umt = zeros(1,24);
Ufc = zeros(1,24);

%% Run the model
fort=1:24
% gas turbine thermal power
%The following is the formula for calculating the efficiency of micro gas turbine
eta_mt(t) = 0.0753*(Pmt(t)/65)^3 – 0.3095*(Pmt(t)/65)^2 + 0.4174*(Pmt(t)/65) + 0.1068;
Pmth(t) = ((Pmt(t)*(1-eta_mt(t)-eta_l))/eta_mt(t))*eta_h*Coph;
% fuel cell power
eta_fc(t) = -0.0023*Pfc(t) + 0.674;
end

%% start and stop
fort=1:24
if Pmt(t)>0
Umt(t) = 1;
end

if Pfc(t)>0
Ufc(t) = 1;
end
end

fort=1:24
if t==1
Cst(t) = Cst_mt*max(0, Umt(t)-Uinit) + Cst_fc*max(0, Ufc(t)-Uinit);
else
Cst(t) = Cst_mt*max(0, Umt(t)-Umt(t-1)) + Cst_fc*max(0, Ufc(t)-Ufc(t-1));
end
end
%% Hourly running cost of the objective function
cost=[];
fort=1:24
cost(t)= Cch4*( (Pmt(t)/(L_gas*eta_mt(t))) + (Pfc(t)/(L_gas*eta_fc(t))) ) … % fuel cost
+ Cm_mt*Pmt(t) + Cm_fc*Pfc(t) + Cm_pv*Ppv(t)… % maintenance cost
+ Cm_wt*Pwt(t) + Cst(t) + (Crb(t) + 1.5)*Px(t) + Cm_Eb*Pb(t);
end
figure
plot(1:24,cost)
hold on
plot(1:24,costp)
title(‘Operating cost per hour’);
legend(‘This article’s scheduling method’,’Conventional scheduling method’);
xlabel(‘time/hour’)
ylabel(‘cost/yuan’)

3 References

Some of the content in the article is quoted from the Internet. The source will be indicated or cited as a reference. It is inevitable that there will be some unfinished information. If there is anything inappropriate, please feel free to contact us to delete it.

[1] Yao Jingkun. Microgrid optimal dispatching based on improved particle swarm algorithm [D]. Liaoning University of Technology, 2016.

4 Matlab code implementation