1Main Content
This program uses an adaptive genetic algorithm to optimize the configuration of distributed power sources, with the sum of investment operating costs, network loss costs, electricity purchase costs, and carbon emission costs as the optimization objective. The power flow calculation is performed using the forward-backward method. The program not only reproduces the 33-node system from the reference literature but also implements the site selection and capacity model for the 118-node distribution network. Therefore, the program package linked at the end includes two parts: one is the optimization program for the 118-node system, and the other is for the 33-node system.The program is written in Matlab, with clear comments!
-
Implementation of Adaptive Genetic Algorithm
%**************Adaptive Mutation Rate************if fit1(k)>=fit_avg pmut=proc1*(1/(pmut1-pmut2+exp((fit1(k+1)-fit_avg)/(fit1(n)-fit_avg))));else pmut=k2*pmut1; end %************************************ rk=rand();if rk<pmutpos=fix(rand()*length)+1;%Randomly generate mutation point # fix(x) rounds towards zero #ifpos==1 %The position of the export circuit breaker cannot changepos=pos+1; endpop(k,pos)=rand()*(pmax/10);%Mutate the mutation point %****************Original Program**************% if sum(pop)>(pmax/10)% pop=floor(pop*((pmax/10)/sum(pop)));% end %********************************** end
2Partial Program
%% Genetic Algorithmpop=encode(n_point,n,pmax); %Use encoding function to obtain initial populationgen=0;%Initialize generation t_cal=1; %Number of calculation iterationsL=30; %Size of the memory populationwhile(gen<=N_gen) time(t_cal)=t_cal; %Standard genetic algorithm process fval=zeros(1,n);%Initialize function values fit=zeros(1,n);%Initialize fitnessfor i=1:n fval(i)=fun(pop(i,:),line,line1,LOAD); %Calculate individual function values, objective functionend fval_avg(time(t_cal))=mean(fval);%Record the average function value of each generation %fval=fval-min(fval);%Ensure fitness is positive fsum=sum(fval);%Total fitness fit_avg=fsum/n;%Calculate average population fitness fit=fval/fsum;%Calculate individual fitness (normalization) [fit1,index]=sort(fit); %Sort the fit array in ascending order and store in fit1; simultaneously, store the corresponding index values in index popfx=pop(index(1:L),:); %Store the memory individuals best=pop(index(1),:);%Record the optimal value of each generation, kept in variable best #Because sorted in ascending order, when n=100, it is the optimal individual# best_fit(1,gen+1)= fun(pop(index(1),:),line,line1,LOAD); fval_best(time(t_cal))=fun(best,line,line1,LOAD);%Calculate the function value of the optimal individual of each generation, stored in array fval_best fsum=sum(1./fval);%Total fitness reciprocal fit=(1./fval)/fsum; q(1)=fit(1);for i=2:n q(i)=q(i-1)+fit(i);%Accumulate individual fitness to form a roulette wheelend pop=select(pop,q,n);%Selection pop=crossover(pop,pcro1,pcro2,n,n_point,pmax,fit1,fit_avg);%Crossover pop=mutation(pop,pmut1,pmut2,n,n_point,pmax,fit1,fit_avg);%Mutation %**************************Microhabitat Technique****************************** pophe=[popfx;pop]; %Total individuals d=0; fval1=zeros(1,n+L);for i=1:1:L+n fval1(1,i)=fun(pophe(i,:),line,line1,LOAD);endfor i=1:1:L+n-1for j=i+1:1:L+n sumd1=sum(((pophe(i,:)-pophe(j,:)).^2)); d=d+sqrt(sumd1);endend sum1=0;for i=1:1:L+n-1for j=i+1:1:L+n sum1=sum1+1;endend radius=d/sum1; %This radius I looked at is just the output value, unclear function, I did not change it radius=radius/(gen+130000);for i=1:1:L+n-1for j=i+1:1:L+n sumd2=0;for l=1:1:n_point d2=((pophe(i,l)-pophe(j,l))^2); sumd2=sumd2+d2;end d(i,j)=sqrt(sumd2);if d(i,j) < radiusif fval1(i)<fval1(j) fval1(j)=fval1(j)+10000000;else fval1(i)=fval1(i)+10000000;endendendend [fn1,fx1]=sort(fval1); pop=pophe(fx1(1:n),:); %*******************Microhabitat Algorithm******************************* %***************Added Program********************** % If this segment is not added, crossover mutation may exceed limits, (the total capacity of distributed power sources does not exceed 20% of the total system load)for ii=1:n total_dg(ii)=sum(pop(ii,:));endfor i=1:nif total_dg(i)>(pmax/10) pop(i,:)=floor(pop(i,:)*((pmax/10)/total_dg(i))); %Convert to less than 1, #floor() does not exceed the maximum integer of the variable#endendfor i=1:nfor j=1:n_pointif pop(i,j)>111.1 pop(i,j)=111.1; %Maximum output power of micro gas turbine does not exceed 300Kw#endendendfor i=1:nfor j=1:n_pointif pop(i,j)<80 pop(i,j)=0; %Maximum output power of micro gas turbine does not exceed 300Kw#endendend %**************************************************** pop(n,:)=best; gen=gen+1;%Next generation t_cal=t_cal+1;end
3Program Results
118-Node System Operating Results
33-Node System Operating Results and Comparison with Original Text
Below are the original results:
Below are the original results:
4Download Link
Scan or Read the Original Text to jump to the program page:
Want to know more about the program? Follow the tutorial below to view the Program Directory!










