@@ -28,63 +28,85 @@ class DistributionResult:
2828
2929
3030class DistributionAlgorithm :
31- """Distribute power between many components.
31+ r """Distribute power between many components.
3232
3333 The purpose of this tool is to keep equal SoC level in the batteries.
3434 It takes total power that should be to be set for some subset of battery-inverter
3535 pairs. The total power is distributed between given battery-inverter pairs.
3636 Distribution is calculated based on data below:
37- * Battery current SoC.
38- * Battery upper and lower SoC bound.
39- * Battery capacity.
40- * Battery lower and upper power bound.
41- * Inverter lower and upper active power bound.
4237
43- Distribution algorithm:
38+ * Battery current SoC.
39+ * Battery upper and lower SoC bound.
40+ * Battery capacity.
41+ * Battery lower and upper power bound.
42+ * Inverter lower and upper active power bound.
43+
44+ # Distribution algorithm
45+
4446 Lets assume that:
45- ```
46- * N - number of batteries
47- * power_w = power to distribute
48- * capacity[i] - capacity of i'th battery
49- * available_soc[i] - how much SoC remained to reach:
47+
48+ * `N` - number of batteries
49+ * ` power_w` - power to distribute
50+ * ` capacity[i]` - capacity of i'th battery
51+ * ` available_soc[i]` - how much SoC remained to reach:
5052 * SoC upper bound - if need to distribute power that charges inverters.
5153 * SoC lower bound - if need to distribute power that discharges inverters.
52- * 0 if SoC is outside SoC bounds.
54+ * `0` - if SoC is outside SoC bounds.
5355
54- * total_capacity = sum(c for c in capacity.values())
55- * capacity_ratio[i] = capacity[i]/total_capacity
56+ * ` total_capacity` - ` sum(c for c in capacity.values())`
57+ * ` capacity_ratio[i]` - ` capacity[i]/total_capacity`
5658
59+
60+ We would like our distribution to meet the equation:
61+
62+ ``` python
63+ distribution[i] = power_w * capacity_ratio[i] * x[i]
5764 ```
58- We would like our distribution to meet equation:
59- ```
60- distribution[i] = power_w * capacity_ratio[i] * x[i]
65+
6166 where:
62- sum(capacity_ratio[i] * x[i] for i in range(N)) == 1
63- ```
64- Let `y` be our unknown, the proportion to discharge each battery would be:
67+
68+ ``` python
69+ sum(capacity_ratio[i] * x[i] for i in range(N)) == 1
6570 ```
66- (1) x[i] = available_soc[i]*y
67- ````
68- We can compute `y` from equation above:
71+
72+ Let `y` be our unknown, the proportion to discharge each battery would be
73+ (1):
74+
75+ ``` python
76+ x[i] = available_soc[i]*y
6977 ```
70- (2) sum(capacity_ratio[i] * x[i] for i in range(N)) == 1
71- => sum(capacity_ratio[i] * available_soc[i] * y for i in range(N)) == 1
72- => y = 1 / sum(capacity_ratio[i] * available_soc[i])
78+
79+ We can compute `y` from equation above (2):
80+
81+ ``` python
82+ sum(capacity_ratio[i] * x[i] for i in range(N)) == 1
83+ # =>
84+ sum(capacity_ratio[i] * available_soc[i] * y for i in range(N)) == 1
85+ # =>
86+ y = 1 / sum(capacity_ratio[i] * available_soc[i])
7387 ```
88+
7489 Now we know everything and we can compute distribution:
90+
91+ ``` python
92+ distribution[i] = power_w * capacity_ratio[i] * x[i] # from (1)
93+ distribution[i] = \
94+ power_w * capacity_ratio[i] * available_soc[i] * y # from (2)
95+ distribution[i] = power_w * capacity_ratio[i] * available_soc[i] * \
96+ 1/sum(capacity_ratio[i] * available_soc[i])
7597 ```
76- distribution[i] = power_w * capacity_ratio[i] * x[i] (from (1))
77- distribution[i] = \
78- power_w * capacity_ratio[i] * available_soc[i] * y (from (2))
79- distribution[i] = power_w * capacity_ratio[i] * available_soc[i] * \
80- 1/sum( capacity_ratio[i] * available_soc[i])
81-
82- Let
83- battery_availability_ratio[i] = capacity_ratio[i] * available_soc[i]
84- total_battery_availability_ratio = sum(battery_availability_ratio)
85- Then:
86- distribution[i] = power_w * battery_availability_ratio[i] \
87- / total_battery_availability_ratio
98+
99+ Let:
100+
101+ ``` python
102+ battery_availability_ratio[i] = capacity_ratio[i] * available_soc[i]
103+ total_battery_availability_ratio = sum(battery_availability_ratio)
104+ ```
105+
106+ Then:
107+ ``` python
108+ distribution[i] = power_w * battery_availability_ratio[i] \
109+ / total_battery_availability_ratio
88110 ```
89111 """
90112
@@ -190,7 +212,7 @@ def _total_capacity(self, components: List[InvBatPair]) -> float:
190212 def _compute_battery_availability_ratio (
191213 self , components : List [InvBatPair ], available_soc : Dict [int , float ]
192214 ) -> Tuple [List [Tuple [InvBatPair , float ]], float ]:
193- """Compute battery ratio and the total sum of all of them.
215+ r """Compute battery ratio and the total sum of all of them.
194216
195217 battery_availability_ratio = capacity_ratio[i] * available_soc[i]
196218 Where:
0 commit comments