import math
import matplotlib.pyplot as plt
SI_target_db = 18.0
N_list = sorted({i**2 + i * j + j**2 for i in range(11) for j in range(1, 11)})
si_urb = [10 * math.log10((math.sqrt(3 * N) ** 4) / 6) for N in N_list]
si_sub = [10 * math.log10((math.sqrt(3 * N) ** 3) / 6) for N in N_list]
si_rur = [10 * math.log10((math.sqrt(3 * N) ** 2) / 6) for N in N_list]
def get_min_N(si_vals):
  return next(N for N, val in zip(N_list, si_vals) if val >= SI_target_db)
print(
    f"Min N for S/I >= 18 dB:\nUrban (n=4): N ="
    f" {get_min_N(si_urb)}\nSuburban (n=3): N ="
    f" {get_min_N(si_sub)}\nRural (n=2): N = {get_min_N(si_rur)}"
)
plt.figure(figsize=(8, 5))
plt.plot(N_list, si_urb, "o-", label="Urban (n=4)")
plt.plot(N_list, si_sub, "s-", label="Suburban (n=3)")
plt.plot(N_list, si_rur, "^-", label="Rural (n=2)")
plt.axhline(18, color="r", linestyle="--", label="18 dB Threshold")
plt.xlabel("Cluster Size (N)")
plt.ylabel("S/I Ratio (dB)")
plt.title("S/I vs Cluster Size (N)")
plt.xlim(0, 50)
plt.ylim(0, 40)
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()
