Skip to content

Instantly share code, notes, and snippets.

@akihironitta
Last active September 2, 2020 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akihironitta/82a6a2c7e8e9148e42a8a8ede6554963 to your computer and use it in GitHub Desktop.
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.
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