avg rank calculation for all topologies
This commit is contained in:
parent
6269168fb8
commit
f2d85a3e7d
@ -146,16 +146,6 @@ def do_graph_animation(output_file_name: str, in_graph: Graph, frame_count: int,
|
|||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
def bus_network(n=30, infected_idx=0) -> Graph:
|
|
||||||
network = Graph()
|
|
||||||
nodes = [Node() for _ in range(n)]
|
|
||||||
nodes[infected_idx].is_infected = True
|
|
||||||
edges = [Edge(nodes[i], nodes[i + 1], 1.0) for i in range(n - 1)]
|
|
||||||
|
|
||||||
network.add_edges(edges)
|
|
||||||
return network
|
|
||||||
|
|
||||||
|
|
||||||
def rank_avg(edges, digits=2):
|
def rank_avg(edges, digits=2):
|
||||||
ranks = {}
|
ranks = {}
|
||||||
for e in edges:
|
for e in edges:
|
||||||
@ -164,6 +154,16 @@ def rank_avg(edges, digits=2):
|
|||||||
return round(mean(ranks.values()), digits)
|
return round(mean(ranks.values()), digits)
|
||||||
|
|
||||||
|
|
||||||
|
def bus_network(n=30, infected_idx=0) -> tuple[Graph, float]:
|
||||||
|
network = Graph()
|
||||||
|
nodes = [Node() for _ in range(n)]
|
||||||
|
nodes[infected_idx].is_infected = True
|
||||||
|
edges = [Edge(nodes[i], nodes[i + 1], 1.0) for i in range(n - 1)]
|
||||||
|
|
||||||
|
network.add_edges(edges)
|
||||||
|
return network, rank_avg(edges)
|
||||||
|
|
||||||
|
|
||||||
def star_network(cluster_count=5, starsize=6) -> tuple[Graph, float]:
|
def star_network(cluster_count=5, starsize=6) -> tuple[Graph, float]:
|
||||||
node_count = cluster_count + cluster_count * starsize + 1
|
node_count = cluster_count + cluster_count * starsize + 1
|
||||||
nodes = [Node() for _ in range(node_count)]
|
nodes = [Node() for _ in range(node_count)]
|
||||||
@ -180,7 +180,7 @@ def star_network(cluster_count=5, starsize=6) -> tuple[Graph, float]:
|
|||||||
return network, rank_avg(edges)
|
return network, rank_avg(edges)
|
||||||
|
|
||||||
|
|
||||||
def ring_network(n=30) -> Graph:
|
def ring_network(n=30) -> tuple[Graph, float]:
|
||||||
network = Graph()
|
network = Graph()
|
||||||
nodes = [Node() for _ in range(n)]
|
nodes = [Node() for _ in range(n)]
|
||||||
nodes[0].is_infected = True
|
nodes[0].is_infected = True
|
||||||
@ -189,14 +189,14 @@ def ring_network(n=30) -> Graph:
|
|||||||
edges.append(end_edge)
|
edges.append(end_edge)
|
||||||
|
|
||||||
network.add_edges(edges)
|
network.add_edges(edges)
|
||||||
return network
|
return network, rank_avg(edges)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
bus = bus_network(36)
|
bus, star_avg_rank = bus_network(36)
|
||||||
do_graph_animation('bus.gif', bus, 90, nx.spiral_layout)
|
do_graph_animation('bus.gif', bus, 90, nx.spiral_layout)
|
||||||
|
|
||||||
ring = ring_network(36)
|
ring, star_avg_rank = ring_network(36)
|
||||||
do_graph_animation('ring.gif', ring, 90, nx.circular_layout)
|
do_graph_animation('ring.gif', ring, 90, nx.circular_layout)
|
||||||
|
|
||||||
star, star_avg_rank = star_network()
|
star, star_avg_rank = star_network()
|
||||||
|
Loading…
Reference in New Issue
Block a user