import math
import matplotlib.pyplot as plt
total_system_area = 3500
cell_radius = 3
total_radio_channels = 100
cluster_sizes = [7, 4, 3]
area_of_one_cell = (3 * math.sqrt(3) / 2) * (cell_radius ** 2)
print(f"Area of a single cell: {area_of_one_cell:.2f} km^2\n")
num_cells_in_system = total_system_area / area_of_one_cell
print(
    f"Approximate total number of cells in the system area: "
    f"{num_cells_in_system:.2f}\n"
)
results = {}
for N in cluster_sizes:
    print(f"--- For Cluster Size N = {N} ---")
    area_of_cluster = N * area_of_one_cell
    print(f"Area of one cluster (N={N}): {area_of_cluster:.2f} km^2")
    num_cluster_repetitions = total_system_area / area_of_cluster
    print(
        f"Number of times the cluster has to be repeated: "
        f"{num_cluster_repetitions:.2f}"
    )
    channels_per_cell = total_radio_channels / N
    system_capacity = num_cells_in_system * channels_per_cell
    print(f"System Capacity: {system_capacity:.2f} channels\n")
    results[N] = {
        "area_of_cluster": area_of_cluster,
        "num_cluster_repetitions": num_cluster_repetitions,
        "system_capacity": system_capacity
    }
print("\n--- Comment on relation between Capacity and Cluster Size ---")
print(
    "Based on the calculations, System Capacity = "
    "(Total System Area / Area of one cell) * "
    "(Total Radio Channels / N)."
)
print(
    "Since Total System Area, Area of one cell, and "
    "Total Radio Channels are constants, System Capacity "
    "is inversely proportional to the cluster size N."
)
print(
    "This implies that as the cluster size (N) decreases, "
    "the system capacity increases. A smaller cluster size "
    "allows for more frequent frequency reuse across the system."
)
print(
    "However, it is crucial to acknowledge the trade-off: "
    "a smaller N typically leads to increased co-channel "
    "interference, which is an important factor in real-world "
    "cellular design."
)
cluster_sizes_plot = sorted(list(results.keys()))
system_capacities_plot = [
    results[N]["system_capacity"] for N in cluster_sizes_plot
]
plt.figure(figsize=(10, 6))
plt.plot(
    cluster_sizes_plot,
    system_capacities_plot,
    marker='o',
    linestyle='-',
    color='b'
)
plt.title("System Capacity vs. Cluster Size")
plt.xlabel("Cluster Size (N)")
plt.ylabel("System Capacity (channels)")
plt.xticks(cluster_sizes_plot)
plt.grid(True)
plt.tight_layout()
plt.show()
