plotNumberOfDCP.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. """
  4. # --- Config ---
  5. n = 2
  6. limit = 100
  7. # --- Data Generation ---
  8. # w and d go from 0 to 100 (natural numbers)
  9. w_vals = np.arange(2, limit + 1)
  10. d_vals = np.arange(2, limit + 1)
  11. # Create a grid for w and d
  12. width, depth = np.meshgrid(w_vals, d_vals)
  13. # Calculate x axis
  14. X = (width - 1) * (depth - 1) + 1
  15. n_eff = np.where(width - 2 >= 0, np.minimum(n, width - 2), n)
  16. safe_n = np.where(n_eff == 0, 1, n_eff)
  17. # Calculate n2 and the floor term
  18. n_2 = (width - 2) % safe_n
  19. floor_term = np.floor((width - safe_n - 1) / safe_n)
  20. # Calculate y axis
  21. # Breakdown of the formula logic:
  22. term1 = (2 * safe_n + 1) * (depth - 1) + 1
  23. term2 = ((2 * safe_n + 2) * (depth - 1) + 1) * floor_term
  24. # The last term (2*n2 + 2)*(d - 1) + 1 only if n2 != 0
  25. last_term = (2 * n_2 + 2) * (depth - 1) + 1
  26. last_term = np.where(n_2 != 0, last_term, 0)
  27. print(last_term)
  28. Y = term1 + term2 + last_term
  29. # --- Plotting ---
  30. plt.figure(figsize=(12, 7))
  31. # Flatten the arrays to plot y vs x directly
  32. plt.scatter(X.flatten(), Y.flatten(), s=5, alpha=0.4, color='#2ca02c')
  33. plt.title(f'Number of DCP calls over Number of atomic models \n with n={n}', fontsize=14)
  34. plt.xlabel('Number of Atomic Models')
  35. plt.ylabel('Number of DirectConnectPort Calls')
  36. plt.grid(True, which='both', linestyle='--', alpha=0.5)
  37. # Optional: Log scale if y grows extremely fast compared to x
  38. # plt.yscale('log')
  39. plt.tight_layout()
  40. plt.show()
  41. """
  42. # --- Config ---
  43. # width and depth are now fixed
  44. width = 100
  45. depth = 100
  46. n_limit = width
  47. # --- Data Generation ---
  48. # n varies from 1 to n_limit
  49. n_vals = np.arange(1, n_limit + 1)
  50. # Total number of atomic models (fixed based on width and depth)
  51. X_total = (width - 1) * (depth - 1) + 1
  52. # Calculate Y (DCP calls) for each n based on the formula logic
  53. # n_eff is capped at width - 1 if applicable
  54. n = np.where(width - 1 >= 0, np.minimum(n_vals, width - 1), n_vals)
  55. n_2 = (width - n - 1) % n
  56. floor_term = np.floor((width - n - 1) / n)
  57. # Breakdown of the formula logic:
  58. term1 = (2 * n + 1) * (depth - 1) + 1
  59. term2 = ((2 * n + 2) * (depth - 1) + 1) * floor_term
  60. # The last term (2*n2 + 2)*(depth - 1) + 1 only applies if n2 != 0
  61. last_term = np.where(n_2 != 0, (2 * n_2 + 2) * (depth - 1) + 1, 0)
  62. Y = term1 + term2 + last_term
  63. # --- Plotting ---
  64. plt.figure(figsize=(16, 9))
  65. plt.plot(n_vals, Y, marker='o', markersize=3, linestyle='-', color='#2ca02c')
  66. # Title includes total atomic models, width, and depth
  67. plt.title(f'Number of DirectConnectPort calls in relation to the Number of Models Created per Level per Cycle '
  68. f'\n Total Atomic Models: {X_total} ({width}, {depth})', fontsize=16)
  69. plt.xlabel('Number of Models Created per Level per Cycle (n)')
  70. plt.ylabel('Number of DirectConnectPort Calls')
  71. plt.grid(True, which='both', linestyle='--', alpha=0.5)
  72. plt.tight_layout()
  73. plt.show()
  74. # Save the plot
  75. # plt.savefig('dcp_calls_vs_n.png')