def generate_parameters(N, M, nb_local_community, p, carrying_capacity_b, graph_model): r = stats.uniform.rvs( loc=0, scale=1, size=M ) # growth rate, uniform distribution between 0 and 1, vector of size M while np.any(r == 0.): for index, value in enumerate(r): if value == 0.: r[index] = stats.uniform.rvs(loc=0, scale=1) # k: carrying capacity k = stats.beta.rvs(a=1, b=carrying_capacity_b, loc=0, scale=1, size=M) # Scaling of carrying capacity k between 1 and 100 k = 1. + k * 100 # Interaction matrix A ## Random Erdös-Renyi model if graph_model == "ER": A = graph.generate_random_graph(N, p) elif graph_model == "WS": A = graph.generate_watts_strogatz_graph(N, p) else: raise ValueError("Unknown graph model.") # Initial abundance of species x_0 x_0 = stats.uniform.rvs( loc=10, scale=90, size=(nb_local_community, M)) # Uniform distribution between 10 and 100 return r, k, A, x_0
def main(): """ Generates new graphs """ parser = argparse.ArgumentParser() parser.add_argument("-p", help="path to data directory", type=str) parser.add_argument("-nn", help="number of nodes in new graph", type=int) parser.add_argument("-od", help="number of OD pairs in new graph", type=int) #TODO: manage edge cases when n_OD is too large for instance args = parser.parse_args() path = os.path.join('/Users/lucasfuentes/icu/notebooks/Data_comparison', args.p) _, _ = generate_random_graph(args.nn, args.od, path) return
import random import graph n = 20 m = 30 G = graph.generate_random_graph(n, m) (V, E) = G # print(G) print("Number of edges is {}, we want {}".format(len(E), m)) start = random.choice(list(V)) stop = random.choice(list(V)) cur = start print("Starting at {}".format(cur)) if len(graph.neighbours_of(G, cur)) == 0: raise Exception("Bad luck, {} has no neighbours".format(cur)) num_steps = 0 max_num_steps = 1000 history = [cur] while cur != stop and num_steps < max_num_steps: num_steps += 1 # pick a neighbour of cur at random neighbours = graph.neighbours_of(G, cur)
num_edges = int(argv.pop(0)) elif token == "--start": start = int(argv.pop(0)) elif token == "--stop": stop = int(argv.pop(0)) elif token == "--max_steps": max_num_steps = int(argv.pop(0)) else: print("Bad argument {}".format(token)) sys.exit(1) # use supplied seed if given if seed is not None: random.seed(seed) G = graph.generate_random_graph(num_vertices, num_edges) dot_file_name = "walk-graph.dot" # display.write_dot_desc(G, dot_file_name) (V, E) = G # start and stop vertices if start is None: start = random.choice(list(V)) if stop is None: stop = random.choice(list(V)) # rendering attributes attr = {"vertex_color":{}, "edge_color":{}}
A.append(vertex_id) else: B.append(vertex_id) return A,B def random_contraction(g): A,B = Vertex(),Vertex() A_ids,B_ids = [],[] while len(g.get_vertices()) > 2: print("num verticies",g.num_vertices) time.sleep(1) edge = random.choice(g.get_all_edges()) start_edges = g.get_edges(edge[0]) end_edges = g.get_edges(edge[1]) g.remove_vertex(edge[0]) removed_vertex,removed_edges = g.remove_vertex(edge[1]) print("num verticies",g.num_vertices) A,B = choice(removed_vertex,removed_edges,A,B) g.add_vertex(edge[0]) start_edges = update_edges(edge,start_edges) end_edges = update_edges(edge,end_edges) for edge in start_edges: g.add_edge(edge[0],edge[1]) for edge in end_edges: g.add_edge(edge[0],edge[1]) return A,B,g.get_all_edges() A,B,edges = random_contraction(generate_random_graph()) import code code.interact(local=locals())
B.append(vertex_id) return A, B def random_contraction(g): A, B = Vertex(), Vertex() A_ids, B_ids = [], [] while len(g.get_vertices()) > 2: print("num verticies", g.num_vertices) time.sleep(1) edge = random.choice(g.get_all_edges()) start_edges = g.get_edges(edge[0]) end_edges = g.get_edges(edge[1]) g.remove_vertex(edge[0]) removed_vertex, removed_edges = g.remove_vertex(edge[1]) print("num verticies", g.num_vertices) A, B = choice(removed_vertex, removed_edges, A, B) g.add_vertex(edge[0]) start_edges = update_edges(edge, start_edges) end_edges = update_edges(edge, end_edges) for edge in start_edges: g.add_edge(edge[0], edge[1]) for edge in end_edges: g.add_edge(edge[0], edge[1]) return A, B, g.get_all_edges() A, B, edges = random_contraction(generate_random_graph()) import code code.interact(local=locals())