├── README.md ├── sellers.csv ├── buyers.csv └── decentralizedptp.m /README.md: -------------------------------------------------------------------------------- 1 | # Decentralized-p2p 2 | This repository contains supplementary data and MATLAB code for "Mechanism Design for Decentralized Peer-to-Peer Energy Trading Considering Heterogeneous Preferences" by Saber Talari, Mohsen Khorasany, Reza Razzaghi, Wolfgang Ketter, and Amin Shokri Gazafroudi. 3 | The main code is named as "decentralizedptp" and takes "sellers" and "buyers" input data as csv files and generates the results of a decentralized p2p trading between sellers and buyers. 4 | -------------------------------------------------------------------------------- /sellers.csv: -------------------------------------------------------------------------------- 1 | I_n,Q_n,P_n,L_n,R_n,G_n,alpha_L,alpha_R,alpha_G 2 | 1,-2.29,11.3,1,0.9,1,0.16,0.72,1.07 3 | 2,-0.41,14.3,1,0.9,1,0.04,0.92,0.24 4 | 3,-0.64,14.1,1,0.9,1,2.84,1.2,1.03 5 | 4,-0.23,15.5,1,0.8,1,1.52,0.44,0.65 6 | 5,-0.32,15.1,1,0.8,1,1.52,0.5,0.31 7 | 7,-1.27,12.1,1,0.97,0,0.08,1.25,0.83 8 | 10,-0.34,14.8,1,1,0,3.28,0.99,0.92 9 | 11,-1.68,11.6,1,0.86,0,0.68,0.08,1.03 10 | 14,-1.31,11.8,1,0.9,0,1.12,0.69,0.82 11 | 18,-1.22,12.8,1,1,0,2.88,0.4,0.06 12 | 22,-0.2,15.8,2,1,0,2.28,0.04,0.24 13 | 27,-0.88,13.9,2,0.9,0,1.52,0.68,0.48 14 | 31,-1.1,13.5,2,0.97,0,2.4,0.3,0.47 15 | 36,-4.29,10.4,3,0.84,1,0.52,0.69,0.33 16 | 37,-2.41,10.9,3,1,1,1.2,0.1,0.8 17 | 38,-2.64,10.5,3,0.9,1,0.6,0.38,1.08 18 | 39,-4.23,10.4,3,0.9,1,0,0.05,0.88 19 | 40,-4.32,10.3,3,0.9,1,0.12,0.05,0.47 20 | 42,-1.27,12.6,3,0.8,0,3.2,0.42,0.06 21 | 46,-1.35,11.7,4,0.6,0,3.4,1.13,0.28 22 | 48,-1.18,13.3,4,0.86,0,4.36,0.45,0.73 23 | 51,-2.26,11.4,4,0.8,0,3.56,0.7,0.45 24 | 53,-2.32,11.1,4,0.89,0,3.2,1.14,0.14 25 | 55,-2.58,10.9,4,0.7,0,1.32,1.02,0.32 26 | -------------------------------------------------------------------------------- /buyers.csv: -------------------------------------------------------------------------------- 1 | I_n,Q_n,P_n,L_n,R_n,G_n,alpha_L,alpha_R,alpha_G 2 | 6,0.63,21.7,1,1,0,2.16,0.85,0.43 3 | 8,0.38,22.1,1,0.7,0,3.76,0.89,0.31 4 | 9,0.12,22.5,1,0.6,0,0.84,0.07,0.89 5 | 12,1.03,19.1,1,0.84,0,3.8,0.78,0.67 6 | 13,1.08,18.3,1,0.9,0,1.08,1.29,0.23 7 | 15,0.98,19.2,1,0.9,0,4.04,0.44,0.9 8 | 16,2.86,16.9,1,0.8,0,2,1.21,1.01 9 | 17,2.47,17.5,1,0.8,0,2.36,0.13,0.08 10 | 19,1.06,18.4,2,0.97,0,4.6,0.66,0.02 11 | 20,6.34,16.1,2,0.7,0,1.16,0.49,0.26 12 | 21,1.22,17.5,2,0.6,0,4.6,0.76,1.09 13 | 23,1.45,16.2,2,0.86,0,0.92,0.08,0.14 14 | 24,3.89,16.4,2,0.84,0,1.44,1.05,1.03 15 | 25,2.74,17.3,2,0.9,0,1.84,0.97,0.97 16 | 26,0.74,21.3,2,0.9,0,0.36,0.28,0.48 17 | 28,1.09,18.1,2,0.8,0,0.52,0.26,0.34 18 | 29,1.23,17.1,2,0.8,0,4.76,0.94,0.49 19 | 30,0.82,21.12,2,1,0,0.04,1.18,0.33 20 | 32,1.04,18.8,2,0.7,0,1.04,0.85,0.19 21 | 33,1.78,15.2,2,0.6,0,1.28,0.39,0.14 22 | 34,0.68,21.3,2,1,0,2.4,0.73,0.74 23 | 35,1.96,18.2,2,0.86,0,4.36,0.69,0.51 24 | 41,0.63,21.5,3,0.8,0,3.64,0.24,0.98 25 | 43,0.38,21.9,3,1,0,2.4,0.81,0.21 26 | 44,0.12,22.6,3,0.97,0,0.88,0.35,0.21 27 | 45,0.34,22.4,4,0.7,0,0.68,0.03,0 28 | 47,0.84,20.5,4,1,0,0.08,0.98,1.01 29 | 49,0.91,19.7,4,0.84,0,0.36,0.48,0.02 30 | 50,1.39,16.4,4,1,0,1.72,0.42,0.89 31 | 52,2.04,18.1,4,1,0,2.64,0.56,0.34 32 | 54,1.5,15.5,4,0.85,0,2.04,0.6,0.78 33 | -------------------------------------------------------------------------------- /decentralizedptp.m: -------------------------------------------------------------------------------- 1 | clc; clear; close all; 2 | 3 | %% Input parameters 4 | FIT= 10; % Feed-in tariff 5 | TOU=23; % Market price 6 | M=100; %Big number for distance calculation 7 | gamma=0.5; %permiums limit 8 | 9 | %%Bidding step 10 | 11 | % Sellers parameters 12 | seller_data = csvread('sellers.csv', 1, 0); 13 | I_s= transpose(seller_data(:,1)); %Seller ID 14 | Q_s= -transpose(seller_data(:,2)); %Seller offer-Quantity 15 | P_s= transpose(seller_data(:,3)); %Seller offer-Price 16 | L_s= transpose(seller_data(:,4)); %Seller location ID 17 | R_s= transpose(seller_data(:,5)); %Seller Reputation 18 | G_s= transpose(seller_data(:,6)); %Seller Green energy index 19 | alpha_L_s= transpose(seller_data(:,7)); %Seller location permium 20 | alpha_R_s= transpose(seller_data(:,8)); %Seller reputation permium 21 | alpha_G_s= transpose(seller_data(:,9)); %Seller green energy permium 22 | Ns= size(seller_data,1); %Number of sellers 23 | 24 | % Buyers parameters 25 | buyer_data = csvread('buyers.csv', 1, 0); 26 | I_b= transpose(buyer_data(:,1)); %Buyer ID 27 | Q_b= transpose(buyer_data(:,2)); %Buyer offer-Quantity 28 | P_b= transpose(buyer_data(:,3)); %Buyer offer-Price 29 | L_b= transpose(buyer_data(:,4)); %Buyer location ID 30 | R_b= transpose(buyer_data(:,5)); %Buyer Reputation 31 | G_b= transpose(buyer_data(:,6)); %Buyer Green energy index 32 | alpha_L_b= transpose(buyer_data(:,7)); %Buyer location permium 33 | alpha_R_b= transpose(buyer_data(:,8)); %Buyer reputation permium 34 | alpha_G_b= transpose(buyer_data(:,9)); %Buyer green energy permium 35 | Nb= size(buyer_data,1); %Number of buyers 36 | 37 | 38 | %%Checking STV constraint equation (2) 39 | for i=1:Ns 40 | if alpha_L_s(i) + alpha_R_s(i) + alpha_G_s(i) > gamma .*(P_s(i)) %if STV is not satisfied 41 | Q_s(i)= -1000; %Change seller's offer to a large negative value so that seller can not trade 42 | end 43 | end 44 | 45 | for j=1:Nb 46 | if alpha_L_b(i) + alpha_R_b(i) + alpha_G_b(i) > gamma .*(P_b(i)) %if STV is not satisfied 47 | Q_b(i)= 1000; %Change buyer's offer to a large value so that buyer can not trade 48 | end 49 | end 50 | 51 | 52 | 53 | %% Forming Utility matrices 54 | U_s= zeros(Ns,Nb); % Sellers utility matrix 55 | TP_s= zeros(Ns,Nb); % Temporary price matrix for sellers 56 | U_b = zeros(Nb,Ns); % Buyers utility matrix 57 | TP_b= zeros(Nb,Ns); % Temporary price matrix for buyers 58 | lambda= zeros(Ns,Nb); %Transaction price matrix 59 | for i=1:Ns 60 | for j=1:Nb 61 | TP_s(i,j)= P_s(i) - (alpha_L_s(i) .*(1- abs(L_s(i)-L_b(j))./M) +alpha_R_s(i).* R_b(j) + alpha_G_s(i) .* G_b(j)); %equation (15) and (16) 62 | 63 | TP_b(j,i)= P_b(j) + (alpha_L_b(j) .*(1- abs(L_s(i)-L_b(j))./M) +alpha_R_b(j).* R_s(i) + alpha_G_b(j) .* G_s(i)); %equation (17) and (18) 64 | 65 | lambda(i,j)= (TP_s(i,j) + TP_b(j,i))./2; %equation (14) 66 | 67 | U_b(j,i)= min(Q_s(i),Q_b(j)).*(P_b(j)-lambda(i,j)); %equation (12) 68 | U_s(i,j)= min(Q_s(i),Q_b(j)).*(lambda(i,j)-P_s(i)); %equation (13) 69 | end 70 | end 71 | 72 | 73 | %% Matching step 74 | MM_s=zeros(Ns,Nb); % Sellers matching matrix 75 | 76 | %Sellers matching matrix calculation 77 | for i=1:Ns %Start from the seller with the lowest offer (sellers are arranged in ascending order in input file) 78 | [B,idx]=sort(U_s(i,:),'descend'); %Arrange all avaialble buyers to seller i based on the utility 79 | for j=[idx] %for all arranged buyers 80 | if (Q_s(i) - Q_b(j)) >-3 %check if the seller can provide the requested power 81 | MM_s(i,j)=1; % Set Mtaching index to 1 82 | Q_b(j)=10000; % Change the offer of buyer to a big number so that other sellers can not choose it 83 | Q_s(i)=-10000; % Change the offer of seller to a big number so that other buyers can not choose it 84 | else % if the seller cannot provide the requested power 85 | 86 | MM_s(i,j)=0; % Set Mtaching index to 0 87 | end 88 | end 89 | 90 | end 91 | 92 | %Reset the values in Q_b and Q_s before calculating buyers matching matrix 93 | Q_b= transpose(buyer_data(:,2)); %Buyer offer-Quantity 94 | Q_s= -transpose(seller_data(:,2)); %Seller offer-Quantity 95 | 96 | MM_b=zeros(Nb,Ns); % Buyers matching matrix 97 | %Buyers matching matrix calculation 98 | for j=1:Nb %Start from the buyer with the highest bid (buyers are arranged in descending order in input file) 99 | [BB,idxx]=sort(U_b(j,:),'descend'); %Arrange all available buyers to buyer j based on the utility 100 | 101 | for i=[idxx] %for all arranged sellers 102 | if (Q_b(j) - Q_s(i)) <5 %check if the seller can provide the requested power 103 | if MM_s(i,j)~=0 %Check if the offer of seller is vailable 104 | MM_b(j,i)=1; %Set matching index to 1 105 | Q_s(i)=-10000; % Change the offer of buyer to a big number so that other sellers can not choose it 106 | Q_b(j)=10000; % Change the offer of seller to a big number so that other buyers can not choose it 107 | end 108 | 109 | else % if the seller cannot provide the requested power 110 | 111 | MM_b(j,i)=0; % Set Mtaching index to 0 112 | end 113 | end 114 | 115 | end 116 | %Reset the values in Q_b and Q_s 117 | 118 | Q_b= transpose(buyer_data(:,2)); 119 | Q_s=- transpose(seller_data(:,2)); 120 | 121 | 122 | 123 | figure %quantity 124 | w1=0.8; 125 | bar(Q_b,w1,'FaceColor',[0.2 0.2 0.5]) 126 | hold on 127 | QSS=[Q_s([3 4]),0,Q_s([12 22 11 16 13 10]),0,Q_s(6),0, Q_s([14 15 21]), 0, Q_s([9 19 20 17 7 1 2 5]),0,0 ,Q_s(23),0, Q_s([18 8 24])]; 128 | w2=0.5; 129 | bar(QSS,w2,'FaceColor',[0.3 0.9 0.9]) 130 | 131 | plot(min(Q_b,QSS), '-*','LineWidth',1,'MarkerSize',6,'Color','#D95319') 132 | legend({'Buyers Offers','Sellers Offers', 'Traded Quanitity'},'Location','northeast') 133 | hold on 134 | xlabel('Matched prosumers','FontSize',10, 'fontname','times new roman') 135 | ylabel('Power (kW)','FontSize',10, 'fontname','times new roman') 136 | set(gca,'Xtick',1:1:31,'XTickLabel',{I_b}) 137 | set(gca,'fontname','times new roman', 'FontSize',10) 138 | xtickangle(90) 139 | 140 | figure %Matching 141 | subplot(2,1,1) 142 | spy(MM_b','ko',4) 143 | xlabel({'Buyers (\it I_n)';'(a)'},'FontSize',10, 'fontname','times new roman') 144 | ylabel('Sellers (\it I_n)','FontSize',10, 'fontname','times new roman') 145 | set(gca,'Xtick',1:1:31,'XTickLabel',{I_b}) 146 | set(gca,'Ytick',1:1:24,'YTickLabel',{I_s}) 147 | set(gca,'fontname','times new roman', 'FontSize',8) 148 | xtickangle(90) 149 | hold on 150 | xbox1 =[0 0 4.5 4.5]; 151 | ybox1= [0 8.5 8.5 0]; 152 | patch(xbox1, ybox1, 'black', 'Facecolor', 'green', 'FaceAlpha',0.2) 153 | hold on 154 | xbox2 =[4.5 4.5 19.5 19.5]; 155 | ybox2= [8.5 13.5 13.5 8.5]; 156 | patch(xbox2, ybox2, 'black', 'Facecolor', 'green', 'FaceAlpha',0.2) 157 | 158 | hold on 159 | xbox3 =[19.5 19.5 23.5 23.5]; 160 | ybox3= [13.5 19.5 19.5 13.5]; 161 | patch(xbox3, ybox3, 'black', 'Facecolor', 'green', 'FaceAlpha',0.2) 162 | 163 | hold on 164 | xbox4 =[23.5 23.5 32 32]; 165 | ybox4= [19.5 25 25 19.5]; 166 | patch(xbox4, ybox4, 'black', 'Facecolor', 'green', 'FaceAlpha',0.2) 167 | 168 | hold on 169 | xbox5 =[0 0 32 32]; 170 | ybox5= [0 25 25 0]; 171 | patch(xbox5, ybox5, 'black', 'Facecolor', 'black', 'FaceAlpha',0.1) 172 | 173 | subplot(2,1,2) 174 | MM_np=[0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0;0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1;1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0;0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; 175 | spy(MM_np','ko',4) 176 | xlabel({'Buyers (\it I_n)';'(b)'},'FontSize',10, 'fontname','times new roman') 177 | ylabel('Sellers (\it I_n)','FontSize',10, 'fontname','times new roman') 178 | set(gca,'Xtick',1:1:31,'XTickLabel',{I_b}) 179 | set(gca,'Ytick',1:1:24,'YTickLabel',{I_s}) 180 | set(gca,'fontname','times new roman', 'FontSize',8) 181 | xtickangle(90) 182 | hold on 183 | xbox1 =[0 0 4.5 4.5]; 184 | ybox1= [0 8.5 8.5 0]; 185 | patch(xbox1, ybox1, 'black', 'Facecolor', 'green', 'FaceAlpha',0.2) 186 | hold on 187 | xbox2 =[4.5 4.5 19.5 19.5]; 188 | ybox2= [8.5 13.5 13.5 8.5]; 189 | patch(xbox2, ybox2, 'black', 'Facecolor', 'green', 'FaceAlpha',0.2) 190 | 191 | hold on 192 | xbox3 =[19.5 19.5 23.5 23.5]; 193 | ybox3= [13.5 19.5 19.5 13.5]; 194 | patch(xbox3, ybox3, 'black', 'Facecolor', 'green', 'FaceAlpha',0.2) 195 | 196 | hold on 197 | xbox4 =[23.5 23.5 32 32]; 198 | ybox4= [19.5 25 25 19.5]; 199 | patch(xbox4, ybox4, 'black', 'Facecolor', 'green', 'FaceAlpha',0.2) 200 | 201 | hold on 202 | xbox5 =[0 0 32 32]; 203 | ybox5= [0 25 25 0]; 204 | patch(xbox5, ybox5, 'black', 'Facecolor', 'black', 'FaceAlpha',0.1) 205 | 206 | 207 | 208 | figure %Utility 209 | clims = [0 1]; 210 | imagesc((U_s./max(U_s)+U_b'./max(U_b)')./2,clims) 211 | hold on 212 | map2= [0.95 0.95 0.95; 0.01 0.98 0.01;0.12 0.79 0.12;0.17 0.62 0.17;0.18 0.4 0.18]; 213 | colormap(map2); 214 | 215 | hold on 216 | c1 = colorbar; 217 | hold on 218 | spy(MM_np','ro',4) 219 | xlabel('Buyers (\it I_n)','FontSize',10, 'fontname','times new roman') 220 | ylabel('Sellers (\it I_n)','FontSize',10, 'fontname','times new roman') 221 | set(gca,'Xtick',1:1:31,'XTickLabel',{I_b}) 222 | set(gca,'Ytick',1:1:24,'YTickLabel',{I_s}) 223 | set(gca,'fontname','times new roman', 'FontSize',8) 224 | xtickangle(90) 225 | 226 | figure %dailyperformance of prosumers 227 | %The data for this figure is taken from load/generation profile of prosumers and their energy trading over different time slots. 228 | %P2P trade of prosumers 229 | p2_p2p=[0.018 0.169 0.181 0.294 0.172 0.205 0.338 0.337 -1.017 -2.482 0.143 -0.955 -0.99 -0.962 -0.801 -1.393 -0.945 -1.122 -1.067 -1.202]; 230 | p16_p2p=[-0.472 -0.684 -1.017 -1.247 -1.276 -1.43 -1.711 -2.004 -2.776 -3.063 -2.29 -2.614 -3.036 -2.611 -2.394 -2.589 -1.942 -1.732 -1.678 -1.346]; 231 | p39_p2p=[-0.539 -0.227 -0.792 -0.242 0.051 2.115 2.171 2.004 2.063 2.224 2.199 2.234 2.263 2.209 2.21 0.185 0.148 0.088 0.097 0.102]; 232 | 233 | %Daily load and generation of prsumers (first row load, second row generation) 234 | p2_LG=[0.187 0.19 0.187 0.185 0.183 0.182 0.183 0.189 0.182 0.191 0.186 0.186 0.325 0.21 0.182 0.119 0.182 0.125 0.278 0.283 0.225 0.257 1.623 3.095 0.482 1.561 1.578 1.518 1.314 1.856 1.351 1.453 1.323 1.371 1.566 1.553 1.589 0.83 1.119 0.815 0.497 0.331 0.306 0.355 0.316 0.302 0.222 0.189 235 | 0 0 0 0.000 0 0 0 0 0 0 0 0 0.013 0.106 0.2 0.288 0.363 0.419 0.45 0.488 0.563 0.594 0.606 0.613 0.625 0.606 0.588 0.556 0.513 0.463 0.406 0.331 0.256 0.169 0.088 0.031 0.013 0.013 0 0 0 0 0 0 0 0 0.006 0]; 236 | p16_LG=[0.265 0.232 0.188 0.261 0.395 0.241 0.158 0.194 0.153 0.172 0.167 0.141 0.345 0.282 0.472 0.684 1.017 1.247 1.276 1.43 1.711 2.004 2.776 3.063 2.29 2.614 3.036 2.611 2.394 2.589 1.942 1.732 1.678 1.346 0.927 0.938 1.083 0.908 1.015 1.593 1.275 0.894 0.473 0.491 0.43 0.688 0.222 0.298]; 237 | 238 | p39_LG=[0.145 0.154 0.162 2.204 0.99 0.106 0.11 0.196 0.142 0.135 0.113 0.102 0.115 0.115 0.545 0.24 0.861 0.417 0.174 0.148 0.123 0.321 0.281 0.132 0.176 0.141 0.125 0.172 0.159 0.184 0.196 0.237 0.191 0.154 0.766 0.903 0.877 1.172 0.996 0.911 0.553 0.347 0.316 0.323 0.296 0.314 0.405 0.25 239 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0.006 0.006 0.013 0.069 0.175 0.225 0.263 0.294 0.325 0.344 0.356 0.375 0.375 0.388 0.381 0.369 0.369 0.344 0.325 0.288 0.256 0.213 0.163 0.1 0.031 0 0 0 0 0 0 0 0 0 0]; 240 | 241 | subplot(2,1,1) 242 | plot(p2_LG(1,:)-p2_LG(2,:),'-^','LineWidth',1,'MarkerSize',4, 'Color','#0072BD') 243 | hold on 244 | % plot(p2(2,:),'-b','LineWidth',1) 245 | hold on 246 | plot(p16_LG,'-ob','LineWidth',1,'MarkerSize',4,'Color','#D95319') 247 | hold on 248 | plot(p39_LG(1,:)-p39_LG(2,:),'-sr','LineWidth',1,'MarkerSize',4,'Color','#EDB120') 249 | hold on 250 | % plot(p39(2,:),'-.b','LineWidth',1) 251 | hold on 252 | plot([0,48],[0,0],'-.k','LineWidth',1) 253 | hold on 254 | xbox5 =[15 15 34 34]; 255 | ybox5= [-0.5 3.5 3.5 -0.5]; 256 | patch(xbox5, ybox5, 'black', 'Facecolor', 'black', 'FaceAlpha',0.07) 257 | % plot([0 10],[0 0], '--','LineWidth',2) 258 | xlabel({'Time (hh:mm)';'(a)'},'FontSize',12, 'fontname','times new roman') 259 | ylabel('Net Power (kW)','FontSize',12, 'fontname','times new roman') 260 | % set(gca,'Xtick',1:1:10,['10:30', '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30' ,'15:00'],'XTickLabel',{I_b}) 261 | % set(gca,'Ytick',1:1:24,'YTickLabel',{I_s}) 262 | xticks([1:2:48]) 263 | xticklabels({'1:00','2:00','3:00','4:00','5:00','6:00','7:00','8:00','9:00','10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00','0:00'}) 264 | legend('P2', 'P16','P39','Orientation','horizontal'); 265 | xtickangle(90) 266 | xlim([1,48]) 267 | ylim([-0.5,3.5]) 268 | set(gca,'fontname','times new roman', 'FontSize',12) 269 | subplot(2,1,2) 270 | bar([p39_p2p; p16_p2p; p2_p2p]') 271 | % bar([buy39]','r') 272 | % hold on 273 | % bar([sell16]','b') 274 | xticks([1:1:20]) 275 | xticklabels({'8:00','8:30','9:00','9:30','10:00','10:30','11:00','11:30','12:00','12:30','13:00','13:30','14:00','14:30','15:00','15:30','16:00','16:30','17:00','17:30'}) 276 | xtickangle(90) 277 | ylim([-3.5,2.5]) 278 | xlabel({'Time (hh:mm)';'(b)'},'FontSize',12, 'fontname','times new roman') 279 | ylabel('Traded power (kW)','FontSize',12, 'fontname','times new roman') 280 | set(gca,'fontname','times new roman', 'FontSize',12) 281 | legend('\fontname{Times New Roman} P2','\fontname{Times New Roman} P16', '\fontname{Times New Roman} P39','Orientation','horizontal'); 282 | 283 | 284 | %Export output data 285 | csvwrite('matchs.csv', MM_s); 286 | csvwrite('matchb.csv', MM_b); 287 | csvwrite('utilitys.csv', U_s); 288 | csvwrite('utilityb.csv', U_b); 289 | csvwrite('marketp.csv', lambda); 290 | csvwrite('finaloffer.csv', TP_s); 291 | csvwrite('finalbid.csv', TP_b); 292 | csvwrite('31buyer.csv', buyer_data); 293 | csvwrite('24seller.csv', seller_data); 294 | --------------------------------------------------------------------------------