-
Notifications
You must be signed in to change notification settings - Fork 8
/
TestMain_Bat.m
131 lines (116 loc) · 4.97 KB
/
TestMain_Bat.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
%Test Main with the lab updates as InputDate
close all
clear all
clc
% load InputData.mat
load MG2_PV_forecast_summer;
load MG2_Load24h_15min;
load MG2_PV_real_summer;
load MG2_Load_real;
PV_24h=MG2_PV_forecast_summer';
PV_real_24h=MG2_PV_real_summer';
Pload_24h=MG2_Load24h_15min; %in W
Pload_real_24h=MG2_Load_real;
InputData.timeStart=0;
InputData.timeHorizon=6;
InputData.maximum_capacity_battery=7500; %Wh
InputData.max_batt_discharge=5000; %W
InputData.max_batt_charge=3000; %W
InputData.SoC=0.5*InputData.maximum_capacity_battery; %Wh
PriceBuy=[repmat(9.33,1,28) repmat(16.05,1,44) repmat(12.07,1,16) repmat(9.33,1,8)];
PriceSell=repmat(0.3,1,96);
% InputDataReal=InputData;
% InputDataReal.Pload=Pload_real_24h(InputData.timeStart*4+1:4*(InputData.timeStart+InputData.timeHorizon));
% InputDataReal.Ppv=PV_real_24h(InputData.timeStart*4+1:4*(InputData.timeStart+InputData.timeHorizon));
% read_time2=toc; %send to display the time it took to read the data
%AICI
for i=1:(24-6)*4
% InputData.timeStart=i/4;
InputData.timeStart=i;
% i=1;
% t=InputData.timeStart+i*InputData.timeHorizon;
% % % % % InputData.Pload=Pload_24h(InputData.timeStart*4+1:4*(InputData.timeStart+InputData.timeHorizon));
% % % % % InputData.Ppv=PV_24h(InputData.timeStart*4+1:4*(InputData.timeStart+InputData.timeHorizon));
% % % % % InputData.PriceBuy=PriceBuy(InputData.timeStart*4+1:4*(InputData.timeStart+InputData.timeHorizon));
% % % % % InputData.PriceSell=PriceSell(InputData.timeStart*4+1:4*(InputData.timeStart+InputData.timeHorizon));
% % % % % [References]=MILP_microgrid_optimizationIC_Bat(InputData);
InputData.Pload=Pload_24h(i:i+23);
InputData.Ppv=PV_24h(i:i+23);
InputData.PriceBuy=PriceBuy(i:i+23);
InputData.PriceSell=PriceSell(i:i+23);
[References]=MILP_microgrid_optimizationIC_Bat(InputData);
% fprintf('sum References each row shall be equal to Pgrid:\n')
% sum(References,2)
% References
i
ReferencesOUT_EMS=References(1,:)
OUT_EMS(i,:)=ReferencesOUT_EMS;
% ReferencesOUT_EMS(i,:)=References(1,:);
% ReferencesOUT_EMS(i,:)
% ReferencesReal(i,:)=[InputDataReal.Ppv(i)/1000 -InputDataReal.Pload(i)/1000 References(1,3) References(1,4)];
ReferencesReal=[PV_real_24h(i)/1000 -Pload_real_24h(i)/1000 References(1,3) References(1,5)]
REAL(i,:)=ReferencesReal;
% ReferencesReal(i,:)
% PgridSetUp(i)=-sum(ReferencesReal(i,:),2);
Pbat_measured=-sum(ReferencesReal,2);
PbatMeasured(i)=-sum(ReferencesReal,2);
%update InputData.Ppv for the next EMS call
InputData.SoC=InputData.SoC+Pbat_measured*0.25;
InputData.Ppv(1:24)= PV_24h(i+1:i+24);
PpvNext24points=PV_24h(i+1:i+24);
Ppv_predictedNext15min=InputData.Ppv(1);
% ReferencesReal(1,1)*1000;
InputData.Ppv(1)=(InputData.Ppv(1)+ReferencesReal(1,1)*1000)/2; %(InputData.Ppv(1)+mean(Preal1(counter3min-2:counter3min)))/2
Ppv_adjustedAvgPrevMeasNext15min=InputData.Ppv(1);
Ppv_predictedNext30min=InputData.Ppv(2);
InputData.Ppv(2)=0.5*(InputData.Ppv(2)+InputData.Ppv(1))/2+0.3*InputData.Ppv(2)+0.2*InputData.Ppv(3);
Ppv_adjustedAvgPrevMeasNext30min=InputData.Ppv(2);
%update InputData.Pload for the next EMS call
InputData.Pload(1:24)= Pload_24h(i+1:i+24);
PloadNext24points=Pload_24h(i+1:i+24);
Pload_predictedNext15min=InputData.Pload(1);
% ReferencesReal(1,1)*1000;
InputData.Pload(1)=(InputData.Pload(1)+abs(ReferencesReal(1,2)*1000))/2;%=(InputData.Pload(1)+mean(Preal2(counter3min-2:counter3min)))/2;
Pload_adjustedAvgPrevMeasNext15min=InputData.Pload(1);
Pload_predictedNext30min=InputData.Pload(2);
InputData.Pload(2)=0.5*(InputData.Pload(2)+InputData.Pload(1))/2+0.3*InputData.Pload(2)+0.2*InputData.Pload(3);
Pload_adjustedAvgPrevMeasNext30min=InputData.Pload(2);
% %TO BE DELETED
% fprintf('counter\n')
% i
% fprintf('check if OK: counter15min:counter15min+23 aka counter15min=2 => 2:25 \n')
% i+1:i+1+4*InputData.timeHorizon-1
% %END %TO BE DELETED
%update InputData for prices in the next call
InputData.PriceBuy=PriceBuy(i+1:i+24);
InputData.PriceSell=PriceSell(i+1:i+24);
end
% [ReferencesReal]=MILP_microgrid_optimizationIC(InputDataReal);
% fprintf('sum ReferencesReal each row shall be equal to Pgrid:\n')
% sum(ReferencesReal,2)
% ReferencesReal
OUT_EMS
REAL
% x_time=[InputData.timeStart:1/4:InputData.timeStart+InputData.timeHorizon];
x_time=0:1/4:i/4-0.25;
figure()
plot(x_time(1:end),OUT_EMS(:,1), '.-y',...
x_time(1:end),OUT_EMS(:,2), '.-r',...
x_time(1:end),OUT_EMS(:,3), '.-b',...
x_time(1:end),OUT_EMS(:,4), '.-g',...
x_time(1:end),OUT_EMS(:,5), '.-k');
title('EMS references')
xlabel('Time (h)')
ylabel ('Power (kW)')
legend('Ppv', 'Pload', 'Psell_neigh', 'Pbat', 'Pgrid');
figure()
plot(x_time(1:end),REAL(:,1), '.-y',...
x_time(1:end),REAL(:,2), '.-r',...
x_time(1:end),REAL(:,3), '.-b',...
x_time(1:end),REAL(:,4), '.-k',...
x_time(1:end),PbatMeasured, '.-g');
title('REAL references')
xlabel('Time (h)')
ylabel ('Power (kW)')
legend('PpvReal','PloadReal', 'PsellNeighEMS', 'PgridEMS', 'PbatCalc');
PbatMeasured