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
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) SimulationOptions = simulation_options__(dt=1e-3, T=10, contactMode='farthest') tempStimulus = stimulus__(biasType='DC', TimeVector=SimulationOptions.TimeVector, onTime=0, offTime=10, onAmp=0.5,