@@ -93,6 +93,33 @@ def inverter_msg(
93
93
)
94
94
95
95
96
+ def create_components (
97
+ num : int ,
98
+ capacity : List [Metric ],
99
+ soc : List [Metric ],
100
+ power : List [PowerBounds ],
101
+ ) -> List [InvBatPair ]:
102
+ """Create components with given arguments.
103
+
104
+ Args:
105
+ num: Number of components
106
+ capacity: Capacity for each battery
107
+ soc: SoC for each battery
108
+ soc_bounds: SoC bounds for each battery
109
+ supply_bounds: Supply bounds for each battery and inverter
110
+ consumption_bounds: Consumption bounds for each battery and inverter
111
+
112
+ Returns:
113
+ List of the components
114
+ """
115
+ components : List [InvBatPair ] = []
116
+ for i in range (0 , num ):
117
+ battery = battery_msg (2 * i , capacity [i ], soc [i ], power [2 * i ])
118
+ inverter = inverter_msg (2 * i + 1 , power [2 * i + 1 ])
119
+ components .append (InvBatPair (battery , inverter ))
120
+ return components
121
+
122
+
96
123
class TestDistributionAlgorithm : # pylint: disable=too-many-public-methods
97
124
"""Test whether the algorithm works as expected."""
98
125
@@ -266,34 +293,6 @@ def test_distribute_power_three_batteries_3(self) -> None:
266
293
assert result .distribution == approx ({1 : 0 , 3 : 300 , 5 : 0 })
267
294
assert result .remaining_power == approx (700.0 )
268
295
269
- def create_components ( # pylint: disable=too-many-arguments
270
- self ,
271
- num : int ,
272
- capacity : List [Metric ],
273
- soc : List [Metric ],
274
- power : List [PowerBounds ],
275
- ) -> List [InvBatPair ]:
276
- """Create components with given arguments.
277
-
278
- Args:
279
- num: Number of components
280
- capacity: Capacity for each battery
281
- soc: SoC for each battery
282
- soc_bounds: SoC bounds for each battery
283
- supply_bounds: Supply bounds for each battery and inverter
284
- consumption_bounds: Consumption bounds for each battery and inverter
285
-
286
- Returns:
287
- List of the components
288
- """
289
-
290
- components : List [InvBatPair ] = []
291
- for i in range (0 , num ):
292
- battery = battery_msg (2 * i , capacity [i ], soc [i ], power [2 * i ])
293
- inverter = inverter_msg (2 * i + 1 , power [2 * i + 1 ])
294
- components .append (InvBatPair (battery , inverter ))
295
- return components
296
-
297
296
# Test distribute supply power
298
297
def test_supply_three_batteries_1 (self ) -> None :
299
298
"""Test distribute supply power for batteries with different SoC."""
@@ -314,7 +313,7 @@ def test_supply_three_batteries_1(self) -> None:
314
313
PowerBounds (- 900 , 0 , 0 , 0 ),
315
314
PowerBounds (- 900 , 0 , 0 , 0 ),
316
315
]
317
- components = self . create_components (3 , capacity , soc , bounds )
316
+ components = create_components (3 , capacity , soc , bounds )
318
317
319
318
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
320
319
result = algorithm .distribute_power (- 1200 , components )
@@ -339,7 +338,7 @@ def test_supply_three_batteries_2(self) -> None:
339
338
PowerBounds (- 900 , 0 , 0 , 0 ),
340
339
PowerBounds (- 900 , 0 , 0 , 0 ),
341
340
]
342
- components = self . create_components (3 , capacity , soc , bounds )
341
+ components = create_components (3 , capacity , soc , bounds )
343
342
344
343
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
345
344
result = algorithm .distribute_power (- 1400 , components )
@@ -364,7 +363,7 @@ def test_supply_three_batteries_3(self) -> None:
364
363
PowerBounds (- 800 , 0 , 0 , 0 ),
365
364
PowerBounds (- 900 , 0 , 0 , 0 ),
366
365
]
367
- components = self . create_components (3 , capacity , soc , supply_bounds )
366
+ components = create_components (3 , capacity , soc , supply_bounds )
368
367
369
368
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
370
369
result = algorithm .distribute_power (- 1400 , components )
@@ -389,7 +388,7 @@ def test_supply_three_batteries_4(self) -> None:
389
388
PowerBounds (- 800 , 0 , 0 , 0 ),
390
389
PowerBounds (- 900 , 0 , 0 , 0 ),
391
390
]
392
- components = self . create_components (3 , capacity , soc , bounds )
391
+ components = create_components (3 , capacity , soc , bounds )
393
392
394
393
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
395
394
result = algorithm .distribute_power (- 1700 , components )
@@ -414,7 +413,7 @@ def test_supply_three_batteries_5(self) -> None:
414
413
PowerBounds (- 800 , 0 , 0 , 0 ),
415
414
PowerBounds (- 900 , 0 , 0 , 0 ),
416
415
]
417
- components = self . create_components (3 , capacity , soc , supply_bounds )
416
+ components = create_components (3 , capacity , soc , supply_bounds )
418
417
419
418
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
420
419
result = algorithm .distribute_power (- 1700 , components )
@@ -437,7 +436,7 @@ def test_supply_two_batteries_1(self) -> None:
437
436
PowerBounds (- 600 , 0 , 0 , 0 ),
438
437
PowerBounds (- 1000 , 0 , 0 , 0 ),
439
438
]
440
- components = self . create_components (2 , capacity , soc , supply_bounds )
439
+ components = create_components (2 , capacity , soc , supply_bounds )
441
440
442
441
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
443
442
result = algorithm .distribute_power (- 600 , components )
@@ -459,7 +458,7 @@ def test_supply_two_batteries_2(self) -> None:
459
458
PowerBounds (- 600 , 0 , 0 , 0 ),
460
459
PowerBounds (- 1000 , 0 , 0 , 0 ),
461
460
]
462
- components = self . create_components (2 , capacity , soc , supply_bounds )
461
+ components = create_components (2 , capacity , soc , supply_bounds )
463
462
464
463
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
465
464
result = algorithm .distribute_power (- 600 , components )
@@ -485,7 +484,7 @@ def test_consumption_three_batteries_1(self) -> None:
485
484
PowerBounds (0 , 0 , 0 , 900 ),
486
485
PowerBounds (0 , 0 , 0 , 900 ),
487
486
]
488
- components = self . create_components (3 , capacity , soc , bounds )
487
+ components = create_components (3 , capacity , soc , bounds )
489
488
490
489
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
491
490
result = algorithm .distribute_power (1200 , components )
@@ -510,7 +509,7 @@ def test_consumption_three_batteries_2(self) -> None:
510
509
PowerBounds (0 , 0 , 0 , 900 ),
511
510
PowerBounds (0 , 0 , 0 , 900 ),
512
511
]
513
- components = self . create_components (3 , capacity , soc , bounds )
512
+ components = create_components (3 , capacity , soc , bounds )
514
513
515
514
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
516
515
result = algorithm .distribute_power (1400 , components )
@@ -535,7 +534,7 @@ def test_consumption_three_batteries_3(self) -> None:
535
534
PowerBounds (0 , 0 , 0 , 800 ),
536
535
PowerBounds (0 , 0 , 0 , 900 ),
537
536
]
538
- components = self . create_components (3 , capacity , soc , bounds )
537
+ components = create_components (3 , capacity , soc , bounds )
539
538
540
539
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
541
540
result = algorithm .distribute_power (1400 , components )
@@ -560,7 +559,7 @@ def test_consumption_three_batteries_4(self) -> None:
560
559
PowerBounds (0 , 0 , 0 , 800 ),
561
560
PowerBounds (0 , 0 , 0 , 900 ),
562
561
]
563
- components = self . create_components (3 , capacity , soc , bounds )
562
+ components = create_components (3 , capacity , soc , bounds )
564
563
565
564
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
566
565
result = algorithm .distribute_power (1700 , components )
@@ -585,7 +584,7 @@ def test_consumption_three_batteries_5(self) -> None:
585
584
PowerBounds (0 , 0 , 0 , 800 ),
586
585
PowerBounds (0 , 0 , 0 , 900 ),
587
586
]
588
- components = self . create_components (3 , capacity , soc , bounds )
587
+ components = create_components (3 , capacity , soc , bounds )
589
588
590
589
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
591
590
result = algorithm .distribute_power (1700 , components )
@@ -610,7 +609,7 @@ def test_consumption_three_batteries_6(self) -> None:
610
609
PowerBounds (0 , 0 , 0 , 800 ),
611
610
PowerBounds (0 , 0 , 0 , 900 ),
612
611
]
613
- components = self . create_components (3 , capacity , soc , bounds )
612
+ components = create_components (3 , capacity , soc , bounds )
614
613
615
614
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
616
615
result = algorithm .distribute_power (1700 , components )
@@ -635,7 +634,7 @@ def test_consumption_three_batteries_7(self) -> None:
635
634
PowerBounds (0 , 0 , 0 , 800 ),
636
635
PowerBounds (0 , 0 , 0 , 900 ),
637
636
]
638
- components = self . create_components (3 , capacity , soc , bounds )
637
+ components = create_components (3 , capacity , soc , bounds )
639
638
640
639
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
641
640
result = algorithm .distribute_power (500 , components )
@@ -657,7 +656,7 @@ def test_consumption_two_batteries_1(self) -> None:
657
656
PowerBounds (0 , 0 , 0 , 600 ),
658
657
PowerBounds (0 , 0 , 0 , 1000 ),
659
658
]
660
- components = self . create_components (2 , capacity , soc , bounds )
659
+ components = create_components (2 , capacity , soc , bounds )
661
660
662
661
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
663
662
result = algorithm .distribute_power (600 , components )
@@ -679,7 +678,7 @@ def test_consumption_two_batteries_distribution_exponent(self) -> None:
679
678
PowerBounds (0 , 0 , 0 , 9000 ),
680
679
PowerBounds (0 , 0 , 0 , 9000 ),
681
680
]
682
- components = self . create_components (2 , capacity , soc , bounds )
681
+ components = create_components (2 , capacity , soc , bounds )
683
682
684
683
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
685
684
result = algorithm .distribute_power (8000 , components )
@@ -713,7 +712,7 @@ def test_consumption_two_batteries_distribution_exponent_1(self) -> None:
713
712
PowerBounds (0 , 0 , 0 , 9000 ),
714
713
PowerBounds (0 , 0 , 0 , 9000 ),
715
714
]
716
- components = self . create_components (2 , capacity , soc , bounds )
715
+ components = create_components (2 , capacity , soc , bounds )
717
716
718
717
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
719
718
result = algorithm .distribute_power (900 , components )
@@ -765,7 +764,7 @@ def test_supply_two_batteries_distribution_exponent(self) -> None:
765
764
PowerBounds (- 9000 , 0 , 0 , 0 ),
766
765
PowerBounds (- 9000 , 0 , 0 , 0 ),
767
766
]
768
- components = self . create_components (2 , capacity , soc , bounds )
767
+ components = create_components (2 , capacity , soc , bounds )
769
768
770
769
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
771
770
result = algorithm .distribute_power (- 8000 , components )
@@ -799,7 +798,7 @@ def test_supply_two_batteries_distribution_exponent_1(self) -> None:
799
798
PowerBounds (- 9000 , 0 , 0 , 0 ),
800
799
PowerBounds (- 9000 , 0 , 0 , 0 ),
801
800
]
802
- components = self . create_components (2 , capacity , soc , supply_bounds )
801
+ components = create_components (2 , capacity , soc , supply_bounds )
803
802
804
803
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
805
804
result = algorithm .distribute_power (- 8000 , components )
@@ -836,7 +835,7 @@ def test_supply_three_batteries_distribution_exponent_2(self) -> None:
836
835
PowerBounds (- 9000 , 0 , 0 , 0 ),
837
836
PowerBounds (- 9000 , 0 , 0 , 0 ),
838
837
]
839
- components = self . create_components (3 , capacity , soc , bounds )
838
+ components = create_components (3 , capacity , soc , bounds )
840
839
841
840
algorithm = DistributionAlgorithm (distributor_exponent = 1 )
842
841
result = algorithm .distribute_power (- 8000 , components )
@@ -879,7 +878,7 @@ def test_supply_three_batteries_distribution_exponent_3(self) -> None:
879
878
PowerBounds (- 9000 , 0 , 0 , 0 ),
880
879
PowerBounds (- 9000 , 0 , 0 , 0 ),
881
880
]
882
- components = self . create_components (3 , capacity , soc , supply_bounds )
881
+ components = create_components (3 , capacity , soc , supply_bounds )
883
882
884
883
algorithm = DistributionAlgorithm (distributor_exponent = 0.5 )
885
884
result = algorithm .distribute_power (- 1300 , components )
@@ -907,7 +906,7 @@ def test_supply_two_batteries_distribution_exponent_less_then_1(self) -> None:
907
906
PowerBounds (0 , 0 , 0 , 9000 ),
908
907
PowerBounds (0 , 0 , 0 , 9000 ),
909
908
]
910
- components = self . create_components (2 , capacity , soc , bounds )
909
+ components = create_components (2 , capacity , soc , bounds )
911
910
912
911
algorithm = DistributionAlgorithm (distributor_exponent = 0.5 )
913
912
result = algorithm .distribute_power (1000 , components )
0 commit comments