from execute.optimal_distribution import optimal_distribution # Choose simulation options uniform = False num_steps = 250 # Load data and generate network _, routes = load_airport_and_route(deep_load=True) netx = from_edgelist(routes) N = number_of_nodes(netx) net = network(N, graph=netx) budget = balls_per_node * N print('Data imported and network generated') # Get optimal distribution optimal = optimal_distribution(uniform, deep_load=True) # Initialize opponent distribution if uniform: red = array([balls_per_node] * N) else: degrees = array(sorted(degree(netx), key=lambda d: d[0]))[:, 1] max_d_node = argmax(degrees) red = zeros(N) red[max_d_node] = budget # Run optimal strategy net.set_initial_distribution(black=optimal, red=red) exposures = run_polya(net, steps=num_steps)
from model.optimize import simple_centrality, metric_names from execute.optimal_distribution import optimal_distribution # Red distribution (uniform or single) uniform = False airports, routes = load_airport_and_route(deep_load=True) # Import data N = len(airports) # Initialize N budget = balls_per_node * N netx = from_edgelist(routes) # Generate networkx network net = network(N, graph=netx) # Generate network print('Data imported and network generated') degrees = array(sorted(degree(netx), key=lambda d: d[0]))[:, 1] max_d_node = argmax(degrees) # Get index of max degree optimal = optimal_distribution(deep_load=True) if uniform: red = array([balls_per_node] * N) else: red = zeros(N) red[max_d_node] = budget exposures = [] # Run basic metrics for metric_id, _ in enumerate(metric_names): simple_centrality(net, metric_id, red=red) exposures.append(run_polya(net)) # Run optimal strategy
from execute.import_data import load_airport_and_route from execute.optimal_distribution import optimal_distribution from utilities.plotting import plot_net_w_routes, plot_network from networkx import from_edgelist from utilities import filter_degree, re_index from numpy import max, min, multiply, add # Define constants data_path = '../../data/optimal_distribution/f_100_analytical.csv' path = '../../results/network/optimal.csv' # Import data and filter airports, routes = load_airport_and_route(deep_load=True, filter_data=False) airports, _, routes = filter_degree(airports, routes, d_cut_off=100) airports, routes = re_index(airports, routes) # Initialize/calculate plotting values weights = optimal_distribution(alt_file=data_path) min_val, max_val = min(weights), max(weights) delt = max_val - min_val weights = multiply(add(weights, -min_val), 1 / delt) # Plot network netx = from_edgelist(routes) plot_network(netx, netx_plot=True, weights=weights, file_name=path, plot_edges=True, size=(10, 6))