How to write the equation for minimizing one day power loss of a PV system as an objective function to be used in Genetic Algorithm.

19 views (last 30 days)
Baisakh Sarangi
Baisakh Sarangi on 2 Dec 2021
Answered: Alan Weiss on 2 Dec 2021
I want to write an objective function (of the form of y = a*x1^(2) + b*x2^(2) ) by taking x1 = bus location (varying from 2 to 33; since i am using IEEE 33 Bus distribution network for my project), x2 = number of panels (varying from 1 to 1000). The objective function will be the one day power loss when a PV system is connected with one particular bus of the 33-bus distribution network. The size of the PV unit is fixed at 5KW. The power output from a PV unit is Pout = Pmax * (irradiation factor); here Pmax = 5 KW. The irradiation factor varies hourly. The function for calculating the real power losses that i have created is as shown below:
function objective_function = real_power_loss(Z,Zbase,Ibranch,Vbase,Sbase)
objective_function = sum(real((Z*Zbase).*((Ibranch*(Vbase^2/Sbase)).^2)));
end
I need to iterate this function in a for loop for i = 1 to 24 for getting the total one day power loss. The code i have written for iterating through each of the 33 buses and increasing the number of panels from 1 to 1000 is as shown below:
function y = Objfunc(x1, x2)
for x1 = 2:33
LD = load('linedata33bus.m'); % loading the branch data
BD = load('Busdata33bus.m'); % loading the bus data
IRR = load('irradiation_factor_data.m');
for f = 1:24
for x2 = 1:1000
BD(x1,2) = -5*x2*IRR(f,2);
BD(x1,3) = 0;
Sbase = 200; % Sbase = 200 MVA
Vbase = 11; % Vbase = 11 KV
Zbase = (Vbase^2)/Sbase;
LD(:,4:5) = LD(:,4:5)/Zbase; % converting the branch impedances into p.u
BD(:,2:3) = BD(:,2:3)/(1000*Sbase); % converting the load at each node into p.u
Sload = complex(BD(:,2),BD(:,3)); % defining the S for each load
V = ones(size(BD,1),1); % defining the initial values of all the bus voltages as equal to the voltage of the slack bus i.e 1 p.u
Z = complex(LD(:,4),LD(:,5)); % defining the branch impedance for each branch
Ibranch = zeros(size(LD,1),1); % initial values of branch currents = 0
Iter = 1000;
%THE ALGORITHM
for k = 1:Iter
% BACKWARD SWEEP
Iload = conj(Sload./V); % calculating the load current for each load
for j = size(LD,1):-1:1 % starting from the end of the feeder
[c e] = find(LD(:,2:3) == LD(j,3)); % here we find all the values in the 2nd and 3rd columns of LD which are equal to the branch no. we are assessing. In [c e], c will contain the row no. of all the rows that have the branch no. in them and e will basically contain the column no. which is 1 and 2 in this code.
if size(c,1) == 1 % if c has only one value that means j is an ending bus i.e only one branch is connected to that bus
Ibranch(LD(j,1)) = Iload(LD(j,3)); % then the current passing through the jth branch is equal to the current passing through the corresponding load
else
Ibranch(LD(j,1)) = Iload(LD(j,3)) + sum(Ibranch(LD(c,1))) - Ibranch(LD(j,1)); % else the branch current is equal to the corresponding load current(i.e the load connected to the corresponding bus) plus the sum of the currents of all branches that are connected to the same bus. Since we calculate Ibranch(LD(j,1)) twice in Ibranch(LD(c,1)) (because in c we have j value as well) so we need to subtract it once.
end
end
% FORWARD SWEEP
for j = 1:size(LD,1) % starting from the beginning of the feeder
V(LD(j,3)) = V(LD(j,2)) - Ibranch(LD(j,1))*Z(j); % Here the ending bus voltage = starting bus voltage - (the current through the branch that connects these two buses)*(impedance of that branch). This equation is obtained using KVL.
end
end
y = real_power_loss(Z,Zbase,Ibranch,Vbase,Sbase);
end
end
end
Here it shows that the variables x1 and x2 remains unused (which i have to use as the variables in my objective fucntion). i can't understand.
Also when i use the ga solver in MATLAB to optimiza the function its not working and its showing busy and it stucks:
FitFunc = @Objfunc;
nvars = 3;
[x1, x2, fval] = ga(FitFunc,nvars);
I dont know how to convert the function that i have written into a correct form of objective function of the form of a polynomial for solving it using genetic algorithm.
Please help me anyone, urgently required for me.

Answers (2)

Alan Weiss
Alan Weiss on 2 Dec 2021
Your function as written does not make use of the input x1 and x2 values. Instead, it declares these variables as indices for two sums, and sums over fixed values, meaning the x1 and x2 values do not enter into the objective function at the end of the summations. In other words, the function as written is a constant independent of the input values.
I don't understand what you are trying to do, but your function is not a function of the input variables.
  1 Comment
Baisakh Sarangi
Baisakh Sarangi on 2 Dec 2021
Sir actually I want to create an objective function representing the per day power losses of the 33-bus distribution system when a PV unit is connected to any bus and of any size and the function will be containing the variables x1 = bus location (varying from 2 to 33) (i.e the location of the bus to which the PV unit is connected at the present iteration) and x2 = number of panels of the PV unit (varying from 1 to 1000), and then optimize this function using genetic algorithm solver in MATLAB. But sir I couldn't find a way how to write the objective function. Sir can you please help. This is important for my academics.

Sign in to comment.


Alan Weiss
Alan Weiss on 2 Dec 2021
I think that you need to rethink your objective function. It sounds like the input variables must be integers in a certain range. You can use the Problem-Based Optimization Workflow to do that easily:
x1 = optimvar('x1','LowerBound',2,'UpperBound',33,...
'Type','integer');
x2 = optimvar('x2','LowerBound',1,'UpperBound',1000,...
'Type','integer');
You then need to write your objective function in terms of x1 and x2. You have to be careful when using the problem-baed approach that all of your optimization variables and expressions are real. You can use internal variables that are complex, just make sure that the objective is purely real.
If you run into issues with not being able to use optimization variables as indices, create auxiliary variables y1 and y2 and express things in terms of the auxiliary variables. Then couple the x and y variables along the lines of Integer and Logical Modeling.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by