0001 function [PgMax] = sg_gen_capacity(link_ids, Btypes, Tab_2D_Pgmax)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 Generation_buses = find(Btypes==1);
0022 N=length(Btypes(:,1));
0023 Ng=length(Generation_buses);
0024
0025 Generation_nodedegree=nodedegree(Generation_buses,link_ids);
0026
0027 maxnode = max(Generation_nodedegree(:,2));
0028
0029
0030 Normalized_Generation_nodedegree=[Generation_nodedegree(:,1),Generation_nodedegree(:,2)/maxnode];
0031
0032 Total_Generation= 10 ^(-0.21*(log10(N))^2+2.06*log10(N)+0.66);
0033
0034 [Normalized_r_Pgmax,MAX_r_Pgmax]=initialgeneration(Ng,Total_Generation);
0035
0036
0037
0038
0039 [Corr_Pgmax,Norm_Generation_setting]=Assignment(Normalized_Generation_nodedegree,Normalized_r_Pgmax,Tab_2D_Pgmax);
0040
0041 Generation_setting = Norm_Generation_setting;
0042 Generation_setting(:,2)= Generation_setting(:,2).*maxnode;
0043 Generation_setting(:,3)= Generation_setting(:,3).*MAX_r_Pgmax;
0044
0045 PgMax=[Generation_setting(:,1),Generation_setting(:,3)];
0046
0047
0048 function Load_nodedegree=nodedegree(Load_buses,link_ids)
0049
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
0072
0073
0074
0075
0076
0077 mu = Total_Generation./Ng;
0078 P=sg_exprnd(mu,Ng,1);
0079
0080 SG=round(0.01*Ng);
0081
0082
0083 P_super=max(P)+(2.*rand(SG,1)*max(P));
0084
0085 [samp,ind]=sg_datasample(P,SG,'replace',false);
0086 P(ind)=[];
0087
0088 r_Pg=[P;P_super];
0089
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
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 Ng=length(Normalized_r_Pg);
0112
0113
0114 Tab_2D_Ng=round(Tab_2D.*Ng);
0115
0116
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
0127 N_K=zeros(1,14);
0128 N_K = sum(Tab_2D_Ng,1);
0129
0130
0131 Sort_nodedegree=sortrows(Normalized_Generation_nodedegree,2);
0132
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
0176 N_G=zeros(1,14);
0177 N_G = sum(Tab_2D_Ng,2)';
0178
0179
0180
0181 Sort_r_Pg=sort(Normalized_r_Pg);
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
0225
0226
0227
0228
0229
0230
0231
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
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