import matplotlib.pyplot as plt import numpy as np """ # --- Config --- n = 2 limit = 100 # --- Data Generation --- # w and d go from 0 to 100 (natural numbers) w_vals = np.arange(2, limit + 1) d_vals = np.arange(2, limit + 1) # Create a grid for w and d width, depth = np.meshgrid(w_vals, d_vals) # Calculate x axis X = (width - 1) * (depth - 1) + 1 n_eff = np.where(width - 2 >= 0, np.minimum(n, width - 2), n) safe_n = np.where(n_eff == 0, 1, n_eff) # Calculate n2 and the floor term n_2 = (width - 2) % safe_n floor_term = np.floor((width - safe_n - 1) / safe_n) # Calculate y axis # Breakdown of the formula logic: term1 = (2 * safe_n + 1) * (depth - 1) + 1 term2 = ((2 * safe_n + 2) * (depth - 1) + 1) * floor_term # The last term (2*n2 + 2)*(d - 1) + 1 only if n2 != 0 last_term = (2 * n_2 + 2) * (depth - 1) + 1 last_term = np.where(n_2 != 0, last_term, 0) print(last_term) Y = term1 + term2 + last_term # --- Plotting --- plt.figure(figsize=(12, 7)) # Flatten the arrays to plot y vs x directly plt.scatter(X.flatten(), Y.flatten(), s=5, alpha=0.4, color='#2ca02c') plt.title(f'Number of DCP calls over Number of atomic models \n with n={n}', fontsize=14) plt.xlabel('Number of Atomic Models') plt.ylabel('Number of DirectConnectPort Calls') plt.grid(True, which='both', linestyle='--', alpha=0.5) # Optional: Log scale if y grows extremely fast compared to x # plt.yscale('log') plt.tight_layout() plt.show() """ # --- Config --- # width and depth are now fixed width = 100 depth = 100 n_limit = width # --- Data Generation --- # n varies from 1 to n_limit n_vals = np.arange(1, n_limit + 1) # Total number of atomic models (fixed based on width and depth) X_total = (width - 1) * (depth - 1) + 1 # Calculate Y (DCP calls) for each n based on the formula logic # n_eff is capped at width - 1 if applicable n = np.where(width - 1 >= 0, np.minimum(n_vals, width - 1), n_vals) n_2 = (width - n - 1) % n floor_term = np.floor((width - n - 1) / n) # Breakdown of the formula logic: term1 = (2 * n + 1) * (depth - 1) + 1 term2 = ((2 * n + 2) * (depth - 1) + 1) * floor_term # The last term (2*n2 + 2)*(depth - 1) + 1 only applies if n2 != 0 last_term = np.where(n_2 != 0, (2 * n_2 + 2) * (depth - 1) + 1, 0) Y = term1 + term2 + last_term # --- Plotting --- plt.figure(figsize=(16, 9)) plt.plot(n_vals, Y, marker='o', markersize=3, linestyle='-', color='#2ca02c') # Title includes total atomic models, width, and depth plt.title(f'Number of DirectConnectPort calls in relation to the Number of Models Created per Level per Cycle ' f'\n Total Atomic Models: {X_total} ({width}, {depth})', fontsize=16) plt.xlabel('Number of Models Created per Level per Cycle (n)') plt.ylabel('Number of DirectConnectPort Calls') plt.grid(True, which='both', linestyle='--', alpha=0.5) plt.tight_layout() plt.show() # Save the plot # plt.savefig('dcp_calls_vs_n.png')