-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathtransmission.jl
More file actions
703 lines (641 loc) · 45.6 KB
/
transmission.jl
File metadata and controls
703 lines (641 loc) · 45.6 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
@doc raw"""
transmission!(EP::Model, inputs::Dict, setup::Dict)
This function establishes decisions, expressions, and constraints related to transmission power flows between model zones and associated transmission
losses (if modeled).
Power flow and transmission loss terms are also added to the power balance constraint for each zone:
```math
\begin{aligned}
& - \sum_{l\in \mathcal{L}}{(\varphi^{map}_{l,z} \times \Phi_{l,t})} - \frac{1}{2} \sum_{l\in \mathcal{L}}{(\varphi^{map}_{l,z} \times \beta_{l,t}(\cdot))}
\end{aligned}
```
Power flows, $\Phi_{l,t}$, on each line $l$ into or out of a zone (defined by the network map $\varphi^{map}_{l,z}$), are considered in the demand balance
equation for each zone. By definition, power flows leaving their reference zone are positive, thus the minus sign is used for this term.
Losses due to power flows increase demand, and one-half of losses across a line linking two zones are attributed to each connected zone.
The losses function $\beta_{l,t}(\cdot)$ will depend on the configuration used to model losses (see below).
**Accounting for Transmission Between Zones**
Power flow, $\Phi_{l,t}$, on each line (or more likely a `path' aggregating flows across multiple parallel lines) is constrained to be less than or
equal to the line's power transfer capacity, $\varphi^{cap}_{l}$, plus any transmission capacity added on that line (for lines eligible for expansion
in the set $\mathcal{E}$). The additional transmission capacity, $\bigtriangleup\varphi^{cap}_{l} $, is constrained by a maximum allowed
reinforcement, $\overline{\bigtriangleup\varphi^{cap}_{l}}$, for each line $l \in \mathcal{E}$. For asymmetric bidirectional lines, the capacity added
in the two directions are considered separately and are denoted as $\varphi^{cap}_{l}^{+}$ and $\varphi^{cap}_{l}^{-}$, respectively, plus any any transmission
capacity added, denoted by $\bigtriangleup\varphi^{cap}_{l}^{+}$ and $\bigtriangleup\varphi^{cap}_{l}^{-}$, respectively.
```math
\begin{aligned}
% trasmission constraints
&-\varphi^{cap}_{l} \leq \Phi_{l,t} \leq \varphi^{cap}_{l} , &\quad \forall l \in \mathcal{L},\forall t \in \mathcal{T}\\
\end{aligned}
```
**Accounting for Transmission Between Zones with Asymmetrical Flow Limits**
```math
\begin{aligned}
% trasmission constraints
&-\varphi^{cap}_{l}^{-} \leq \Phi_{l,t} \leq \varphi^{cap}_{l}^{+} , &\quad \forall l \in \mathcal{L_{asym}},\forall t \in \mathcal{T}\\
\end{aligned}
```
**Accounting for Transmission Losses**
Transmission losses due to power flows can be accounted for in three different ways. The first option is to neglect losses entirely, setting the value of the losses function to zero for all lines at all hours. The second option is to assume that losses are a fixed percentage, $\varphi^{loss}_{l}$, of the magnitude of power flow on each line, $\mid \Phi_{l,t} \mid$ (e.g., losses are a linear function of power flows). Finally, the third option is to calculate losses, $\ell_{l,t}$, by approximating a quadratic-loss function of power flow across the line using a piecewise-linear function with total number of segments equal to the size of the set $\mathcal{M}$.
```math
\begin{aligned}
%configurable losses formulation
& \beta_{l,t}(\cdot) = \begin{cases} 0 & \text{if~} \text{losses.~0} \\ \\ \varphi^{loss}_{l}\times \mid \Phi_{l,t} \mid & \text{if~} \text{losses.~1} \\ \\ \ell_{l,t} &\text{if~} \text{losses.~2} \end{cases}, &\quad \forall l \in \mathcal{L},\forall t \in \mathcal{T}
\end{aligned}
```
In the above, when accounting for asymmetrical lines
```math
\begin{aligned}
%configurable losses formulation
& \beta_{l,t}(\cdot) = \begin{cases} 0 & \text{if~} \text{losses.~0} \\ \\ \varphi^{loss (+)}_{l} \times \Phi^{+}_{l,t} + \varphi^{loss (-)}_{l} \times \Phi^{-}_{l,t} & \text{if~} \text{losses.~1} \\ \\ \ell^{+}_{l,t}, \ell^{+}_{l,t}, &\text{if~} \text{losses.~2} \end{cases}, &\quad \forall l \in \mathcal{L},\forall t \in \mathcal{T}
\end{aligned}
```
For the second option, an absolute value approximation is utilized to calculate the magnitude of the power flow on each line (reflecting the fact that negative power flows for a line linking nodes $i$ and $j$ represents flows from node $j$ to $i$ and causes the same magnitude of losses as an equal power flow from $i$ to $j$). This absolute value function is linearized such that the flow in the line must be equal to the subtraction of the auxiliary variable for flow in the positive direction, $\Phi^{+}_{l,t}$, and the auxiliary variable for flow in the negative direction, $\Phi^{+}_{l,t}$, of the line. Then, the magnitude of the flow is calculated as the sum of the two auxiliary variables. The sum of positive and negative directional flows are also constrained by the line flow capacity.
```math
\begin{aligned}
% trasmission losses simple
&\Phi_{l,t} = \Phi^{+}_{l,t} - \Phi^{-}_{l,t}, &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T}\\
&\mid \Phi_{l,t} \mid = \Phi^{+}_{l,t} + \Phi^{-}_{l,t}, &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T}\\
&\Phi^{+}_{l,t} + \Phi^{-}_{l,t} \leq \varphi^{cap}_{l}, &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T}\\
&\Phi^{+}_{l,t} + \Phi^{-}_{l,t} \leq \text{min}(\varphi^{cap(+)}_{l}, \varphi^{cap(-)}_{l}) &\quad \forall l \in \mathcal{L_{asym}}, \forall t \in \mathcal{T}
\end{aligned}
```
If discrete unit commitment decisions are modeled, ``phantom losses'' can be observed wherein the auxiliary variables for flows in both directions ($\Phi^{+}_{l,t}$ and $\Phi^{-}_{l,t}$) are both increased to produce increased losses so as to avoid cycling a thermal generator and incurring start-up costs or opportunity costs related to minimum down times. This unrealistic behavior can be eliminated via inclusion of additional constraints and a set of auxiliary binary variables, $ON^{+}_{l,t} \in {0,1} \forall l \in \mathcal{L}$. Then the following additional constraints are created:
```math
\begin{aligned}
\Phi^{+}_{l,t} \leq TransON^{+}_{l,t}, &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T}\\
\Phi^{-}_{l,t} \leq \varphi^{cap}_{l} -TransON^{+}_{l,t}, &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T}
\end{aligned}
```
where $TransON^{+}_{l,t}$ is a continuous variable, representing the product of the binary variable $ON^{+}_{l,t}$ and the expression, $\varphi^{cap}_{l}$. This product cannot be defined explicitly, since it will lead to a bilinear expression involving two variables. Instead, we enforce this definition via the Glover's Linearization as shown below (also referred McCormick Envelopes constraints for bilinear expressions, which is exact when one of the variables is binary).
```math
\begin{aligned}
TransON^{+}_{l,t} \leq (\overline{varphi^{cap}_{l}} + \overline{\bigtriangleup\varphi^{cap}_{l}}) \times TransON^{+}_{l,t}, &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T} \\
TransON^{+}_{l,t} \leq \varphi^{cap}_{l}, &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T} \\
TransON^{+}_{l,t} \geq \varphi^{cap}_{l} - (\overline{\varphi^{cap}_{l}} + \overline{\bigtriangleup\varphi^{cap}_{l}}) \times(1- TransON^{+}_{l,t}), &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T} \\
\end{aligned}
```
These constraints permit only the positive or negative auxiliary flow variables to be non-zero at a given time period, not both. In case of asymmetric lines,
there will be two sets of the equations written above, one set for ech direction, with corresponding auxiliary variables and directional transmission flow limits.
For the third option, losses are calculated as a piecewise-linear approximation of a quadratic function of power flows. In order to do this, we represent the absolute value of the line flow variable by the sum of positive stepwise flow variables $(\mathcal{S}^{+}_{m,l,t}, \mathcal{S}^{-}_{m,l,t})$, associated with each partition of line losses computed using the corresponding linear expressions. This can be understood as a segmentwise linear fitting (or first order approximation) of the quadratic losses function. The first constraint below computes the losses a the accumulated sum of losses for each linear stepwise segment of the approximated quadratic function, including both positive domain and negative domain segments. A second constraint ensures that the stepwise variables do not exceed the maximum size per segment. The slope and maximum size for each segment are calculated as per the method in \cite{Zhang2013}.
```math
\begin{aligned}
& \ell_{l,t} = \frac{\varphi^{ohm}_{l}}{(\varphi^{volt}_{l})^2}\bigg( \sum_{m \in \mathcal{M}}( S^{+}_{m,l}\times \mathcal{S}^{+}_{m,l,t} + S^{-}_{m,l}\times \mathcal{S}^{-}_{m,l,t}) \bigg), &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T} \\
& \text{\quad Where:} \\
& \quad S^{+}_{m,l} = \frac{2+4 \times \sqrt{2}\times (m-1)}{1+\sqrt{2} \times (2 \times M-1)} (\overline{\varphi^{cap}_{l}} + \overline{\bigtriangleup\varphi^{cap}_{l}}) &\quad \forall m \in [1 \colon M], l \in \mathcal{L} \\
& \quad S^{-}_{m,l} = \frac{2+4 \times \sqrt{2}\times (m-1)}{1+\sqrt{2} \times (2 \times M-1)} (\overline{\varphi^{cap}_{l}} + \overline{\bigtriangleup\varphi^{cap}_{l}}) &\quad \forall m \in [1 \colon M], l \in \mathcal{L}\\
& \\
& \mathcal{S}^{+}_{m,l,t}, \mathcal{S}^{-}_{m,l,t} <= \overline{\mathcal{S}_{m,l}} &\quad \forall m \in [1:M], l \in \mathcal{L}, t \in \mathcal{T} \\
& \text{\quad Where:} \\
& \quad \overline{S_{l,z}} = \begin{cases} \frac{(1+\sqrt{2})}{1+\sqrt{2} \times (2 \times M-1)} (\overline{\varphi^{cap}_{l}} + \overline{\bigtriangleup\varphi^{cap}_{l}}) & \text{if~} m = 1 \\
\frac{2 \times \sqrt{2} }{1+\sqrt{2} \times (2 \times M-1)} (\overline{\varphi^{cap}_{l}} + \overline{\bigtriangleup\varphi^{cap}_{l}}) & \text{if~} m > 1 \end{cases}
\end{aligned}
```
Next, a constraint ensures that the sum of auxiliary segment variables ($m \geq 1$) minus the "zero" segment (which allows values to go into the negative domain) from both positive and negative domains must total the actual power flow across the line, and a constraint ensures that the sum of negative and positive flows do not exceed the flow capacity of the line.
```math
\begin{aligned}
&\sum_{m \in [1:M]} (\mathcal{S}^{+}_{m,l,t}) - \mathcal{S}^{+}_{0,l,t} = \Phi_{l,t}, &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T}\\
&\sum_{m \in [1:M]} (\mathcal{S}^{-}_{m,l,t}) - \mathcal{S}^{-}_{0,l,t} = - \Phi_{l,t}
\end{aligned}
```
As with losses option 2, this segment-wise approximation of a quadratic loss function also permits 'phantom losses' to avoid cycling thermal units when discrete unit commitment decisions are modeled. In this case, the additional constraints below are also added to ensure that auxiliary segments variables do not exceed maximum value per segment and that they are filled in order; i.e., one segment cannot be non-zero unless prior segment is at its maximum value. Binary constraints deal with absolute value of power flow on each line. If the flow is positive, $\mathcal{S}^{+}_{0,l,t}$ must be zero; if flow is negative, $\mathcal{S}^{+}_{0,l,t}$ must be positive and takes on value of the full negative flow, forcing all $\mathcal{S}^{+}_{m,l,t}$ other segments ($m \geq 1$) to be zero. Conversely, if the flow is negative, $\mathcal{S}^{-}_{0,l,t}$ must be zero; if flow is positive, $\mathcal{S}^{-}_{0,l,t}$ must be positive and takes on value of the full positive flow, forcing all $\mathcal{S}^{-}_{m,l,t}$ other segments ($m \geq 1$) to be zero. Requiring segments to fill in sequential order and binary variables to ensure variables reflect the actual direction of power flows are both necessary to eliminate ``phantom losses'' from the solution. These constraints and binary decisions are ommited if the model is fully linear.
```math
\begin{aligned}
&\mathcal{S}^{+}_{m,l,t} <= \overline{\mathcal{S}_{m,l}} \times ON^{+}_{m,l,t}, &\quad \forall m \in [1:M], \forall l \in \mathcal{L}, \forall t \in \mathcal{T}\\
&\mathcal{S}^{-}_{m,l,t} <= \overline{\mathcal{S}_{m,l}} \times ON^{-}_{m,l,t}, &\quad \forall m \in[1:M], \forall l \in \mathcal{L}, \forall t \in \mathcal{T}\\
&\mathcal{S}^{+}_{m,l,t} \geq ON^{+}_{m+1,l,t} \times \overline{\mathcal{S}_{m,l}}, &\quad \forall m \in [1:M], \forall l \in \mathcal{L}, \forall t \in \mathcal{T}\\
&\mathcal{S}^{-}_{m,l,t} \geq ON^{-}_{m+1,l,t} \times \overline{\mathcal{S}_{m,l}} , &\quad \forall m \in [1:M], \forall l \in \mathcal{L}, \forall t \in \mathcal{T}\\
&\mathcal{S}^{+}_{0,l,t} \leq \varphi^{max}_{l} \times (1- ON^{+}_{1,l,t}), &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T}\\
&\mathcal{S}^{-}_{0,l,t} \leq \varphi^{max}_{l} \times (1- ON^{-}_{1,l,t}), &\quad \forall l \in \mathcal{L}, \forall t \in \mathcal{T}
\end{aligned}
```
As before, for asymmetric lines, there will be two sets of the above constraints for each direction.
"""
function transmission!(EP::Model, inputs::Dict, setup::Dict)
println("Transmission Module")
T = inputs["T"] # Number of time steps (hours)
Z = inputs["Z"] # Number of zones
L_sym = inputs["L_sym"] # Number of transmission lines with symmetrical bidirectional flow
L_asym = 0 #Default number of asymmetrical lines
# Number of lines in the network
if setup["asymmetrical_trans_flow_limit"] == 1
L_asym = inputs["L_asym"] #Number of transmission lines with different capacities in two directions
end
L = L_sym + L_asym
UCommit = setup["UCommit"]
CapacityReserveMargin = setup["CapacityReserveMargin"]
EnergyShareRequirement = setup["EnergyShareRequirement"]
IncludeLossesInESR = setup["IncludeLossesInESR"]
## sets and indices for transmission losses
TRANS_LOSS_SEGS = inputs["TRANS_LOSS_SEGS"] # Number of segments used in piecewise linear approximations quadratic loss functions - can only take values of TRANS_LOSS_SEGS =1, 2
if setup["asymmetrical_trans_flow_limit"] == 1
LOSS_LINES_ASYM = inputs["LOSS_LINES_ASYM"] # Lines for which loss coefficients apply (are non-zero);
LOSS_LINES_SYM = inputs["LOSS_LINES_SYM"]
else
LOSS_LINES = inputs["LOSS_LINES"] # Lines for which loss coefficients apply (are non-zero);
end
#=
if setup["asymmetrical_trans_flow_limit"] == 0
inputs["pPercent_Loss_Pos"] = inputs["pPercent_Loss_Neg"] = inputs["pPercent_Loss"]
inputs["pTrans_Max_Possible_Pos"] = inputs["pTrans_Max_Possible_Neg"] = inputs["pTrans_Max_Possible"]
inputs["pTrans_Loss_Coef_Pos"] = inputs["pTrans_Loss_Coef_Neg"] = inputs["pTrans_Loss_Coef"]
EP[:eAvail_Trans_Cap_Pos] = EP[:eAvail_Trans_Cap_Neg] = EP[:eAvail_Trans_Cap]
end
=#
### Variables ###
# Power flow on each transmission line "l" at hour "t"
@variable(EP, vFLOW[l = 1:L, t = 1:T])
if (TRANS_LOSS_SEGS == 1) #loss is a constant times absolute value of power flow
if setup["asymmetrical_trans_flow_limit"] == 1
# Positive and negative flow variables
@variable(EP, vTAUX_NEG_ASYM[l in LOSS_LINES_ASYM, t = 1:T]>=0)
@variable(EP, vTAUX_POS_ASYM[l in LOSS_LINES_ASYM, t = 1:T]>=0)
@variable(EP, vTAUX_NEG[l in LOSS_LINES_SYM, t = 1:T]>=0)
@variable(EP, vTAUX_POS[l in LOSS_LINES_SYM, t = 1:T]>=0)
if UCommit == 1
# Single binary variable to ensure positive or negative flows only
@variable(EP, vTAUX_POS_ON_ASYM[l in LOSS_LINES_ASYM, t = 1:T], Bin)
# Continuous variable representing product of binary variable (vTAUX_POS_ON) and avail transmission capacity in positive direction
@variable(EP, vPROD_TRANSCAP_ON_POS_ASYM[l in LOSS_LINES_ASYM, t = 1:T]>=0)
# Continuous variable representing product of binary variable (vTAUX_POS_ON) and avail transmission capacity in negative direction
@variable(EP, vPROD_TRANSCAP_ON_NEG_ASYM[l in LOSS_LINES_ASYM, t = 1:T]>=0)
@variable(EP, vTAUX_POS_ON[l in LOSS_LINES_SYM, t = 1:T], Bin)
# Continuous variable representing product of binary variable (vTAUX_POS_ON) and avail transmission capacity
@variable(EP, vPROD_TRANSCAP_ON[l in LOSS_LINES_SYM, t = 1:T]>=0)
end
else
# Positive and negative flow variables
@variable(EP, vTAUX_NEG[l in LOSS_LINES, t = 1:T]>=0)
@variable(EP, vTAUX_POS[l in LOSS_LINES, t = 1:T]>=0)
if UCommit == 1
# Single binary variable to ensure positive or negative flows only
@variable(EP, vTAUX_POS_ON[l in LOSS_LINES, t = 1:T], Bin)
# Continuous variable representing product of binary variable (vTAUX_POS_ON) and avail transmission capacity
@variable(EP, vPROD_TRANSCAP_ON[l in LOSS_LINES, t = 1:T]>=0)
end
end
else # TRANS_LOSS_SEGS>1
if setup["asymmetrical_trans_flow_limit"] == 1
# Auxiliary variables for linear piecewise interpolation of quadratic losses
@variable(EP, vTAUX_NEG_ASYM[l in LOSS_LINES_ASYM, s = 0:TRANS_LOSS_SEGS, t = 1:T]>=0)
@variable(EP, vTAUX_POS_ASYM[l in LOSS_LINES_ASYM, s = 0:TRANS_LOSS_SEGS, t = 1:T]>=0)
@variable(EP, vTAUX_NEG[l in LOSS_LINES_SYM, s = 0:TRANS_LOSS_SEGS, t = 1:T]>=0)
@variable(EP, vTAUX_POS[l in LOSS_LINES_SYM, s = 0:TRANS_LOSS_SEGS, t = 1:T]>=0)
if UCommit == 1
# Binary auxilary variables for each segment >1 to ensure segments fill in order
@variable(EP,
vTAUX_POS_ON_ASYM[l in LOSS_LINES_ASYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
Bin)
@variable(EP,
vTAUX_NEG_ON_ASYM[l in LOSS_LINES_ASYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
Bin)
@variable(EP,
vTAUX_POS_ON[l in LOSS_LINES_SYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
Bin)
@variable(EP,
vTAUX_NEG_ON[l in LOSS_LINES_SYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
Bin)
end
else
# Auxiliary variables for linear piecewise interpolation of quadratic losses
@variable(EP, vTAUX_NEG[l in LOSS_LINES, s = 0:TRANS_LOSS_SEGS, t = 1:T]>=0)
@variable(EP, vTAUX_POS[l in LOSS_LINES, s = 0:TRANS_LOSS_SEGS, t = 1:T]>=0)
if UCommit == 1
# Binary auxilary variables for each segment >1 to ensure segments fill in order
@variable(EP,
vTAUX_POS_ON[l in LOSS_LINES, s = 1:TRANS_LOSS_SEGS, t = 1:T],
Bin)
@variable(EP,
vTAUX_NEG_ON[l in LOSS_LINES, s = 1:TRANS_LOSS_SEGS, t = 1:T],
Bin)
end
end
end
# Transmission losses on each transmission line "l" at hour "t"
if setup["asymmetrical_trans_flow_limit"] == 1
@variable(EP, vTLOSS_ASYM[l in LOSS_LINES_ASYM, t = 1:T]>=0)
@variable(EP, vTLOSS[l in LOSS_LINES_SYM, t = 1:T]>=0)
else
@variable(EP, vTLOSS[l in LOSS_LINES, t = 1:T]>=0)
end
### Expressions ###
## Transmission power flow and loss related expressions:
# Net power flow outgoing from zone "z" at hour "t" in MW
@expression(EP,
eNet_Export_Flows[z = 1:Z, t = 1:T],
sum(inputs["pNet_Map"][l, z] * vFLOW[l, t] for l in 1:L))
# Losses from power flows into or out of zone "z" in MW
if setup["asymmetrical_trans_flow_limit"] == 1
@expression(EP,
eLosses_By_Zone[z = 1:Z, t = 1:T],
sum(abs(inputs["pNet_Map"][l, z]) * (1 / 2) * vTLOSS[l, t] for l in LOSS_LINES_SYM)
+ sum(abs(inputs["pNet_Map"][l, z]) * (1 / 2) * vTLOSS_ASYM[l, t] for l in LOSS_LINES_ASYM))
else
@expression(EP,
eLosses_By_Zone[z = 1:Z, t = 1:T],
sum(abs(inputs["pNet_Map"][l, z]) * (1 / 2) * vTLOSS[l, t] for l in LOSS_LINES))
end
## Power Balance Expressions ##
@expression(EP, ePowerBalanceNetExportFlows[t = 1:T, z = 1:Z],
-eNet_Export_Flows[z, t])
@expression(EP, ePowerBalanceLossesByZone[t = 1:T, z = 1:Z],
-eLosses_By_Zone[z, t])
add_similar_to_expression!(EP[:ePowerBalance], ePowerBalanceLossesByZone)
add_similar_to_expression!(EP[:ePowerBalance], ePowerBalanceNetExportFlows)
# Capacity Reserves Margin policy
if CapacityReserveMargin > 0
if Z > 1
@expression(EP,
eCapResMarBalanceTrans[res = 1:inputs["NCapacityReserveMargin"], t = 1:T],
sum(inputs["dfTransCapRes_excl"][l, res] *
inputs["dfDerateTransCapRes"][l, res] * EP[:vFLOW][l, t] for l in 1:L))
add_similar_to_expression!(EP[:eCapResMarBalance], -eCapResMarBalanceTrans)
end
end
### Constraints ###
## Power flow and transmission (between zone) loss related constraints
# Maximum power flows, power flow on each transmission line cannot exceed maximum capacity of the line at any hour "t"
if setup["asymmetrical_trans_flow_limit"] ==1
# Maximum power flows, power flow on each transmission line cannot exceed maximum capacity of the line at any hour "t"
println(EP[:eAvail_Trans_Cap_Pos])
@constraints(EP,
begin
cMaxFlow_out[l = 1:L_sym, t = 1:T], vFLOW[l, t] <= EP[:eAvail_Trans_Cap][l]
cMaxFlow_in[l = 1:L_sym, t = 1:T], vFLOW[l, t] >= -EP[:eAvail_Trans_Cap][l]
cMaxFlow_out_asym[l = 1:L_asym, t = 1:T], vFLOW[(l+L_sym), t] <= EP[:eAvail_Trans_Cap_Pos][l] #Change these with Auxiliary
cMaxFlow_in_asym[l = 1:L_asym, t = 1:T], vFLOW[(l+L_sym), t] >= -EP[:eAvail_Trans_Cap_Neg][l] #Change these with Auxiliary
end)
else
@constraints(EP,
begin
cMaxFlow_out[l = 1:L, t = 1:T], vFLOW[l, t] <= EP[:eAvail_Trans_Cap][l]
cMaxFlow_in[l = 1:L, t = 1:T], vFLOW[l, t] >= -EP[:eAvail_Trans_Cap][l]
end)
end
# Transmission loss related constraints - linear losses as a function of absolute value
if TRANS_LOSS_SEGS == 1
if setup["asymmetrical_trans_flow_limit"] ==1
@constraints(EP,
begin
# Losses are alpha times absolute values
cTLoss[l in LOSS_LINES_SYM, t = 1:T],
vTLOSS[l, t] ==
inputs["pPercent_Loss"][l] * ((vTAUX_POS[l, t]) + (vTAUX_NEG[l, t]))
# Power flow is sum of positive and negative components
cTAuxSum[l in LOSS_LINES_SYM, t = 1:T],
vTAUX_POS[l, t] - vTAUX_NEG[l, t] == vFLOW[l, t]
# Sum of auxiliary flow variables in either direction cannot exceed maximum line flow capacity
cTAuxLimit[l in LOSS_LINES_SYM, t = 1:T],
vTAUX_POS[l, t] + vTAUX_NEG[l, t] <= EP[:eAvail_Trans_Cap][l]
end)
@constraints(EP,
begin
# Losses are alpha times absolute values
cTLoss_asym[l in LOSS_LINES_ASYM, t = 1:T],
vTLOSS_ASYM[l, t] ==
inputs["pPercent_Loss_Pos"][l] * (vTAUX_POS_ASYM[l, t]) + inputs["pPercent_Loss_Neg"][l] * (vTAUX_NEG_ASYM[l, t])
# Power flow is sum of positive and negative components
cTAuxSum_asym[l in LOSS_LINES_ASYM, t = 1:T],
vTAUX_POS_ASYM[l, t] - vTAUX_NEG_ASYM[l, t] == vFLOW[(l+L_sym), t]
# Sum of auxiliary flow variables in either direction cannot exceed maximum line flow capacity
cTAuxLimit_pos[l in LOSS_LINES_ASYM, t = 1:T],
vTAUX_POS_ASYM[l, t] + vTAUX_NEG_ASYM[l, t] <= min(EP[:eAvail_Trans_Cap_Pos][l], EP[:eAvail_Trans_Cap_Neg][l])
end)
if UCommit == 1
# Constraints to limit phantom losses that can occur to avoid discrete cycling costs/opportunity costs due to min down
@constraints(EP,
begin
cTAuxPosUB[l in LOSS_LINES_SYM, t = 1:T],
vTAUX_POS[l, t] <= vPROD_TRANSCAP_ON[l, t]
# Either negative or positive flows are activated, not both
cTAuxNegUB[l in LOSS_LINES_SYM, t = 1:T],
vTAUX_NEG[l, t] <= EP[:eAvail_Trans_Cap][l] - vPROD_TRANSCAP_ON[l, t]
# McCormick representation of product of continuous and binary variable
# (in this case, of: vPROD_TRANSCAP_ON[l,t] = EP[:eAvail_Trans_Cap][l] * vTAUX_POS_ON[l,t])
# McCormick constraint 1
[l in LOSS_LINES_SYM, t = 1:T],
vPROD_TRANSCAP_ON[l, t] <=
inputs["pTrans_Max_Possible_Pos"][l] * vTAUX_POS_ON[l, t]
# McCormick constraint 2
[l in LOSS_LINES_SYM, t = 1:T],
vPROD_TRANSCAP_ON[l, t] <= EP[:eAvail_Trans_Cap][l]
# McCormick constraint 3
[l in LOSS_LINES_SYM, t = 1:T],
vPROD_TRANSCAP_ON[l, t] >=
EP[:eAvail_Trans_Cap][l] -
(1 - vTAUX_POS_ON[l, t]) * inputs["pTrans_Max_Possible"][l]
end)
@constraints(EP,
begin
cTAuxPos1UB_asym[l in LOSS_LINES_ASYM, t = 1:T],
vTAUX_POS_ASYM[l, t] <= vPROD_TRANSCAP_ON_POS_ASYM[l, t]
# Either negative or positive flows are activated, not both
cTAuxNeg1UB_asym[l in LOSS_LINES_ASYM, t = 1:T],
vTAUX_NEG_ASYM[l, t] <= EP[:eAvail_Trans_Cap_Neg][l] - vPROD_TRANSCAP_ON_NEG_ASYM[l, t]
cTAuxNeg2UB_asym[l in LOSS_LINES_ASYM, t = 1:T],
vTAUX_NEG_ASYM[l, t] <= vPROD_TRANSCAP_ON_NEG_ASYM[l, t]
# Either negative or positive flows are activated, not both
cTAuxPos2UB_asym[l in LOSS_LINES_ASYM, t = 1:T],
vTAUX_POS_ASYM[l, t] <= EP[:eAvail_Trans_Cap_Pos][l] - vPROD_TRANSCAP_ON_POS_ASYM[l, t]
# McCormick representation of product of continuous and binary variable
# (in this case, of: vPROD_TRANSCAP_ON[l,t] = EP[:eAvail_Trans_Cap][l] * vTAUX_POS_ON[l,t])
# McCormick constraint 1
[l in LOSS_LINES_ASYM, t = 1:T],
vPROD_TRANSCAP_ON_POS_ASYM[l, t] <=
inputs["pTrans_Max_Possible_Pos"][l] * vTAUX_POS_ON_ASYM[l, t]
[l in LOSS_LINES_ASYM, t = 1:T],
vPROD_TRANSCAP_ON_NEG_ASYM[l, t] <=
inputs["pTrans_Max_Possible_Neg"][l] * vTAUX_NEG_ON_ASYM[l, t]
# McCormick constraint 2
[l in LOSS_LINES_ASYM, t = 1:T],
vPROD_TRANSCAP_ON_POS_ASYM[l, t] <= EP[:eAvail_Trans_Cap_Pos][l]
[l in LOSS_LINES_ASYM, t = 1:T],
vPROD_TRANSCAP_ON_NEG_ASYM[l, t] <= EP[:eAvail_Trans_Cap_Neg][l]
# McCormick constraint 3
[l in LOSS_LINES_ASYM, t = 1:T],
vPROD_TRANSCAP_ON_POS_ASYM[l, t] >=
EP[:eAvail_Trans_Cap_Pos][l] -
(1 - vTAUX_POS_ON_POS_ASYM[l, t]) * inputs["pTrans_Max_Possible_Pos"][l]
[l in LOSS_LINES_ASYM, t = 1:T],
vPROD_TRANSCAP_ON_NEG_ASYM[l, t] >=
EP[:eAvail_Trans_Cap_Neg][l] -
(1 - vTAUX_POS_ON_NEG_ASYM[l, t]) * inputs["pTrans_Max_Possible_Neg"][l]
end)
end
else
@constraints(EP,
begin
# Losses are alpha times absolute values
cTLoss[l in LOSS_LINES, t = 1:T],
vTLOSS[l, t] ==
inputs["pPercent_Loss"][l] * ((vTAUX_POS[l, t]) + (vTAUX_NEG[l, t]))
# Power flow is sum of positive and negative components
cTAuxSum[l in LOSS_LINES, t = 1:T],
vTAUX_POS[l, t] - vTAUX_NEG[l, t] == vFLOW[l, t]
# Sum of auxiliary flow variables in either direction cannot exceed maximum line flow capacity
cTAuxLimit[l in LOSS_LINES, t = 1:T],
vTAUX_POS[l, t] + vTAUX_NEG[l, t] <= EP[:eAvail_Trans_Cap][l]
end)
if UCommit == 1
# Constraints to limit phantom losses that can occur to avoid discrete cycling costs/opportunity costs due to min down
@constraints(EP,
begin
cTAuxPosUB[l in LOSS_LINES, t = 1:T],
vTAUX_POS[l, t] <= vPROD_TRANSCAP_ON[l, t]
# Either negative or positive flows are activated, not both
cTAuxNegUB[l in LOSS_LINES, t = 1:T],
vTAUX_NEG[l, t] <= EP[:eAvail_Trans_Cap][l] - vPROD_TRANSCAP_ON[l, t]
# McCormick representation of product of continuous and binary variable
# (in this case, of: vPROD_TRANSCAP_ON[l,t] = EP[:eAvail_Trans_Cap][l] * vTAUX_POS_ON[l,t])
# McCormick constraint 1
[l in LOSS_LINES, t = 1:T],
vPROD_TRANSCAP_ON[l, t] <=
inputs["pTrans_Max_Possible"][l] * vTAUX_POS_ON[l, t]
# McCormick constraint 2
[l in LOSS_LINES, t = 1:T],
vPROD_TRANSCAP_ON[l, t] <= EP[:eAvail_Trans_Cap][l]
# McCormick constraint 3
[l in LOSS_LINES, t = 1:T],
vPROD_TRANSCAP_ON[l, t] >=
EP[:eAvail_Trans_Cap][l] -
(1 - vTAUX_POS_ON[l, t]) * inputs["pTrans_Max_Possible"][l]
end)
end
end # End if(TRANS_LOSS_SEGS == 1) block
end
# When number of segments is greater than 1
if (TRANS_LOSS_SEGS > 1)
if setup["asymmetrical_trans_flow_limit"] ==1
##***FOR SYMMETRICAL LINES***
## between zone transmission loss constraints
# Losses are expressed as a piecewise approximation of a quadratic function of power flows across each line
# Eq 1: Total losses are function of loss coefficient times the sum of auxilary segment variables across all segments of piecewise approximation
# (Includes both positive domain and negative domain segments)
@constraint(EP,
cTLoss[l in LOSS_LINES_SYM, t = 1:T],
vTLOSS[l,
t]==
(inputs["pTrans_Loss_Coef"][l] *
sum((2 * s - 1) * (inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_POS[l, s, t] for s in 1:TRANS_LOSS_SEGS)) +
(inputs["pTrans_Loss_Coef"][l] *
sum((2 * s - 1) * (inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_NEG[l, s, t] for s in 1:TRANS_LOSS_SEGS)))
# Eq 2: Sum of auxilary segment variables (s >= 1) minus the "zero" segment (which allows values to go negative)
# from both positive and negative domains must total the actual power flow across the line
@constraints(EP,
begin
cTAuxSumPos[l in LOSS_LINES_SYM, t = 1:T],
sum(vTAUX_POS[l, s, t] for s in 1:TRANS_LOSS_SEGS) - vTAUX_POS[l, 0, t] ==
vFLOW[l, t]
cTAuxSumNeg[l in LOSS_LINES_SYM, t = 1:T],
sum(vTAUX_NEG[l, s, t] for s in 1:TRANS_LOSS_SEGS) - vTAUX_NEG[l, 0, t] ==
-vFLOW[l, t]
end)
if UCommit == 0 || UCommit == 2
# Eq 3: Each auxilary segment variables (s >= 1) must be less than the maximum power flow in the zone / number of segments
@constraints(EP,
begin
cTAuxMaxPos[l in LOSS_LINES_SYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_POS[l, s, t] <=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS)
cTAuxMaxNeg[l in LOSS_LINES_SYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_NEG[l, s, t] <=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS)
end)
else # Constraints that can be ommitted if problem is convex (i.e. if not using MILP unit commitment constraints)
# Eqs 3-4: Ensure that auxilary segment variables do not exceed maximum value per segment and that they
# "fill" in order: i.e. one segment cannot be non-zero unless prior segment is at it's maximum value
# (These constraints are necessary to prevents phantom losses in MILP problems)
@constraints(EP,
begin
cTAuxOrderPos1[l in LOSS_LINES_SYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_POS[l, s, t] <=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_POS_ON[l, s, t]
cTAuxOrderNeg1[l in LOSS_LINES_SYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_NEG[l, s, t] <=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_NEG_ON[l, s, t]
cTAuxOrderPos2[l in LOSS_LINES_SYM, s = 1:(TRANS_LOSS_SEGS - 1), t = 1:T],
vTAUX_POS[l, s, t] >=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_POS_ON[l, s + 1, t]
cTAuxOrderNeg2[l in LOSS_LINES_SYM, s = 1:(TRANS_LOSS_SEGS - 1), t = 1:T],
vTAUX_NEG[l, s, t] >=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_NEG_ON[l, s + 1, t]
end)
# Eq 5: Binary constraints to deal with absolute value of vFLOW.
@constraints(EP,
begin
# If flow is positive, vTAUX_POS segment 0 must be zero; If flow is negative, vTAUX_POS segment 0 must be positive
# (and takes on value of the full negative flow), forcing all vTAUX_POS other segments (s>=1) to be zero
cTAuxSegmentZeroPos[l in LOSS_LINES_SYM, t = 1:T],
vTAUX_POS[l, 0, t] <=
inputs["pTrans_Max_Possible"][l] * (1 - vTAUX_POS_ON[l, 1, t])
# If flow is negative, vTAUX_NEG segment 0 must be zero; If flow is positive, vTAUX_NEG segment 0 must be positive
# (and takes on value of the full positive flow), forcing all other vTAUX_NEG segments (s>=1) to be zero
cTAuxSegmentZeroNeg[l in LOSS_LINES_SYM, t = 1:T],
vTAUX_NEG[l, 0, t] <=
inputs["pTrans_Max_Possible"][l] * (1 - vTAUX_NEG_ON[l, 1, t])
end)
end
##***FOR ASYMMETRICAL LINES***
## between zone transmission loss constraints
# Losses are expressed as a piecewise approximation of a quadratic function of power flows across each line
# Eq 1: Total losses are function of loss coefficient times the sum of auxilary segment variables across all segments of piecewise approximation
# (Includes both positive domain and negative domain segments)
@constraint(EP,
cTLoss_asym[l in LOSS_LINES_ASYM, t = 1:T],
vTLOSS_ASYM[l,
t]==
(inputs["pTrans_Loss_Coef_Pos"][l] *
sum((2 * s - 1) * (inputs["pTrans_Max_Possible_Pos"][l] / TRANS_LOSS_SEGS) *
vTAUX_POS_ASYM[l, s, t] for s in 1:TRANS_LOSS_SEGS)) +
(inputs["pTrans_Loss_Coef_Neg"][l] *
sum((2 * s - 1) * (inputs["pTrans_Max_Possible_Neg"][l] / TRANS_LOSS_SEGS) *
vTAUX_NEG_ASYM[l, s, t] for s in 1:TRANS_LOSS_SEGS)))
# Eq 2: Sum of auxilary segment variables (s >= 1) minus the "zero" segment (which allows values to go negative)
# from both positive and negative domains must total the actual power flow across the line
@constraints(EP,
begin
cTAuxSumPos_asym[l in LOSS_LINES_ASYM, t = 1:T],
sum(vTAUX_POS_ASYM[l, s, t] for s in 1:TRANS_LOSS_SEGS) - vTAUX_POS_ASYM[l, 0, t] ==
vFLOW[(l+L_sym), t]
cTAuxSumNeg_asym[l in LOSS_LINES_ASYM, t = 1:T],
sum(vTAUX_NEG_ASYM[l, s, t] for s in 1:TRANS_LOSS_SEGS) - vTAUX_NEG_ASYM[l, 0, t] ==
-vFLOW[(l+L_sym), t]
end)
if UCommit == 0 || UCommit == 2
# Eq 3: Each auxilary segment variables (s >= 1) must be less than the maximum power flow in the zone / number of segments
@constraints(EP,
begin
cTAuxMaxPos_asym[l in LOSS_LINES_ASYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_POS_ASYM[l, s, t] <=
(inputs["pTrans_Max_Possible_Pos"][l] / TRANS_LOSS_SEGS)
cTAuxMaxNeg_asym[l in LOSS_LINES_ASYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_NEG_ASYM[l, s, t] <=
(inputs["pTrans_Max_Possible_Neg"][l] / TRANS_LOSS_SEGS)
end)
else # Constraints that can be ommitted if problem is convex (i.e. if not using MILP unit commitment constraints)
# Eqs 3-4: Ensure that auxilary segment variables do not exceed maximum value per segment and that they
# "fill" in order: i.e. one segment cannot be non-zero unless prior segment is at it's maximum value
# (These constraints are necessary to prevents phantom losses in MILP problems)
@constraints(EP,
begin
cTAuxOrderPos1_asym[l in LOSS_LINES_ASYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_POS_ASYM[l, s, t] <=
(inputs["pTrans_Max_Possible_Pos"][l] / TRANS_LOSS_SEGS) *
vTAUX_POS_ON_ASYM[l, s, t]
cTAuxOrderNeg1_asym[l in LOSS_LINES_ASYM, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_NEG_ASYM[l, s, t] <=
(inputs["pTrans_Max_Possible_Neg"][l] / TRANS_LOSS_SEGS) *
vTAUX_NEG_ON_ASYM[l, s, t]
cTAuxOrderPos2_asym[l in LOSS_LINES_ASYM, s = 1:(TRANS_LOSS_SEGS - 1), t = 1:T],
vTAUX_POS_ASYM[l, s, t] >=
(inputs["pTrans_Max_Possible_Pos"][l] / TRANS_LOSS_SEGS) *
vTAUX_POS_ON_ASYM[l, s + 1, t]
cTAuxOrderNeg2_asym[l in LOSS_LINES_ASYM, s = 1:(TRANS_LOSS_SEGS - 1), t = 1:T],
vTAUX_NEG_ASYM[l, s, t] >=
(inputs["pTrans_Max_Possible_Neg"][l] / TRANS_LOSS_SEGS) *
vTAUX_NEG_ON_ASYM[l, s + 1, t]
end)
# Eq 5: Binary constraints to deal with absolute value of vFLOW.
@constraints(EP,
begin
# If flow is positive, vTAUX_POS segment 0 must be zero; If flow is negative, vTAUX_POS segment 0 must be positive
# (and takes on value of the full negative flow), forcing all vTAUX_POS other segments (s>=1) to be zero
cTAuxSegmentZeroPos_asym[l in LOSS_LINES_ASYM, t = 1:T],
vTAUX_POS_ASYM[l, 0, t] <=
inputs["pTrans_Max_Possible_Pos"][l] * (1 - vTAUX_POS_ON_ASYM[l, 1, t])
# If flow is negative, vTAUX_NEG segment 0 must be zero; If flow is positive, vTAUX_NEG segment 0 must be positive
# (and takes on value of the full positive flow), forcing all other vTAUX_NEG segments (s>=1) to be zero
cTAuxSegmentZeroNeg_asym[l in LOSS_LINES_ASYM, t = 1:T],
vTAUX_NEG_ASYM[l, 0, t] <=
inputs["pTrans_Max_Possible_Neg"][l] * (1 - vTAUX_NEG_ON_ASYM[l, 1, t])
end)
end
else
## between zone transmission loss constraints
# Losses are expressed as a piecewise approximation of a quadratic function of power flows across each line
# Eq 1: Total losses are function of loss coefficient times the sum of auxilary segment variables across all segments of piecewise approximation
# (Includes both positive domain and negative domain segments)
@constraint(EP,
cTLoss[l in LOSS_LINES, t = 1:T],
vTLOSS[l,
t]==
(inputs["pTrans_Loss_Coef"][l] *
sum((2 * s - 1) * (inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_POS[l, s, t] for s in 1:TRANS_LOSS_SEGS)) +
(inputs["pTrans_Loss_Coef"][l] *
sum((2 * s - 1) * (inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_NEG[l, s, t] for s in 1:TRANS_LOSS_SEGS)))
# Eq 2: Sum of auxilary segment variables (s >= 1) minus the "zero" segment (which allows values to go negative)
# from both positive and negative domains must total the actual power flow across the line
@constraints(EP,
begin
cTAuxSumPos[l in LOSS_LINES, t = 1:T],
sum(vTAUX_POS[l, s, t] for s in 1:TRANS_LOSS_SEGS) - vTAUX_POS[l, 0, t] ==
vFLOW[l, t]
cTAuxSumNeg[l in LOSS_LINES, t = 1:T],
sum(vTAUX_NEG[l, s, t] for s in 1:TRANS_LOSS_SEGS) - vTAUX_NEG[l, 0, t] ==
-vFLOW[l, t]
end)
if UCommit == 0 || UCommit == 2
# Eq 3: Each auxilary segment variables (s >= 1) must be less than the maximum power flow in the zone / number of segments
@constraints(EP,
begin
cTAuxMaxPos[l in LOSS_LINES, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_POS[l, s, t] <=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS)
cTAuxMaxNeg[l in LOSS_LINES, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_NEG[l, s, t] <=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS)
end)
else # Constraints that can be ommitted if problem is convex (i.e. if not using MILP unit commitment constraints)
# Eqs 3-4: Ensure that auxilary segment variables do not exceed maximum value per segment and that they
# "fill" in order: i.e. one segment cannot be non-zero unless prior segment is at it's maximum value
# (These constraints are necessary to prevents phantom losses in MILP problems)
@constraints(EP,
begin
cTAuxOrderPos1[l in LOSS_LINES, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_POS[l, s, t] <=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_POS_ON[l, s, t]
cTAuxOrderNeg1[l in LOSS_LINES, s = 1:TRANS_LOSS_SEGS, t = 1:T],
vTAUX_NEG[l, s, t] <=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_NEG_ON[l, s, t]
cTAuxOrderPos2[l in LOSS_LINES, s = 1:(TRANS_LOSS_SEGS - 1), t = 1:T],
vTAUX_POS[l, s, t] >=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_POS_ON[l, s + 1, t]
cTAuxOrderNeg2[l in LOSS_LINES, s = 1:(TRANS_LOSS_SEGS - 1), t = 1:T],
vTAUX_NEG[l, s, t] >=
(inputs["pTrans_Max_Possible"][l] / TRANS_LOSS_SEGS) *
vTAUX_NEG_ON[l, s + 1, t]
end)
# Eq 5: Binary constraints to deal with absolute value of vFLOW.
@constraints(EP,
begin
# If flow is positive, vTAUX_POS segment 0 must be zero; If flow is negative, vTAUX_POS segment 0 must be positive
# (and takes on value of the full negative flow), forcing all vTAUX_POS other segments (s>=1) to be zero
cTAuxSegmentZeroPos[l in LOSS_LINES, t = 1:T],
vTAUX_POS[l, 0, t] <=
inputs["pTrans_Max_Possible"][l] * (1 - vTAUX_POS_ON[l, 1, t])
# If flow is negative, vTAUX_NEG segment 0 must be zero; If flow is positive, vTAUX_NEG segment 0 must be positive
# (and takes on value of the full positive flow), forcing all other vTAUX_NEG segments (s>=1) to be zero
cTAuxSegmentZeroNeg[l in LOSS_LINES, t = 1:T],
vTAUX_NEG[l, 0, t] <=
inputs["pTrans_Max_Possible"][l] * (1 - vTAUX_NEG_ON[l, 1, t])
end)
end
end
end # End if(TRANS_LOSS_SEGS > 0) block
# ESR Lossses
if EnergyShareRequirement >= 1 && IncludeLossesInESR == 1
@expression(EP, eESRTran[ESR = 1:inputs["nESR"]],
sum(inputs["dfESR"][z, ESR] *
sum(inputs["omega"][t] * EP[:eLosses_By_Zone][z, t] for t in 1:T)
for z in findall(x -> x > 0, inputs["dfESR"][:, ESR])))
add_similar_to_expression!(EP[:eESR], -eESRTran)
end
end