-
Notifications
You must be signed in to change notification settings - Fork 1
/
EE7400_3_10_Stochastic_GEP_problem_using_dynamic_approach_NC.m
208 lines (170 loc) · 10.3 KB
/
EE7400_3_10_Stochastic_GEP_problem_using_dynamic_approach_NC.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
clc
clear classes
%% Read system input
p_cq=[0;100;200;300;400;500];
M = 5000;
investment_per_MW=70000;
Demand=zeros(2,2,4);
Demand(:,:,1)=[212,402;214,407];
Demand(:,:,2)=[212,402;284,539];
Demand(:,:,3)=[281,533;284,539];
Demand(:,:,4)=[281,533;377,715];
%% Define problem variables % time period in row, op con in column
%Primal variable
P_existing_gen = sdpvar(2,2,4,'full'); % Generation
P_can_gen = sdpvar(2,2,4,'full'); % Candidate Generation
P_can_max = sdpvar(2,1,4,'full'); % Candidate Generation maximum
Pline = sdpvar(2,2,4,'full');
Del1 = sdpvar(2,2,4,'full');
Del2 = sdpvar(2,2,4,'full');
%Dual variable
lamda1=sdpvar(2,2,4,'full');
lamda2=sdpvar(2,2,4,'full');
mu_ex_gen=sdpvar(2,2,4,'full');
mu_can_gen=sdpvar(2,2,4,'full');
mu_line=sdpvar(2,2,4,'full');
mu_line_max=sdpvar(2,2,4,'full');
mu_line_min=sdpvar(2,2,4,'full');
mu_del1_max=sdpvar(2,2,4,'full');
mu_del1_min=sdpvar(2,2,4,'full');
mu_del2_max=sdpvar(2,2,4,'full');
mu_del2_min=sdpvar(2,2,4,'full');
mu_del_ref=sdpvar(2,2,4,'full');
%Binary variable
u_cq = binvar(6,2,4,'full');
z_cqo= binvar(6,4,4,'full');
z_cqo_cap= binvar(6,4,4,'full');
%% Building objective function
Objective=0;
for w=1:4
Objective = Objective + 0.25*[P_can_max(1,1,w)*140000+P_can_max(2,1,w)*70000 +...
6000*(35*P_existing_gen(1,1,w) + 25*P_can_gen(1,1,w)) + 2760*(35*P_existing_gen(1,2,w) + 25*P_can_gen(1,2,w))+... %time period 1
6000*(35*P_existing_gen(2,1,w) + 25*P_can_gen(2,1,w)) + 2760*(35*P_existing_gen(2,2,w) + 25*P_can_gen(2,2,w))] ; %time period 2
end
%% constraints
Constraints = [];
for w=1:4
Constraints=[Constraints, sum(u_cq(:,1,w).*p_cq) == P_can_max(1,1,w)];
Constraints=[Constraints, sum(u_cq(:,2,w).*p_cq) == P_can_max(2,1,w)];
Constraints=[Constraints, sum(u_cq(:,1,w)) == 1];
Constraints=[Constraints, sum(u_cq(:,2,w)) == 1];
end
Constraints=[Constraints,P_can_max(1,1,1)==P_can_max(1,1,2)];
Constraints=[Constraints,P_can_max(1,1,2)==P_can_max(1,1,3)];
Constraints=[Constraints,P_can_max(1,1,3)==P_can_max(1,1,4)];
Constraints=[Constraints,P_can_max(2,1,1)==P_can_max(2,1,2)];
Constraints=[Constraints,P_can_max(2,1,3)==P_can_max(2,1,4)];
for w=1:4
%% Time period 1, Operating condition 1
Constraints=[Constraints, P_existing_gen(1,1,w) - Pline(1,1,w) == 0];
Constraints=[Constraints, P_can_gen(1,1,w) + Pline(1,1,w) == Demand(1,1,w)];
Constraints=[Constraints, Pline(1,1,w) == 500*(Del1(1,1,w)-Del2(1,1,w))];
Constraints=[Constraints, -500 <= Pline(1,1,w) <= 500];
Constraints=[Constraints, P_existing_gen(1,1,w) + P_can_gen(1,1,w) == Demand(1,1,w)];
Constraints=[Constraints, 0 <= P_existing_gen(1,1,w) <= 400];
Constraints=[Constraints, 0 <= P_can_gen(1,1,w) <= P_can_max(1,1,w)];
Constraints=[Constraints, -pi <= Del2(1,1,w) <= pi];
Constraints=[Constraints, Del1(1,1,w) == 0];
Constraints=[Constraints, 35-lamda1(1,1,w)+mu_ex_gen(1,1,w)>=0];
Constraints=[Constraints, 25-lamda2(1,1,w)+mu_can_gen(1,1,w)>=0];
Constraints=[Constraints, lamda1(1,1,w)-lamda2(1,1,w)-mu_line(1,1,w)+mu_line_max(1,1,w)-mu_line_min(1,1,w)==0];
Constraints=[Constraints, -500*mu_line(1,1,w)+mu_del2_max(1,1,w)-mu_del2_min(1,1,w)==0];
Constraints=[Constraints, 500*mu_line(1,1,w)+ mu_del_ref(1,1,w)==0];
Constraints=[Constraints, mu_ex_gen(1,1,w)>=0];
Constraints=[Constraints, mu_can_gen(1,1,w)>=0];
Constraints=[Constraints, mu_line_max(1,1,w)>=0];
Constraints=[Constraints, mu_line_min(1,1,w)>=0];
Constraints=[Constraints, mu_del1_max(1,1,w)>=0];
Constraints=[Constraints, mu_del1_min(1,1,w)>=0];
Constraints=[Constraints, 35*P_existing_gen(1,1,w) + 25*P_can_gen(1,1,w)==Demand(1,1,w)*lamda2(1,1,w)-400*mu_ex_gen(1,1,w)-sum(z_cqo(:,1,w))-...
500*(mu_line_max(1,1,w)+mu_line_min(1,1,w)) - pi*(mu_del2_max(1,1,w)+mu_del2_min(1,1,w))];
Constraints=[Constraints, z_cqo(:,1,w)== p_cq*mu_can_gen(1,1,w)-z_cqo_cap(:,1,w)];
Constraints=[Constraints, 0<=z_cqo(:,1,w)<=u_cq(:,1,w)*M];
Constraints=[Constraints, 0<=z_cqo_cap(:,1,w)<=(1-u_cq(:,1,w))*M];
%% Time period 1,Operating condition 2
Constraints=[Constraints, P_existing_gen(1,2,w) - Pline(1,2,w) == 0];
Constraints=[Constraints, P_can_gen(1,2,w) + Pline(1,2,w) == Demand(1,2,w)];
Constraints=[Constraints, Pline(1,2,w) == 500*(Del1(1,2,w)-Del2(1,2,w))];
Constraints=[Constraints, -500 <= Pline(1,2,w) <= 500];
Constraints=[Constraints, P_existing_gen(1,2,w) + P_can_gen(1,2,w) == Demand(1,2,w)];
Constraints=[Constraints, 0 <= P_existing_gen(1,2,w) <= 400];
Constraints=[Constraints, 0 <= P_can_gen(1,2,w) <= P_can_max(1,1,w)];
Constraints=[Constraints, -pi <= Del2(1,2,w) <= pi];
Constraints=[Constraints, Del1(1,2,w) == 0];
Constraints=[Constraints, 35-lamda1(1,2,w)+mu_ex_gen(1,2,w)>=0];
Constraints=[Constraints, 25-lamda2(1,2,w)+mu_can_gen(1,2,w)>=0];
Constraints=[Constraints, lamda1(1,2,w)-lamda2(1,2,w)-mu_line(1,2,w)+mu_line_max(1,2,w)-mu_line_min(1,2,w)==0];
Constraints=[Constraints, -500*mu_line(1,2,w)+mu_del2_max(1,2,w)-mu_del2_min(1,2,w)==0];
Constraints=[Constraints, 500*mu_line(1,2,w)+ mu_del_ref(1,2,w)==0];
Constraints=[Constraints, mu_ex_gen(1,2,w)>=0];
Constraints=[Constraints, mu_can_gen(1,2,w)>=0];
Constraints=[Constraints, mu_line_max(1,2,w)>=0];
Constraints=[Constraints, mu_line_min(1,2,w)>=0];
Constraints=[Constraints, mu_del1_max(1,2,w)>=0];
Constraints=[Constraints, mu_del1_min(1,2,w)>=0];
Constraints=[Constraints, 35*P_existing_gen(1,2,w)+25*P_can_gen(1,2,w)==Demand(1,2,w)*lamda2(1,2,w)-400*mu_ex_gen(1,2,w)-sum(z_cqo(:,2,w))-...
500*(mu_line_max(1,2,w)+mu_line_min(1,2,w)) - pi*(mu_del2_max(1,2,w)+mu_del2_min(1,2,w))];
Constraints=[Constraints, z_cqo(:,2,w)== p_cq*mu_can_gen(1,2,w)-z_cqo_cap(:,2,w)];
Constraints=[Constraints, 0<=z_cqo(:,2,w)<=u_cq(:,1,w)*M];
Constraints=[Constraints, 0<=z_cqo_cap(:,2,w)<=(1-u_cq(:,1,w))*M];
%% Time period 2, Operating condition 1
Constraints=[Constraints, P_existing_gen(2,1,w) - Pline(2,1,w) == 0];
Constraints=[Constraints, P_can_gen(2,1,w) + Pline(2,1,w) == Demand(2,1,w)];
Constraints=[Constraints, Pline(2,1,w) == 500*(Del1(2,1,w)-Del2(2,1,w))];
Constraints=[Constraints, -500 <= Pline(2,1,w) <= 500];
Constraints=[Constraints, P_existing_gen(2,1,w) + P_can_gen(2,1,w) == Demand(2,1,w)];
Constraints=[Constraints, 0 <= P_existing_gen(2,1,w) <= 400];
Constraints=[Constraints, 0 <= P_can_gen(2,1,w) <= P_can_max(1,1,w) + P_can_max(2,1,w)];% sum of 'P_can_max' in two time period
Constraints=[Constraints, -pi <= Del2(2,1,w) <= pi];
Constraints=[Constraints, Del1(2,1,w) == 0];
Constraints=[Constraints, 35-lamda1(2,1,w)+mu_ex_gen(2,1,w)>=0];
Constraints=[Constraints, 25-lamda2(2,1,w)+mu_can_gen(2,1,w)>=0];
Constraints=[Constraints, lamda1(2,1,w)-lamda2(2,1,w)-mu_line(2,1,w)+mu_line_max(2,1,w)-mu_line_min(2,1,w)==0];
Constraints=[Constraints, -500*mu_line(2,1,w)+mu_del2_max(2,1,w)-mu_del2_min(2,1,w)==0];
Constraints=[Constraints, 500*mu_line(2,1,w)+ mu_del_ref(2,1,w)==0];
Constraints=[Constraints, mu_ex_gen(2,1,w)>=0];
Constraints=[Constraints, mu_can_gen(2,1,w)>=0];
Constraints=[Constraints, mu_line_max(2,1,w)>=0];
Constraints=[Constraints, mu_line_min(2,1,w)>=0];
Constraints=[Constraints, mu_del1_max(2,1,w)>=0];
Constraints=[Constraints, mu_del1_min(2,1,w)>=0];
Constraints=[Constraints, 35*P_existing_gen(2,1,w) + 25*P_can_gen(2,1,w)==Demand(2,1,w)*lamda2(2,1,w)-400*mu_ex_gen(2,1,w)-sum(z_cqo(:,3,w))-...
500*(mu_line_max(2,1,w)+mu_line_min(2,1,w)) - pi*(mu_del2_max(2,1,w)+mu_del2_min(2,1,w))];
Constraints=[Constraints, z_cqo(:,3,w)== p_cq*mu_can_gen(2,1,w)-z_cqo_cap(:,3,w)];
Constraints=[Constraints, 0<=z_cqo(:,3,w)<=u_cq(:,2,w)*M];
Constraints=[Constraints, 0<=z_cqo_cap(:,3,w)<=(1-u_cq(:,2,w))*M];
%% Time period 2,Operating condition 2
Constraints=[Constraints, P_existing_gen(2,2,w) - Pline(2,2,w) == 0];
Constraints=[Constraints, P_can_gen(2,2,w) + Pline(2,2,w) == Demand(2,2,w)];
Constraints=[Constraints, Pline(2,1,w) == 500*(Del1(2,1,w)-Del2(2,2,w))];
Constraints=[Constraints, -500 <= Pline(2,2,w) <= 500];
Constraints=[Constraints, P_existing_gen(2,2,w) + P_can_gen(2,2,w) == Demand(2,2,w)];
Constraints=[Constraints, 0 <= P_existing_gen(2,2,w) <= 400];
Constraints=[Constraints, 0 <= P_can_gen(2,2,w) <= P_can_max(1,1,w) + P_can_max(2,1,w)];% sum of 'P_can_max' in two time period
Constraints=[Constraints, -pi <= Del2(2,2,w) <= pi];
Constraints=[Constraints, Del1(2,2,w) == 0];
Constraints=[Constraints, 35-lamda1(2,2,w)+mu_ex_gen(2,2,w)>=0];
Constraints=[Constraints, 25-lamda2(2,2,w)+mu_can_gen(2,2,w)>=0];
Constraints=[Constraints, lamda1(2,2,w)-lamda2(2,2,w)-mu_line(2,2,w)+mu_line_max(2,2,w)-mu_line_min(2,2,w)==0];
Constraints=[Constraints, -500*mu_line(2,2,w)+mu_del2_max(2,2,w)-mu_del2_min(2,2,w)==0];
Constraints=[Constraints, 500*mu_line(2,2,w)+ mu_del_ref(2,2,w)==0];
Constraints=[Constraints, mu_ex_gen(2,2,w)>=0];
Constraints=[Constraints, mu_can_gen(2,2,w)>=0];
Constraints=[Constraints, mu_line_max(2,2,w)>=0];
Constraints=[Constraints, mu_line_min(2,2,w)>=0];
Constraints=[Constraints, mu_del1_max(2,2,w)>=0];
Constraints=[Constraints, mu_del1_min(2,2,w)>=0];
Constraints=[Constraints, 35*P_existing_gen(2,2,w)+25*P_can_gen(2,2,w)==Demand(2,2,w)*lamda2(2,2,w)-400*mu_ex_gen(2,2,w)-sum(z_cqo(:,4,w))-...
500*(mu_line_max(2,2,w)+mu_line_min(2,2,w)) - pi*(mu_del2_max(2,2,w)+mu_del2_min(2,2,w))];
Constraints=[Constraints, z_cqo(:,4,w)== p_cq*mu_can_gen(2,2,w)-z_cqo_cap(:,4,w)];
Constraints=[Constraints, 0<=z_cqo(:,4,w)<=u_cq(:,2,w)*M];
Constraints=[Constraints, 0<=z_cqo_cap(:,4,w)<=(1-u_cq(:,2,w))*M];
end
%% finding optimal solution
ops = sdpsettings('verbose',0,'debug',1);
Solution = optimize(Constraints,Objective,ops)
P_can_max=value(P_can_max)
u_cq=value(u_cq)
P_existing_gen=value(P_existing_gen)
P_can_gen=value(P_can_gen)
value(Objective)