Skip to content

Commit 9841ada

Browse files
committed
Rewrite power distribution algorithm examples as a table
These are not code examples, but demonstrations for how the distribution algorithm works. So this change makes them more readable, and prevents the unnecessary pylint checks on them, making CI faster. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent f43a32a commit 9841ada

File tree

1 file changed

+23
-77
lines changed

1 file changed

+23
-77
lines changed

src/frequenz/sdk/actor/power_distributing/_distribution_algorithm/_distribution_algorithm.py

Lines changed: 23 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -147,39 +147,16 @@ def __init__(self, distributor_exponent: float = 1) -> None:
147147
* `Bat1.available_soc = 10`, `Bat2.available_soc = 30`
148148
* `Bat1.available_soc / Bat2.available_soc = 3`
149149
150-
We need to distribute 8000W.
150+
A request power of 8000W will be distributed as follows, for different
151+
values of `distribution_exponent`:
151152
152-
If `distribution_exponent` is:
153+
| distribution_exponent | Bat1 | Bat2 |
154+
|-----------------------|------|------|
155+
| 0 | 4000 | 4000 |
156+
| 1 | 2000 | 6000 |
157+
| 2 | 800 | 7200 |
158+
| 3 | 285 | 7715 |
153159
154-
* `0`: distribution for each battery will be the equal.
155-
```python
156-
BAT1_DISTRIBUTION = 4000
157-
BAT2_DISTRIBUTION = 4000
158-
```
159-
160-
* `1`: then `Bat2` will have 3x more power assigned then `Bat1`.
161-
```python
162-
# 10 * x + 30 * x = 8000
163-
X = 200
164-
BAT1_DISTRIBUTION = 2000
165-
BAT2_DISTRIBUTION = 6000
166-
```
167-
168-
* `2`: then `Bat2` will have 9x more power assigned then `Bat1`.
169-
```python
170-
# 10^2 * x + 30^2 * x = 8000
171-
X = 80
172-
BAT1_DISTRIBUTION = 800
173-
BAT2_DISTRIBUTION = 7200
174-
```
175-
176-
* `3`: then `Bat2` will have 27x more power assigned then `Bat1`.
177-
```python
178-
# 10^3 * x + 30^3 * x = 8000
179-
X = 0.285714286
180-
BAT1_DISTRIBUTION = 285
181-
BAT2_DISTRIBUTION = 7715
182-
```
183160
184161
# Example 2
185162
@@ -189,39 +166,15 @@ def __init__(self, distributor_exponent: float = 1) -> None:
189166
* `Bat1.available_soc = 30`, `Bat2.available_soc = 60`
190167
* `Bat1.available_soc / Bat2.available_soc = 2`
191168
192-
We need to distribute 900W.
193-
194-
If `distribution_exponent` is:
169+
A request power of 900W will be distributed as follows, for different
170+
values of `distribution_exponent`.
195171
196-
* `0`: distribution for each battery will be the same.
197-
```python
198-
BAT1_DISTRIBUTION = 4500
199-
BAT2_DISTRIBUTION = 450
200-
```
201-
202-
* `1`: then `Bat2` will have 2x more power assigned then `Bat1`.
203-
```python
204-
# 30 * x + 60 * x = 900
205-
X = 100
206-
BAT1_DISTRIBUTION = 300
207-
BAT2_DISTRIBUTION = 600
208-
```
209-
210-
* `2`: then `Bat2` will have 4x more power assigned then `Bat1`.
211-
```python
212-
# 30^2 * x + 60^2 * x = 900
213-
X = 0.2
214-
BAT1_DISTRIBUTION = 180
215-
BAT2_DISTRIBUTION = 720
216-
```
217-
218-
* `3`: then `Bat2` will have 8x more power assigned then `Bat1`.
219-
```python
220-
# 30^3 * x + 60^3 * x = 900
221-
X = 0.003703704
222-
BAT1_DISTRIBUTION = 100
223-
BAT2_DISTRIBUTION = 800
224-
```
172+
| distribution_exponent | Bat1 | Bat2 |
173+
|-----------------------|------|------|
174+
| 0 | 450 | 450 |
175+
| 1 | 300 | 600 |
176+
| 2 | 180 | 720 |
177+
| 3 | 100 | 800 |
225178
226179
# Example 3
227180
@@ -230,26 +183,19 @@ def __init__(self, distributor_exponent: float = 1) -> None:
230183
* `Bat1.soc = 44` and `Bat2.soc = 64`.
231184
* `Bat1.available_soc = 36 (80 - 44)`, `Bat2.available_soc = 16 (80 - 64)`
232185
233-
We need to distribute 900W.
186+
A request power of 900W will be distributed as follows, for these values of
187+
`distribution_exponent`:
234188
235189
If `distribution_exponent` is:
236190
237-
* `0`: distribution for each battery will be the equal.
238-
```python
239-
BAT1_DISTRIBUTION = 450
240-
BAT2_DISTRIBUTION = 450
241-
```
242-
243-
* `0.5`: then `Bat2` will have 6/4x more power assigned then `Bat1`.
244-
```python
245-
# sqrt(36) * x + sqrt(16) * x = 900
246-
X = 100
247-
BAT1_DISTRIBUTION = 600
248-
BAT2_DISTRIBUTION = 400
249-
```
191+
| distribution_exponent | Bat1 | Bat2 |
192+
|-----------------------|------|------|
193+
| 0 | 450 | 450 |
194+
| 0.5 | 600 | 400 |
250195
251196
Raises:
252197
ValueError: If distributor_exponent < 0
198+
253199
"""
254200
super().__init__()
255201

0 commit comments

Comments
 (0)