From 6f8563f7d8c80adff8401c60bd70a204869722c2 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Tue, 21 Jun 2022 16:28:11 +0200 Subject: [PATCH] Fix refactored experiments --- network_attack_propagation.py | 39 +++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/network_attack_propagation.py b/network_attack_propagation.py index 86ea46b..ebae1c3 100644 --- a/network_attack_propagation.py +++ b/network_attack_propagation.py @@ -201,35 +201,42 @@ def summary(average_degrees: list[float], propagation_speeds: list[float]) -> No plt.show() -def experiment(network, avg_degree, node_count): +def experiment(network, avg_degree, node_count, iteration): degrees = [] speeds = [] - sizes = [0, 8, 15] - for i in sizes: - do_graph_animation(f'bus{i}.gif', network, 90, nx.spiral_layout) - speeds.append(network.rounds_survived / node_count) - degrees.append(avg_degree) - print(f"\n{node_count} NODE BUS") - print(f"average degree = {avg_degree}") - print(f"propagation speed = {round(speeds[-1], 2)}") - print(f"bus_{i} rounds survived = {network.rounds_survived + 1}") + do_graph_animation(f'bus{iteration}.gif', network, 90, nx.spiral_layout) + speeds.append(network.rounds_survived / node_count) + degrees.append(avg_degree) + print(f"\n{node_count} NODE BUS") + print(f"average degree = {avg_degree}") + print(f"propagation speed = {round(speeds[-1], 2)}") + print(f"bus_{iteration} rounds survived = {network.rounds_survived + 1}") summary(degrees, speeds) def bus_experiment(): - bus, bus_avg_degree, node_count = bus_network(20 + i) - experiment(bus, bus_avg_degree, node_count) + sizes = [0, 8, 15] + for i in sizes: + bus, bus_avg_degree, node_count = bus_network(20 + i) + experiment(bus, bus_avg_degree, node_count, i) def ring_experiment(): - ring, ring_avg_degree, node_count = ring_network(20 + i) - experiment(ring, ring_avg_degree, node_count) + sizes = [0, 8, 15] + for i in sizes: + ring, ring_avg_degree, node_count = ring_network(20 + i) + experiment(ring, ring_avg_degree, node_count, i) def star_experiment(): - star, star_avg_degree, node_count = star_network(cluster_count=3 + i, starsize=3 + i) - experiment(star, star_avg_degree, node_count) + sizes = [0, 8, 15] + for i in sizes: + star, star_avg_degree, node_count = star_network(cluster_count=3 + i, starsize=3 + i) + experiment(star, star_avg_degree, node_count, i) + +def weighted_star_experiment(): + def main():