Home > matpower7.0 > lib > order_radial.m

order_radial

PURPOSE ^

ORDER_RADIAL Performs oriented ordering to buses and branches.

SYNOPSIS ^

function mpc = order_radial(mpc)

DESCRIPTION ^

ORDER_RADIAL  Performs oriented ordering to buses and branches.

   mpc = order_radial(mpc)

   orders the branches by the the principle of oriented ordering:
   indicies of sending nodes are smaller than the indicies of the
   receiving nodes. The branch index is equal to the index of their
   receiving node. The ordering is taken from:
   D. Rajicic, R. Ackovski and R. Taleski, "Voltage correction power flow,"
   IEEE Transactions on Power Delivery, vol. 9, no. 2, pp. 1056-1062, Apr 1994.

   See also RADIAL_PF.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mpc = order_radial(mpc)
0002 %ORDER_RADIAL  Performs oriented ordering to buses and branches.
0003 %
0004 %   mpc = order_radial(mpc)
0005 %
0006 %   orders the branches by the the principle of oriented ordering:
0007 %   indicies of sending nodes are smaller than the indicies of the
0008 %   receiving nodes. The branch index is equal to the index of their
0009 %   receiving node. The ordering is taken from:
0010 %   D. Rajicic, R. Ackovski and R. Taleski, "Voltage correction power flow,"
0011 %   IEEE Transactions on Power Delivery, vol. 9, no. 2, pp. 1056-1062, Apr 1994.
0012 %
0013 %   See also RADIAL_PF.
0014 
0015 %% define named indices into bus, gen, branch matrices
0016 define_constants;
0017 %% Initialize
0018 slack = mpc.bus(mpc.bus(:,BUS_TYPE) == REF, 1);
0019 [f, t] = deal(mpc.branch(:,F_BUS),mpc.branch(:,T_BUS));
0020 nl = size(mpc.branch,1);
0021 branch_number = (1:nl)';
0022 mpc.branch_order = [];
0023 mpc.loop = [];
0024 mpc.bus_order = slack;
0025 %% Bus and branch ordering
0026 iter = 1;
0027 while ~isempty(f) && iter <= nl
0028     % For each of the "from" buses that are in bus_order,
0029     % add the corresponding "to" buses to it. If both "from" and "to" are
0030     % in bus_order, the branch is forming loop. Add corresponding branch
0031     % numbers to branch_order or to loop.
0032     mf = ismember(f,mpc.bus_order);
0033     mt = ismember(t,mpc.bus_order);
0034     is_loop = mf & mt;
0035     % Add branch to loop and delete it from the list
0036     if any(is_loop)
0037         mpc.loop = [mpc.loop; branch_number(is_loop)];
0038         mf(is_loop) = [];
0039 %         mt(is_loop) = [];
0040         f(is_loop) = [];
0041         t(is_loop) = [];
0042         branch_number(is_loop) = [];
0043     end
0044     % Add unique buses to bus_order
0045     if any(mf)
0046         u = unique(t(mf)); % unique buses
0047         [junk,i] = intersect(t.*mf,u); % first occurence of unique buses in t
0048         mpc.bus_order = [mpc.bus_order; t(i)];
0049         % Add branch to branch_order and delete it from the list
0050         mpc.branch_order = [mpc.branch_order; branch_number(i)];
0051         mf(i) = [];
0052 %         mt(i) = [];
0053         f(i) = [];
0054         t(i) = [];
0055         branch_number(i) = [];
0056     end
0057     % Add any remaining branch to loop and delete it from the list
0058     if any(mf)
0059         mpc.loop = [mpc.loop; branch_number(mf)];
0060         f(mf) = [];
0061         t(mf) = [];
0062         branch_number(mf) = [];
0063     end
0064     % For each of the "to" buses that are in bus_order,
0065     % add the corresponding "from" buses to it. If both "from" and "to" are
0066     % in bus_order, the branch is forming loop. Add corresponding branch
0067     % numbers to branch_order or to loop.
0068     mf = ismember(f,mpc.bus_order);
0069     mt = ismember(t,mpc.bus_order);
0070     is_loop = mf & mt;
0071     % Add branch to loop and delete it from the list
0072     if any(is_loop)
0073         mpc.loop = [mpc.loop; branch_number(is_loop)];
0074         mt(is_loop) = [];
0075 %         mf(is_loop) = [];
0076         f(is_loop) = [];
0077         t(is_loop) = [];
0078         branch_number(is_loop) = [];
0079     end
0080     % Add unique buses to bus_order
0081     if any(mt)
0082         u = unique(f(mt)); % unique buses
0083         [junk,i] = intersect(f.*mt,u); % first occurence of unique buses in f
0084         mpc.bus_order = [mpc.bus_order; f(i)];
0085         % Add branch to branch_order and delete it from the list
0086         mpc.branch_order = [mpc.branch_order; branch_number(i)];
0087 %         mf(i) = [];
0088         mt(i) = [];
0089         f(i) = [];
0090         t(i) = [];
0091         branch_number(i) = [];
0092     end
0093     % Add any remaining branch to loop and delete it from the list
0094     if any(mt)
0095         mpc.loop = [mpc.loop; branch_number(mt)];
0096         f(mt) = [];
0097         t(mt) = [];
0098         branch_number(mt) = [];
0099     end
0100     iter = iter + 1;
0101 end
0102 if ~isempty(f)
0103     mpc.not_connected = branch_number;
0104 else
0105     mpc.not_connected = [];
0106 end
0107 %% Reorder bus, branch and gen.
0108 if isempty(mpc.loop)
0109     % Permute rows in branch
0110     mpc.branch = mpc.branch(mpc.branch_order,:);
0111     % Make an "inverse" vector out of bus_order
0112     mpc.bus_order_inv = sparse(mpc.bus_order,ones(nl+1,1),1:nl+1);
0113     % Swap indicies in "from" and "to" buses using bus_order_inv
0114     [f, t] = deal(mpc.branch(:,F_BUS),mpc.branch(:,T_BUS));
0115     f = mpc.bus_order_inv(f);
0116     t = mpc.bus_order_inv(t);
0117     % Reverse branch orientation of "from" is biger than "to"
0118     mpc.br_reverse = f > t;
0119     [f(mpc.br_reverse), t(mpc.br_reverse)] = deal(t(mpc.br_reverse), f(mpc.br_reverse));
0120     % Put new "from" and "to" indicies in branch
0121     mpc.branch(:,[F_BUS T_BUS]) = [f t];
0122     % Make an "inverse" vector out of branch_order
0123     mpc.branch_order_inv = sparse(mpc.branch_order,ones(nl,1),1:nl);
0124     % Permute rows in bus and replace bus indicies
0125     mpc.bus = mpc.bus(mpc.bus_order,:);
0126     mpc.bus(:,BUS_I) = mpc.bus_order_inv(mpc.bus(:,BUS_I));
0127     % Replace bus indicies in gen
0128     mpc.gen(:,GEN_BUS) = mpc.bus_order_inv(mpc.gen(:,GEN_BUS));
0129 end

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005