Ejemplo n.º 1
0
def generate_GNE(n, m):
    ak = math.floor(2 * m / n)
    dm = 2 * m - ak * n
    g = random_graph(n,
                     lambda i: ak + 1 if i < dm else ak,
                     directed=False,
                     random=False)
    random_rewire(g, model='erdos', n_iter=10, edge_sweep=True)
    return g
Ejemplo n.º 2
0
def rewire_dataset_partially(orig_dataset_name, new_dataset_name, p=0.1):
    graphs, prop_maps = read_dataset(orig_dataset_name)
    for g in graphs:
        pins = g.new_edge_property('int')
        for e in g.edges():
            if random.random() < p:
                pins[e] = 0
            else:
                pins[e] = 1
        random_rewire(g, model='erdos', n_iter=10, edge_sweep=True, pin=pins)
    write_modified_dataset(orig_dataset_name, new_dataset_name, graphs,
                           prop_maps)
Ejemplo n.º 3
0
def opt(g,model="uncorrelated"):
  h = gt.Graph(g)
  diam, aspl = diam_aspl(h)
  
  while True:
    print(diam,aspl)
    tmp = gt.Graph(h)
    print(random_rewire(tmp,model=model))
    tmp_diam, tmp_aspl = diam_aspl(tmp)
    if tmp_diam < diam or ( tmp_diam == diam and tmp_aspl < aspl ):
      h, diam, aspl = tmp, tmp_diam, tmp_aspl
Ejemplo n.º 4
0
def opt(g, model="uncorrelated"):
    h = gt.Graph(g)
    diam, aspl = diam_aspl(h)

    while True:
        print(diam, aspl)
        tmp = gt.Graph(h)
        print(random_rewire(tmp, model=model))
        tmp_diam, tmp_aspl = diam_aspl(tmp)
        if tmp_diam < diam or (tmp_diam == diam and tmp_aspl < aspl):
            h, diam, aspl = tmp, tmp_diam, tmp_aspl
Ejemplo n.º 5
0
def gnp(n, e):        
    '''
    Return an Erdos-renyi graph with n vertices and e edges
    '''
    g = Graph(directed=False)
    g.add_vertex(n)
   
    edgesAdded  = 0
    edgesNeeded = True
    while edgesNeeded:
        fromNode = range(n); toNode = range(n);
        np.random.shuffle(fromNode)
        np.random.shuffle(toNode) 
        for i in xrange(n):
            if fromNode[i] == toNode[i] or g.edge(fromNode[i], toNode[i]) != None:  continue #No self-loops or parallel edges
            g.add_edge(fromNode[i], toNode[i])
            edgesAdded += 1
            if  edgesAdded >= e: 
                edgesNeeded = False
                break
    generation.random_rewire(g, model="erdos")
    return g
Ejemplo n.º 6
0
def rewire_dataset_with_preserved_degree(orig_dataset_name, new_dataset_name):
    graphs, prop_maps = read_dataset(orig_dataset_name)
    for g in graphs:
        random_rewire(g, model='configuration', n_iter=10, edge_sweep=True)
    write_modified_dataset(orig_dataset_name, new_dataset_name, graphs,
                           prop_maps)