def generate_ASN_grid(numOfNetworks, wires_per_network): import wires adj_list = [] graph_list = [] for i in range(numOfNetworks): wires_dict = wires.generate_wires_distribution( number_of_wires=wires_per_network, wire_av_length=150, wire_dispersion=50, gennorm_shape=3, centroid_dispersion=60, Lx=3e2, Ly=3e2, this_seed=i * 5) wires_dict = wires.detect_junctions(wires_dict) wires_dict = wires.generate_graph(wires_dict) while not wires.check_connectedness(wires_dict): wires_dict = wires.generate_wires_distribution( number_of_wires=wires_per_network, wire_av_length=150, wire_dispersion=50, gennorm_shape=3, centroid_dispersion=60, Lx=3e2, Ly=3e2, this_seed=np.random.randint(1000)) wires_dict = wires.detect_junctions(wires_dict) wires_dict = wires.generate_graph(wires_dict) adj_list.append(wires_dict['adj_matrix']) graph_list.append(wires_dict['G']) num_wires_list = [len(graph_list[i]) for i in range(len(graph_list))] total_wires = sum(num_wires_list) bigMat = np.zeros((total_wires + 2, total_wires + 2)) inList = np.zeros(len(adj_list)) outList = np.zeros(len(adj_list)) node_count = 0 for i in range(len(adj_list)): bigMat[node_count:node_count + num_wires_list[i], node_count:node_count + num_wires_list[i]] = adj_list[i] inList[i], outList[i] = get_farthest_pairing(adj_list[i]) + node_count node_count += num_wires_list[i] inList = inList.astype(int) outList = outList.astype(int) bigMat[total_wires, inList] = 1 bigMat[inList, total_wires] = 1 bigMat[total_wires + 1, outList] = 1 bigMat[outList, total_wires + 1] = 1 return bigMat
def generateNetwork(numOfWires = 100, dispersion=100, mean_length = 100, this_seed = 42, iterations=0, max_iters = 10): import wires wires_dict = wires.generate_wires_distribution(number_of_wires = numOfWires, wire_av_length = mean_length, wire_dispersion = 20, gennorm_shape = 3, centroid_dispersion = dispersion, Lx = 5e2, Ly = 5e2, this_seed = this_seed) wires_dict = wires.detect_junctions(wires_dict) wires_dict = wires.generate_graph(wires_dict) if wires.check_connectedness(wires_dict): logging.info(f'The returned network has {wires_dict["number_of_junctions"]} junctions.') return wires_dict elif iterations < max_iters: generateNetwork(numOfWires, dispersion, mean_length, this_seed+1, iterations+1, max_iters) else: logging.warning('No network is generated.') return None
def wires_tester(number_of_wires, avg_length, centroid_dispersion, out_mode='number_of_junctions', attempt_limit=5): counter = 0 out = -1 while (out == -1) & (counter < attempt_limit): temp_seed = np.random.randint(2000) temp_distribution = wires.generate_wires_distribution( number_of_wires=number_of_wires, wire_av_length=avg_length, wire_dispersion=20, gennorm_shape=3, centroid_dispersion=centroid_dispersion, Lx=2e2, Ly=2e2, this_seed=temp_seed) counter += 1 temp_distribution = wires.detect_junctions(temp_distribution) temp_distribution = wires.generate_graph(temp_distribution) if wires.check_connectedness(temp_distribution): logging.info( f"{temp_distribution['number_of_wires']} nanowire network is connected with seed {temp_seed}, average length of {temp_distribution['avg_length']}, dispersion of {temp_distribution['centroid_dispersion']}." ) temp_distribution['clustering'] = nx.average_clustering( temp_distribution['G']) temp_distribution[ 'avg_path_length'] = nx.average_shortest_path_length( temp_distribution['G']) out = temp_distribution[out_mode] else: logging.warning( f"{temp_distribution['number_of_wires']} nanowire network is NOT connected. Current seed is {temp_seed}, average length is {temp_distribution['avg_length']}, dispersion is {temp_distribution['centroid_dispersion']}." ) return out
from dataStruct import * import wires import logging import pickle sparse_ranger = range(20, 100, 10) realization_list = [] for this_sparse in sparse_ranger: logging.info( f"Simulation #{sparse_ranger.index(this_sparse)+1}/{len(sparse_ranger)}" ) wires_dict = wires.generate_wires_distribution( number_of_wires=100, wire_av_length=100, wire_dispersion=10, gennorm_shape=3, centroid_dispersion=this_sparse, Lx=3e2, Ly=3e2) # Get junctions list and their positions wires_dict = wires.detect_junctions(wires_dict) wires_dict = wires.generate_graph(wires_dict) if not wires.check_connectedness(wires_dict): logging.warning( f"This network is not connected, will move on to next one! Current dispersion is {wires_dict['centroid_dispersion']}." ) continue Connectivity = connectivity__(wires_dict=wires_dict)
parser.add_argument('--view_only', dest='view_only', action='store_true', default=False, help='Flag to not save the file.') parser.set_defaults(plot_network=False) args = parser.parse_args() # Generate the network wires_dict = wires.generate_wires_distribution( number_of_wires=args.nwires, wire_av_length=args.mean_length, wire_dispersion=args.std_length, gennorm_shape=args.shape, centroid_dispersion=args.cent_dispersion, this_seed=args.seed, Lx=args.Lx, Ly=args.Ly) # Get junctions list and their positions wires_dict = wires.detect_junctions(wires_dict) # Genreate graph object and adjacency matrix wires_dict = wires.generate_graph(wires_dict) if not wires.check_connectedness(wires_dict): logging.warning("Will select the largest connected component.") wires_dict = wires.select_largest_component(wires_dict)
for nwires in wireList: for seed in seedList: for Lx in LxList: if square: Ly = Lx if fixedDensity: nwires = int(density * Lx * Ly) print('Now generating: nwires = ', nwires, ', seed = ', seed, ' grid = ', Lx, 'x', Ly, 'um^2') # Generate the network wires_dict = wires.generate_wires_distribution( number_of_wires=nwires, wire_av_length=mean_length, wire_dispersion=std_length, gennorm_shape=shape, centroid_dispersion=cent_dispersion, this_seed=seed, Lx=Lx, Ly=Ly, oldNameConvention=oldNameConvention) # Get junctions list and their positions wires_dict = wires.detect_junctions(wires_dict) # Genreate graph object and adjacency matrix wires_dict = wires.generate_graph(wires_dict) if not wires.check_connectedness(wires_dict): wires_dict = wires.select_largest_component(wires_dict) #Calculate network statistics