typer + enums + switch

This commit is contained in:
0xFugue 2022-12-30 03:23:14 +05:30
parent 1c5c17c957
commit efd920688c

View File

@ -107,7 +107,7 @@ def generate_scalefree_graph(n):
# n must be larger than k=D=3 # n must be larger than k=D=3
def generate_newman_watts_strogatz_graph(n): def generate_newmanwattsstrogatz_graph(n):
return nx.newman_watts_strogatz_graph(n, 3, 0.5) return nx.newman_watts_strogatz_graph(n, 3, 0.5)
@ -125,24 +125,16 @@ def generate_star_graph(n):
# Generate the network from nw type # Generate the network from nw type
def generate_network(num_nodes, nw_type): def generate_network(n, nw_type):
G = nx.empty_graph() switch = {
if nw_type == networkType.configmodel: networkType.configmodel: generate_config_model(n),
G = generate_config_model(num_nodes) networkType.scalefree: generate_scalefree_graph(n),
elif nw_type == networkType.scalefree: networkType.newmanwattsstrogatz: generate_newmanwattsstrogatz_graph(n),
G = generate_scalefree_graph(num_nodes) networkType.barbell: generate_barbell_graph(n),
elif nw_type == networkType.newmanwattsstrogatz: networkType.balancedtree: generate_balanced_tree(n),
G = generate_newman_watts_strogatz_graph(num_nodes) networkType.star: generate_star_graph(n)
elif nw_type == networkType.barbell: }
G = generate_barbell_graph(num_nodes) return postprocess_network(switch.get(nw_type))
elif nw_type == networkType.balancedtree:
G = generate_balanced_tree(num_nodes)
elif nw_type == networkType.star:
G = generate_star_graph(num_nodes)
else:
print(f"{nw_type} : Unsupported network type")
sys.exit(1)
return postprocess_network(G)
# Label the generated network with prefix # Label the generated network with prefix
@ -158,14 +150,11 @@ def postprocess_network(G):
#Generate per node toml configs #Generate per node toml configs
def generate_toml(topics, node_type=nodeType.desktop): def generate_toml(topics, node_type=nodeType.desktop):
topic_str = " ". join(get_random_sublist(topics)) # topics as a space separated string topic_str = " ". join(get_random_sublist(topics)) # topics as a space separated string
if node_type == nodeType.desktop: switch = {
toml = "rpc-admin = true\nkeep-alive = true\n" nodeType.desktop: "rpc-admin = true\nkeep-alive = true\n",
elif node_type == nodeType.mobile: nodeType.mobile: "rpc-admin = true\nkeep-alive = true\n"
toml = "rpc-admin = true\nkeep-alive = true\n" }
else: toml = f"{switch.get(node_type)}topics = \"{topic_str}\"\n"
print(f"{node_type} : Unsupported node type")
sys.exit(1)
toml = f"{toml}topics = \"{topic_str}\"\n"
return toml return toml