Home > matpower7.0 > extras > syngrid > lib > sg_gen_capacity.m

sg_gen_capacity

PURPOSE ^

SG_GEN_CAPACITY main function to run Pg_max assignment

SYNOPSIS ^

function [PgMax] = sg_gen_capacity(link_ids, Btypes, Tab_2D_Pgmax)

DESCRIPTION ^

SG_GEN_CAPACITY  main function to run Pg_max assignment
   [PGMAX, CORR_PGMAX] = SG_GEN_CAPACITY(LINK_IDS, BTYPES, TAB_2D_PGMAX)

   Input:
       link_ids - matrix (m x 2) indicating the branch terminal buses
       Btypes - bus type assignment vector (N by 1) of G/L/C (1/2/3)
       Tab_2D_Pgmax - PMF map table to assign Pgmax based on node degree

   Output:
       PgMax - matrix (Ng x 2) indicating the generation bus numbers and
           generation capacity at each generation bus

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [PgMax] = sg_gen_capacity(link_ids, Btypes, Tab_2D_Pgmax)
0002 %SG_GEN_CAPACITY  main function to run Pg_max assignment
0003 %   [PGMAX, CORR_PGMAX] = SG_GEN_CAPACITY(LINK_IDS, BTYPES, TAB_2D_PGMAX)
0004 %
0005 %   Input:
0006 %       link_ids - matrix (m x 2) indicating the branch terminal buses
0007 %       Btypes - bus type assignment vector (N by 1) of G/L/C (1/2/3)
0008 %       Tab_2D_Pgmax - PMF map table to assign Pgmax based on node degree
0009 %
0010 %   Output:
0011 %       PgMax - matrix (Ng x 2) indicating the generation bus numbers and
0012 %           generation capacity at each generation bus
0013 
0014 %   SynGrid
0015 %   Copyright (c) 2017-2018, Electric Power and Energy Systems (EPES) Research Lab
0016 %   by Hamidreza Sadeghian and Zhifang Wang, Virginia Commonwealth University
0017 %
0018 %   This file is part of SynGrid.
0019 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0020 
0021 Generation_buses = find(Btypes==1);
0022 N=length(Btypes(:,1));
0023 Ng=length(Generation_buses);
0024 % indicating the node degree at each generation bus
0025 Generation_nodedegree=nodedegree(Generation_buses,link_ids);
0026 % calculate maximum node degree
0027 maxnode = max(Generation_nodedegree(:,2));
0028 % Matrix (Ng by 2) indicating bus number of generation buses and related
0029 % normalized node degree
0030 Normalized_Generation_nodedegree=[Generation_nodedegree(:,1),Generation_nodedegree(:,2)/maxnode];
0031 % Total generation capacity with respect to the network size
0032 Total_Generation= 10 ^(-0.21*(log10(N))^2+2.06*log10(N)+0.66);
0033 % Generation capacities based on the empirical distribution of realistic power grids
0034 [Normalized_r_Pgmax,MAX_r_Pgmax]=initialgeneration(Ng,Total_Generation);
0035 % Assignment of generation capacities based on the related node degree
0036 % Norm_Generation_setting is a matrix ( Ng by 3 ) indicating bus number,
0037 % related normalized node degree and normilized assigned generation
0038 % capacity,  respectively.
0039 [Corr_Pgmax,Norm_Generation_setting]=Assignment(Normalized_Generation_nodedegree,Normalized_r_Pgmax,Tab_2D_Pgmax); %replace the older version of assginement_order()
0040 % Output: calculate actual values for generation capacities
0041 Generation_setting = Norm_Generation_setting;
0042 Generation_setting(:,2)= Generation_setting(:,2).*maxnode;
0043 Generation_setting(:,3)= Generation_setting(:,3).*MAX_r_Pgmax; %Now Generation_setting contains actural values of bus number, node degree, and Pgmax.
0044 % PgMax matrix (Ng by 2)indicating the generation bus numbers and  generation capacity at each generation bus
0045 PgMax=[Generation_setting(:,1),Generation_setting(:,3)];
0046 
0047 %%
0048  function Load_nodedegree=nodedegree(Load_buses,link_ids)
0049  % This function calculates the node degree at each load buses
0050 
0051 Load_nodedegree=[];
0052 L1=length(Load_buses(:,1));
0053 L2=length(link_ids(:,1));
0054 
0055 for Bii=1:length(Load_buses(:,1))
0056     count=0;
0057     for Li=1:length(link_ids(:,1))
0058         if link_ids(Li,1)==Load_buses(Bii,1)
0059             count=count+1;
0060         elseif link_ids(Li,2)==Load_buses(Bii,1)
0061             count=count+1;
0062         end
0063     end
0064     Load_nodedegree=[Load_nodedegree;Load_buses(Bii,1),count];
0065 end
0066 
0067  end
0068 
0069 %%
0070 function [Normalized_r_Pgmax,MAX_r_Pgmax]=initialgeneration(Ng,Total_Generation)
0071 % This is a function to generate generation capacities based on the distribution of realistic grids
0072 % 99% follow the exponential distribution
0073 % 1% of generators take supper large capacity
0074 
0075 % output:
0076 %        Normalized_r_Pg - matrix (Ng by 1) indicating the normalized generation capacity at each generation bus
0077 mu = Total_Generation./Ng;
0078 P=sg_exprnd(mu,Ng,1);
0079 % Calculate number of super large capacities
0080 SG=round(0.01*Ng);
0081 % Generate uniform random super large capacities from [1-3] times of
0082 % maximum generation
0083 P_super=max(P)+(2.*rand(SG,1)*max(P));
0084 % Randomly sample from generations without replacement
0085 [samp,ind]=sg_datasample(P,SG,'replace',false);
0086 P(ind)=[];
0087 % Replace sampled data with super large capacities
0088 r_Pg=[P;P_super];
0089 %% check scaling property for total generation
0090 if (sum(r_Pg)>1.05*Total_Generation ||  sum(r_Pg)<.90*Total_Generation)
0091    r_Pg = r_Pg.*(Total_Generation./sum(r_Pg));
0092 end
0093 
0094 MAX_r_Pgmax=max(r_Pg);
0095 
0096 Normalized_r_Pgmax=r_Pg/MAX_r_Pgmax;
0097  end
0098 %%
0099 function [Corr_co,Norm_Generation_setting]=Assignment(Normalized_Generation_nodedegree,Normalized_r_Pg,Tab_2D)
0100 % This is a function to assign the normalized generation capacities to the generation buses based
0101 % on node degrees
0102 %
0103 % input:
0104 %       Normalized_Generation_nodedegree- matrix (2 by Ng) indicating the normalized value of node degrees
0105 %       Normalized_r_Pg- matrix (1 by Ng) indicating the normalized value of generation capacities
0106 %       Tab_2D - matrix (14 by 14) indicating the assignment pattern
0107 % output:
0108 %       Generation_setting- matrix (Ng by 3) indicating the generation capacity setting at each generation bus
0109 %             gen bus number, norm_node degree,  norm_Pg_max
0110 
0111 Ng=length(Normalized_r_Pg);
0112 % calculate actual nnumber of each cell in 2D table nased on the total
0113 % number of generation capacities
0114 Tab_2D_Ng=round(Tab_2D.*Ng);
0115 % check the mismatch comes from "round". Add or subtract from maximum
0116 % number in the matrix
0117 if sum(sum(Tab_2D_Ng))<Ng
0118     [Max_tab,ind_max_tab]=max(Tab_2D_Ng(:));
0119     [I_row, I_col] = ind2sub(size(Tab_2D_Ng),ind_max_tab);
0120     Tab_2D_Ng(I_row,I_col)=Tab_2D_Ng(I_row,I_col)+(Ng-sum(sum(Tab_2D_Ng)));
0121 elseif sum(sum(Tab_2D_Ng))>Ng
0122     [Max_tab,ind_max_tab]=max(Tab_2D_Ng(:));
0123     [I_row, I_col] = ind2sub(size(Tab_2D_Ng),ind_max_tab);
0124     Tab_2D_Ng(I_row,I_col)=Tab_2D_Ng(I_row,I_col)-(sum(sum(Tab_2D_Ng))-Ng);
0125 end
0126 %% calculate target number of buses based on node degree and 2D table
0127 N_K=zeros(1,14); % matrix for total number of buses in each node degree category
0128 N_K = sum(Tab_2D_Ng,1);
0129 
0130 %% sort node degrees
0131 Sort_nodedegree=sortrows(Normalized_Generation_nodedegree,2);
0132 %% assign buses to the node degree categories
0133 K1=Sort_nodedegree(1:N_K(1,1),:);
0134 Sort_nodedegree(1:N_K(1,1),:)=[];
0135 
0136 K2=Sort_nodedegree(1:N_K(1,2),:);
0137 Sort_nodedegree(1:N_K(1,2),:)=[];
0138 
0139 K3=Sort_nodedegree(1:N_K(1,3),:);
0140 Sort_nodedegree(1:N_K(1,3),:)=[];
0141 
0142 K4=Sort_nodedegree(1:N_K(1,4),:);
0143 Sort_nodedegree(1:N_K(1,4),:)=[];
0144 
0145 K5=Sort_nodedegree(1:N_K(1,5),:);
0146 Sort_nodedegree(1:N_K(1,5),:)=[];
0147 
0148 K6=Sort_nodedegree(1:N_K(1,6),:);
0149 Sort_nodedegree(1:N_K(1,6),:)=[];
0150 
0151 K7=Sort_nodedegree(1:N_K(1,7),:);
0152 Sort_nodedegree(1:N_K(1,7),:)=[];
0153 
0154 K8=Sort_nodedegree(1:N_K(1,8),:);
0155 Sort_nodedegree(1:N_K(1,8),:)=[];
0156 
0157 K9=Sort_nodedegree(1:N_K(1,9),:);
0158 Sort_nodedegree(1:N_K(1,9),:)=[];
0159 
0160 K10=Sort_nodedegree(1:N_K(1,10),:);
0161 Sort_nodedegree(1:N_K(1,10),:)=[];
0162 
0163 K11=Sort_nodedegree(1:N_K(1,11),:);
0164 Sort_nodedegree(1:N_K(1,11),:)=[];
0165 
0166 K12=Sort_nodedegree(1:N_K(1,12),:);
0167 Sort_nodedegree(1:N_K(1,12),:)=[];
0168 
0169 K13=Sort_nodedegree(1:N_K(1,13),:);
0170 Sort_nodedegree(1:N_K(1,13),:)=[];
0171 
0172 K14=Sort_nodedegree(1:N_K(1,14),:);
0173 Sort_nodedegree(1:N_K(1,14),:)=[];
0174 
0175 %% calculate target number of generations in normalized generation capacity categories
0176 N_G=zeros(1,14); % matrix for total number of buses in each node degree category
0177 N_G = sum(Tab_2D_Ng,2)';
0178 
0179 %% sort generation capacities and assign them to normalized generation capacities groups of 2D table
0180 %Sort_r_Pg=sort(Normalized_r_Pg,'descend');
0181 Sort_r_Pg=sort(Normalized_r_Pg); %changed by zfwang, because Tab_2D is now both in ascending order from 1->Ng
0182 
0183 G1=Sort_r_Pg(1:N_G(1,1),:);
0184 Sort_r_Pg(1:N_G(1,1),:)=[];
0185 
0186 G2=Sort_r_Pg(1:N_G(1,2),:);
0187 Sort_r_Pg(1:N_G(1,2),:)=[];
0188 
0189 G3=Sort_r_Pg(1:N_G(1,3),:);
0190 Sort_r_Pg(1:N_G(1,3),:)=[];
0191 
0192 G4=Sort_r_Pg(1:N_G(1,4),:);
0193 Sort_r_Pg(1:N_G(1,4),:)=[];
0194 
0195 G5=Sort_r_Pg(1:N_G(1,5),:);
0196 Sort_r_Pg(1:N_G(1,5),:)=[];
0197 
0198 G6=Sort_r_Pg(1:N_G(1,6),:);
0199 Sort_r_Pg(1:N_G(1,6),:)=[];
0200 
0201 G7=Sort_r_Pg(1:N_G(1,7),:);
0202 Sort_r_Pg(1:N_G(1,7),:)=[];
0203 
0204 G8=Sort_r_Pg(1:N_G(1,8),:);
0205 Sort_r_Pg(1:N_G(1,8),:)=[];
0206 
0207 G9=Sort_r_Pg(1:N_G(1,9),:);
0208 Sort_r_Pg(1:N_G(1,9),:)=[];
0209 
0210 G10=Sort_r_Pg(1:N_G(1,10),:);
0211 Sort_r_Pg(1:N_G(1,10),:)=[];
0212 
0213 G11=Sort_r_Pg(1:N_G(1,11),:);
0214 Sort_r_Pg(1:N_G(1,11),:)=[];
0215 
0216 G12=Sort_r_Pg(1:N_G(1,12),:);
0217 Sort_r_Pg(1:N_G(1,12),:)=[];
0218 
0219 G13=Sort_r_Pg(1:N_G(1,13),:);
0220 Sort_r_Pg(1:N_G(1,13),:)=[];
0221 
0222 G14=Sort_r_Pg(1:N_G(1,14),:);
0223 Sort_r_Pg(1:N_G(1,14),:)=[];
0224 %% assign grouped generation capacities to the 2D table cells
0225 % 1) Save generation buses and their related node degrees in cell arreys of
0226 % K_cell
0227 % 2) Save generation capacities in cell arreys of G_cell
0228 % 3) Assigne generation capacities to the node degrees based  : For each
0229 % cell arrey of K_cell (category of node degrees) starting from first array of G_cell based on the number of
0230 % each cell in Tab_2D_Ng assigne generation capacities and then remove
0231 % asigned generation capacities from G_cell.
0232 K_cell=cell(1,14);
0233 K_cell{1}=K1; K_cell{2}=K2; K_cell{3}=K3; K_cell{4}=K4; K_cell{5}=K5; K_cell{6}=K6; K_cell{7}=K7;
0234 K_cell{8}=K8; K_cell{9}=K9; K_cell{10}=K10; K_cell{11}=K11; K_cell{12}=K12; K_cell{13}=K13; K_cell{14}=K14;
0235 
0236 G_cell=cell(1,14);
0237 G_cell{1}=G1; G_cell{2}=G2; G_cell{3}=G3; G_cell{4}=G4; G_cell{5}=G5; G_cell{6}=G6; G_cell{7}=G7;
0238 G_cell{8}=G8; G_cell{9}=G9; G_cell{10}=G10; G_cell{11}=G11; G_cell{12}=G12; G_cell{13}=G13; G_cell{14}=G14;
0239 
0240 for kk=1:14
0241     K_num=1;
0242     for gg=14:-1:1
0243         if Tab_2D_Ng(gg,kk)>0
0244             [samp_G,ind_G]=sg_datasample(G_cell{gg},Tab_2D_Ng(gg,kk),'replace',false);
0245             K_cell{kk}(K_num:(K_num + Tab_2D_Ng(gg,kk)-1),3)=samp_G;
0246             K_num=K_num+Tab_2D_Ng(gg,kk);
0247             G_cell{gg}(ind_G)=[];
0248         else
0249         K_cell{kk}(K_num:(K_num + Tab_2D_Ng(gg,kk)-1),3)=G_cell{gg}(1:Tab_2D_Ng(gg,kk));
0250         end
0251     end
0252 end
0253 % Gen_st is a martrix (Ng by 3) inclouds bus numbers, normalized node degrees and normalized generation capacities
0254 Gen_st=[K_cell{1};K_cell{2};K_cell{3};K_cell{4};K_cell{5};K_cell{6};K_cell{7};K_cell{8};K_cell{9};K_cell{10};K_cell{11};K_cell{12};K_cell{13};K_cell{14}];
0255 Norm_Generation_setting=sortrows(Gen_st,1);
0256 Corr_co=corr(Norm_Generation_setting(:,2),Norm_Generation_setting(:,3));
0257 end
0258 end

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