def create_k_partite(maxi): """ Función para la creación de una gráfica k-partita. :param maxi: La cota superior al número de vértices que tendrá la gráfica aleatoria generada. :return: Una gráfica k-partita de la biblioteca networkx. :rtype: nx.Graph """ n = 1 k = 3 # Quiero repartir uniformemente la misma cantidad de vértices en cada partición. while n % k != 0: # Generando la n y la k (números para vértices y particiones, resp.) de forma # aleatoria en un intervalo permitido. n = randint(2, maxi) k = randint(5, 10) print("Orden de la gráfica (|V|):", n) print("Número de particiones (k):", k) # Dependiendo de un segundo volado, se genera una gráfica k-partida de uno u otro tipo. which_type = randint(1, 2) if which_type == 1: return nx.complete_multipartite_graph(*_construct_list_kp(n, k)), k else: return nx.turan_graph(n, k), k
def get_graph_list(num_factors): graph_list = [] # 2, 3 bipartite graph g = nx.turan_graph(n=5, r=2) graph_list.append(nx.to_numpy_array(g)) g = nx.house_x_graph() graph_list.append(nx.to_numpy_array(g)) g = nx.balanced_tree(r=3, h=2) graph_list.append(nx.to_numpy_array(g)) g = nx.grid_2d_graph(m=3, n=3) graph_list.append(nx.to_numpy_array(g)) g = nx.hypercube_graph(n=3) graph_list.append(nx.to_numpy_array(g)) g = nx.octahedral_graph() graph_list.append(nx.to_numpy_array(g)) return graph_list[:num_factors]
def test_result_turan_graph_50_20(self): assert (calc_and_compare(NX.turan_graph(50, 5)))
G3S=0 G1T=0 G2T=0 G3T=0 mu=10 sigma=2.5 #Orden logaritmico for logarithmOrder in range(3,5): print('Orden: ',logarithmOrder) log = 2**logarithmOrder ban=True # 3 Metodos de generación distintos G1 = nx.lollipop_graph(log, 2) for e in G1.edges(): G1[e[0]][e[1]]['capacity'] = np.random.normal(mu, sigma) G2 = nx.turan_graph(log, 2) for e in G2.edges(): G2[e[0]][e[1]]['capacity'] = np.random.normal(mu, sigma) G3 = nx.ladder_graph(log) for e in G3.edges(): G3[e[0]][e[1]]['capacity'] = np.random.normal(mu, sigma) for newPair in range(5): print('Pareja: ',newPair) #10 Grafos for graphRepetition in range(10): if ban: ban=False while G1T==G1S: G1S = choice(list(G1.nodes())) G1T = choice(list(G1.nodes())) while G2T==G2S:
def test_turan_graph(self): assert nx.number_of_edges(nx.turan_graph(13, 4)) == 63 assert is_isomorphic(nx.turan_graph(13, 4), nx.complete_multipartite_graph(3, 4, 3, 3))
def get_connectivity_graph(qubits, topology='grid', param=None): attempt = 0 while attempt < 10: if topology == 'grid': # assume square grid side = int(np.sqrt(qubits)) G = nx.grid_2d_graph(side, side) elif topology == 'erdosrenyi': if param == None: print("Erdos Renyi graph needs parameter p.") G = nx.fast_gnp_random_graph(qubits, param) elif topology == 'turan': if param == None: print("Turan graph needs parameter r.") G = nx.turan_graph(qubits, param) elif topology == 'regular': if param == None: print("d-regular graph needs parameter d.") G = nx.random_regular_graph(param, qubits) elif topology == 'cycle': G = nx.cycle_graph(qubits) elif topology == 'wheel': G = nx.wheel_graph(qubits) elif topology == 'complete': G = nx.complete_graph(qubits) elif topology == 'hexagonal': # assume square hexagonal grid, node = 2(m+1)**2-2 side = int(np.sqrt((qubits + 2) / 2)) - 1 G = nx.hexagonal_lattice_graph(side, side) elif topology == 'path': G = nx.path_graph(qubits) elif topology == 'ibm_falcon': # https://www.ibm.com/blogs/research/2020/07/qv32-performance/ # 27 qubits G = nx.empty_graph(27) G.name = "ibm_falcon" G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 4), (3, 5), (5, 6), (6, 7), (7, 8), (8, 9), (8, 10), (10, 11), (1, 12), (6, 13), (11, 14), (12, 15), (15, 16), (16, 17), (17, 18), (17, 19), (19, 20), (13, 20), (20, 21), (21, 22), (22, 23), (22, 24), (24, 25), (14, 25), (25, 26)]) elif topology == 'ibm_penguin': # 20 qubits G = nx.empty_graph(20) G.name = "ibm_penguin" G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 4), (0, 5), (5, 6), (6, 7), (7, 8), (8, 9), (4, 9), (5, 10), (10, 11), (11, 12), (7, 12), (12, 13), (13, 14), (9, 14), (10, 15), (15, 16), (16, 17), (17, 18), (18, 19), (14, 19)]) elif topology == '1express': # path with express channels G = nx.convert_node_labels_to_integers(nx.path_graph(qubits)) G.add_edges_from([(s, s + param) for s in range(0, qubits - param, param // 2)]) elif topology == '2express': # grid with express channels side = int(np.sqrt(qubits)) G = nx.convert_node_labels_to_integers(nx.grid_2d_graph( side, side)) G.add_edges_from([ (s, s + param) for x in range(side) for s in range(x * side, x * side + side - param, param // 2) ]) # rows G.add_edges_from([ (s, s + param * side) for y in range(side) for s in range(y, y + side * (side - param), param // 2 * side) ]) # cols else: print("Topology %s not recognized; use empty graph instead." % topology) G = nx.empty_graph(qubits) if nx.is_connected(G) or nx.is_empty(G): break else: attempt += 1 return nx.convert_node_labels_to_integers(G)
G = nx.random_lobster(6, 0.9, 0.9) G = nx.barabasi_albert_graph(8, 5) G = nx.watts_strogatz_graph(8, 3, 0.1) G = nx.erdos_renyi_graph(10, 0.15) G = nx.complete_bipartite_graph(3, 5) G = nx.dorogovtsev_goltsev_mendes_graph(2) G = nx.petersen_graph() G = nx.tutte_graph() G = nx.sedgewick_maze_graph() # cool # G = nx.tetrahedral_graph() # not cool G = nx.ladder_graph(8) G = nx.barbell_graph(5, 2) G = nx.turan_graph(10, 3) def g2d(g): return {k: {k1 for k1 in v} for k, v in g.adj.items()} #pprint(g2d(G)) #nx.draw_shell(G) #plt.show() # sorting nodes (with optional tails - additional strings for each node): # for each node - create "projection" # slice graph into levels by distance # append levels with subgraphs not connected to selected node # canonicalize each subgraph and sort them
'gen': nx.trivial_graph(), 'description_fn': 'trivial_graph()', 'description': 'Return the Trivial graph with one node (with label 0) and no edges.', }, 'turan_graph': { 'name': 'Turan Graph', 'args': ('n', 'r'), 'argtypes': ( int, int, ), 'argvals': (3, 3), 'gen': lambda n, r: nx.turan_graph(n, r), 'description_fn': 'turan_graph(n, r)', 'description': 'Return the Turan Graph.', }, 'wheel_graph': { 'name': 'Wheel Graph', 'args': ('n', ), 'argtypes': (int, ), 'argvals': (3, ), 'gen': lambda n: nx.wheel_graph(n), 'description_fn': 'wheel_graph(n)', 'description': 'Return the wheel graph.', }, 'random_geometric': { 'name': 'Random Geometric',
fig = plt.figure() nx.draw(G, with_labels=True) fig.text(0.02, 0.95, "path graph", fontweight='bold') fig.text(0.02, 0.90, "n(node count) = " + str(n)) plt.show() #star graph G = nx.star_graph(n) fig = plt.figure() nx.draw(G, with_labels=True) fig.text(0.02, 0.95, "star graph", fontweight='bold') fig.text(0.02, 0.90, "n(node count) = " + str(n)) plt.show() #turan graph G = nx.turan_graph(n, 2) fig = plt.figure() nx.draw(G, with_labels=True) fig.text(0.02, 0.95, "turan graph", fontweight='bold') fig.text(0.02, 0.90, "n(node count) = " + str(n)) fig.text(0.02, 0.85, "with 2 disjoint subset") plt.show() #wheel graph G = nx.wheel_graph(n) fig = plt.figure() nx.draw(G, with_labels=True) fig.text(0.02, 0.95, "wheel graph", fontweight='bold') fig.text(0.02, 0.90, "n(node count) = " + str(n)) plt.show()
def create_k_partitte_graph(n: int, k: int) -> nx.classes.graph.Graph: return nx.turan_graph(n, k)