Last active
September 2, 2020 08:42
-
-
Save akihironitta/82a6a2c7e8e9148e42a8a8ede6554963 to your computer and use it in GitHub Desktop.
This script draws how Additive Decrease Multiplicative Increase (AIMD) algorithm work in order to understand the algorithm visually.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from tqdm import tqdm | |
def main(): | |
capacity = 100 | |
throughput = np.array([50., 2.]) | |
decrease = np.array([2., 2.]) | |
increase = np.array([3., 3.]) | |
for i in tqdm(range(100)): | |
if capacity < throughput.sum(): | |
# multiplicative decrease | |
throughput = throughput / decrease | |
else: | |
# additive increase | |
throughput = throughput + increase | |
plt.figure() | |
plt.xlabel("throughput-1") | |
plt.ylabel("throughput-2") | |
plt.axis([0.0, 1.0, 0.0, 1.0]) | |
plt.plot(throughput[0]/capacity, throughput[1]/capacity, marker=".", color="red") | |
plt.plot([0, 1], [0, 1], color="grey") | |
plt.plot([0, 1], [1, 0], color="red") | |
plt.savefig(f"{i:03d}.png") | |
plt.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment