def generate_struct_mask(struct, n_nodes, shuffle_nodes): # a horrible collection of ifs due to args in nx constructors if struct == "star": g = nx.star_graph(n_nodes) elif struct == "random_tree": g = nx.random_tree(n_nodes) elif struct == "powerlaw_tree": g = nx.powerlaw_tree(n_nodes, gamma=3, seed=None) elif struct == "binary_tree": raise NotImplementedError("Implement a binary tree.") elif struct == "path": g = nx.path_graph(n_nodes) elif struct == "cycle": g = nx.cycle_graph(n_nodes) elif struct == "ladder": g = nx.ladder_graph(n_nodes) elif struct == "grid": m = np.random.choice(range(1, n_nodes+1)) n = n_nodes // m g = nx.grid_2d_graph(m, n) elif struct == "circ_ladder": g = nx.circular_ladder_graph(n_nodes) elif struct == "barbell": assert n_nodes >= 4 m = np.random.choice(range(2, n_nodes-1)) blocks = (m, n_nodes-m) g = nx.barbell_graph(*blocks) elif struct == "loll": assert n_nodes >= 2 m = np.random.choice(range(2, n_nodes+1)) g = nx.lollipop_graph(m, n_nodes-m) elif struct == "wheel": g = nx.wheel_graph(n_nodes) elif struct == "bipart": m = np.random.choice(range(n_nodes)) blocks = (m, n_nodes-m) g = nx.complete_multipartite_graph(*blocks) elif struct == "tripart": # allowed to be zero m, M = np.random.choice(range(n_nodes), size=2) if m > M: m, M = M, m blocks = (m, M-m, n_nodes-M) g = nx.complete_multipartite_graph(*blocks) elif struct == "fc": g = nx.complete_graph(n_nodes) else: raise NotImplementedError("Structure {} not implemented yet.".format(struct)) node_order = list(range(n_nodes)) if shuffle_nodes: np.random.shuffle(node_order) # a weird subclass by default; raises a deprecation warning # with a new update of networkx, this should be updated to # nx.convert_matrix.to_numpy_array np_arr_g = nx.to_numpy_matrix(g, nodelist=node_order) return np_arr_g.astype(int)
def test_multipartite_layout(self): sizes = (0, 5, 7, 2, 8) G = nx.complete_multipartite_graph(*sizes) vpos = nx.multipartite_layout(G) assert len(vpos) == len(G) start = 0 for n in sizes: end = start + n assert all(vpos[start][0] == vpos[i][0] for i in range(start + 1, end)) start += n vpos = nx.multipartite_layout(G, align="horizontal", scale=2, center=(2, 2)) assert len(vpos) == len(G) start = 0 for n in sizes: end = start + n assert all(vpos[start][1] == vpos[i][1] for i in range(start + 1, end)) start += n pytest.raises(ValueError, nx.multipartite_layout, G, align="foo")
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 generate_spine_and_leaf_class(self, class_name, verify_name, constants): """Return a class type as each test generated from a set of tests in the graph atlas""" test_class = type(class_name, (ValveGenerativeBase, ), {**constants}) verify_func = getattr(test_class, verify_name) set_up = self.setup_generator(verify_func) setattr(test_class, 'set_up', set_up) curr_nodes = 8 curr_tests = 0 # Iteratively generate spine & leaf networks until `MAX_TESTS` stopping point # By testing all non-isomorphic topologies up to (and including) 7 nodes, # SPINE_NODES + LEAF_NODES <= 7 are already tested # Loop until we have reached a desired number of tests while curr_tests <= self.MAX_TESTS: # Get permutations of numbers that sum to the current number of nodes # The current number of nodes will be split between the two partites of the topology for nodes in ClassGenerator.sums(2, curr_nodes): if 0 in nodes or nodes[0] > nodes[1]: # Ignore empty partites or inverse solutions continue test_name = 'test_%s_%s_spine_and_%s_leaf_topology' % ( curr_tests, nodes[0], nodes[1]) graph = networkx.complete_multipartite_graph(*nodes) test_func = self.test_generator([graph]) setattr(test_class, test_name, test_func) curr_tests += 1 if curr_tests > self.MAX_TESTS: break # Increase current number of nodes curr_nodes += 1 return test_class
def complete_multipartite_graph(n, m=None, o=10): #TODO: More than 3 layers? if m is None: m = n G = nx.complete_multipartite_graph(n, m, o) G.name = 'multipartite' #TODO: pos based on multipartite_layout gist return G
def classic_graphs(): print("Balanced Tree") BG = nx.balanced_tree(3, 2) draw_graph(BG) print("Barbell Graph") BBG = nx.barbell_graph(3, 2) draw_graph(BBG) print("Complete Graph") CG = nx.complete_graph(10) draw_graph(CG) print("Complete Multipartite Graph") CMG = nx.complete_multipartite_graph(1, 2, 10) print([CMG.node[u]['block'] for u in CMG]) print(CMG.edges(0)) print(CMG.edges(2)) print(CMG.edges(4)) draw_graph(CMG) print("Circular Ladder Graph") CLG = nx.circular_ladder_graph(5) draw_graph(CLG) print("Dorogovtsev Goltsev Mendes Graph") DGMG = nx.dorogovtsev_goltsev_mendes_graph(3) draw_graph(DGMG) print("Empty Graph") EG = nx.empty_graph(5, create_using=nx.DiGraph()) draw_graph(EG) print("Grid 2D Graph") G2DG = nx.grid_2d_graph(5, 6) draw_graph(G2DG) print("Grid Graph") GDG = nx.grid_graph(dim=[5, 2]) draw_graph(GDG) print("Hypercube Graph") HG = nx.hypercube_graph(3) draw_graph(HG) print("Ladder Graph") LG = nx.ladder_graph(8) draw_graph(LG) print("Ladder Graph") LG = nx.ladder_graph(8) draw_graph(LG) print("Lollipop Graph") LPG = nx.lollipop_graph(n=6, m=4) draw_graph(LPG) print("Null Graph") NG = nx.null_graph() draw_graph(NG) print("Path Graph") PG = nx.path_graph(16) draw_graph(PG) print("Star Graph") SG = nx.star_graph(16) draw_graph(SG) print("Trivial Graph") TG = nx.trivial_graph() draw_graph(TG) print("Wheel Graph") WG = nx.wheel_graph(n=18) draw_graph(WG)
def test_complete_2_partite_graph(self): """Tests that the complete 2-partite graph is the complete bipartite graph. """ G = nx.complete_multipartite_graph(2, 3) H = nx.complete_bipartite_graph(2, 3) assert_nodes_equal(G, H) assert_edges_equal(G.edges(), H.edges())
def Network_initial(network_name=None, network_size=300, density=0.2, Depth=10, MC_configure=None): if network_name is "ER": rg = nx.erdos_renyi_graph(network_size, density, directed=False) #ER R_initial = nx.adjacency_matrix(rg).toarray() elif network_name is "DCG": rg = nx.erdos_renyi_graph(network_size, density, directed=True) #ER R_initial = nx.adjacency_matrix(rg).toarray() elif network_name is "DAG": if MC_configure is not None: xx = np.append(0, np.cumsum(MC_configure['number'])) for i in range(xx.shape[0] - 1): Reject_index = 1 for j in range(0, xx.shape[0] - 1): if len(MC_configure[i + 1]) == np.sum( np.isin(MC_configure[i + 1], MC_configure[j + 1] + 1)): Reject_index = 0 if Reject_index == 1 and (MC_configure[i + 1] != 1).all(): print( "fail to construct the DAN under current Memory commnity strcutrue configuration" ) Reject_index = 2 if Reject_index != 2: R_initial_0 = np.zeros((network_size, network_size)) for i in range(xx.shape[0] - 1): for j in range(xx.shape[0] - 1): if len(MC_configure[i + 1]) == np.sum( np.isin(MC_configure[i + 1] + 1, MC_configure[j + 1])): R_initial_0[xx[i]:xx[i + 1], xx[j]:xx[j + 1]] = 1 R_initial = np.triu(R_initial_0, 1) else: R_initial = None else: xx = R_shuffle(network_size, Depth) # xx=np.array([3,4,3]) # xx=np.array([60,60,60,60,60]) # xx=np.array([30,30,30,30,30,30,30,30,30,30])*3 rg = nx.complete_multipartite_graph(*tuple(xx)) x = nx.adjacency_matrix(rg).toarray() R_initial = np.triu(x, 1) # R_initial= np.tril(x,1) Real_density = np.sum(R_initial > 0) * 1.0 / (network_size**2) if Real_density > 0 and density < Real_density: R_initial[rng.rand( *R_initial.shape) <= (1.0 - density / Real_density)] = 0 R_initial = np.triu(R_initial, 1) return R_initial
def contains_forbidden_subgraph( G): #checks whether a graph has a forbidden subgraph K5 = nx.complete_graph(5) K33 = nx.complete_multipartite_graph(3, 3) GM = nx.algorithms.isomorphism.GraphMatcher(G, K5) if nx.is_isomorphic(G, K5) or GM.subgraph_is_isomorphic(): return True GM = nx.algorithms.isomorphism.GraphMatcher(G, K33) if nx.is_isomorphic(G, K33) or GM.subgraph_is_isomorphic(): return True return False
def test_complete_multipartite_graph(self): """Tests for generating the complete multipartite graph.""" G = nx.complete_multipartite_graph(2, 3, 4) blocks = [(0, 1), (2, 3, 4), (5, 6, 7, 8)] # Within each block, no two vertices should be adjacent. for block in blocks: for u, v in itertools.combinations_with_replacement(block, 2): assert v not in G[u] assert G.nodes[u] == G.nodes[v] # Across blocks, all vertices should be adjacent. for (block1, block2) in itertools.combinations(blocks, 2): for u, v in itertools.product(block1, block2): assert v in G[u] assert G.nodes[u] != G.nodes[v]
def test_complete_multipartite_graph(self): """Tests for generating the complete multipartite graph.""" G = nx.complete_multipartite_graph(2, 3, 4) blocks = [(0, 1), (2, 3, 4), (5, 6, 7, 8)] # Within each block, no two vertices should be adjacent. for block in blocks: for u, v in itertools.combinations_with_replacement(block, 2): assert_true(v not in G[u]) assert_equal(G.node[u], G.node[v]) # Across blocks, all vertices should be adjacent. for (block1, block2) in itertools.combinations(blocks, 2): for u, v in itertools.product(block1, block2): assert_true(v in G[u]) assert_not_equal(G.node[u], G.node[v])
def test_quotient_graph_complete_multipartite(self): """Tests that the quotient graph of the complete *n*-partite graph under the "same neighbors" node relation is the complete graph on *n* nodes. """ G = nx.complete_multipartite_graph(2, 3, 4) # Two nodes are equivalent if they are not adjacent but have the same # neighbor set. same_neighbors = lambda u, v: (u not in G[v] and v not in G[u] and G[u] == G[v]) expected = nx.complete_graph(3) actual = nx.quotient_graph(G, same_neighbors) # It won't take too long to run a graph isomorphism algorithm on such # small graphs. assert_true(nx.is_isomorphic(expected, actual))
def large_graph_tests(): if not total_coloring_test("Complete graph on 7 vertices", networkx.complete_graph(7), 7): return False if not total_coloring_test("Cycle of length 100", networkx.cycle_graph(100), 4): return False if not total_coloring_test("Star graph on 200 vertices", networkx.star_graph(200), 201): return False if not total_coloring_test("Complete bipartite graph on 4+4 vertices", networkx.complete_multipartite_graph(4, 4), 6): return False if not total_coloring_test("Hypercube of dimension 5", networkx.hypercube_graph(5), 6): return False return True
def compute_similarity_matrix(Xn, n, m, a, b): #create W W = np.zeros((n * m, n * m)) #generate complete multipartite graph connections = [m for i in range(n)] G = nx.complete_multipartite_graph(*connections) for edge in G.edges: #select points to relate x_i = Xn[floor(edge[0] / m)][edge[0] % m] x_j = Xn[floor(edge[1] / m)][edge[1] % m] #compute weights d = dist(x_i, x_j) w = weight(d, a, b) W[edge[0], edge[1]] = w W[edge[1], edge[0]] = w return W
def generate_graph(k_part, num_nodes, density, noise_level): ''' assume max entropy i.e. flat distribution of nodes into partitions ''' part_num_nodes = int(1.0 * num_nodes / k_part) remainder = num_nodes - part_num_nodes * (k_part - 1) parts = tuple([part_num_nodes] * (k_part - 1) + [remainder]) G = nx.complete_multipartite_graph(*parts) complement_edges = set(nx.complement(G).edges()) # subsample edges to delete in order to achieve the target density edges = G.edges() deleted_edges = random.sample(edges, int(len(edges) * (1.0 - density))) G.remove_edges_from(list(deleted_edges)) deleted_nodes = nx.isolates(G) G.remove_nodes_from(list(deleted_nodes)) num_noise_edges = int(len(G.edges()) * noise_level) G.add_edges_from(random.sample(complement_edges, num_noise_edges)) return G
def TestIdenticalGraphs(scheme): result = "" g = nx.complete_graph(100) w = WL_Wrapper(g,g,scheme) if abs(w.score - 1 <0.01): result = result + test_status.format(Name="TestIdenticalGraphs",result="complete_graph: PASS") else: result = result + test_status.format(Name="TestIdenticalGraphs",result="complete_graph: FAIL") pass g = nx.complete_multipartite_graph(10) w = WL_Wrapper(g,g,scheme) if abs(w.score - 1 <0.01): result = result + test_status.format(Name="TestIdenticalGraphs",result="complete_multipartite_graph(10): PASS") else: result = result + test_status.format(Name="TestIdenticalGraphs",result="complete_multipartite_graph(10): FAIL") pass g = nx.empty_graph(100) w = WL_Wrapper(g,g,scheme) if abs(w.score - 1 <0.01): result = result + test_status.format(Name="TestIdenticalGraphs",result="empty_graph(100): PASS") else: result = result + test_status.format(Name="TestIdenticalGraphs",result="empty_graph(100): FAIL") pass return result
def test_complete_1_partite_graph(self): """Tests that the complete 1-partite graph is the empty graph.""" G = nx.complete_multipartite_graph(3) H = nx.empty_graph(3) assert_nodes_equal(G, H) assert_edges_equal(G.edges(), H.edges())
def test_complete_0_partite_graph(self): """Tests that the complete 0-partite graph is the null graph.""" G = nx.complete_multipartite_graph() H = nx.null_graph() assert_nodes_equal(G, H) assert_edges_equal(G.edges(), H.edges())
def test_line_inverse_line_multipartite(self): G = nx.complete_multipartite_graph(3, 4, 5) H = nx.line_graph(G) J = nx.inverse_line_graph(H) assert_true(nx.is_isomorphic(G, J))
# K5.3: two disconnected components, c1 and c2, where C1 is a 5-clique K5 and C2 is a 3-clique K3 K3 = nx.complete_graph(3) K53 = nx.disjoint_union(K5,K3) adjacencyMatrix53 = nx.adjacency_matrix(K53) print('Adjacency matrix for K5.3') print(adjacencyMatrix53.todense()) # K5.3e: Almost the same as K53 but there is a single edge connecting the two components K53e = nx.disjoint_union(K5,K3) K53e.add_edge(5,1) adjacencyMatrixK53e = nx.adjacency_matrix(K53e) print('Adjacency matrix for K5.3e') print(adjacencyMatrixK53e.todense()) # B2.3: Complete bi-partite graph with n1=2 nodes in the first part and n2=3 nodes in the second part B23 = nx.complete_multipartite_graph(2,3) adjacencyMatrixB23 = nx.adjacency_matrix(B23) print('Adjacency matrix for B2.3') print(adjacencyMatrixB23.todense()) # S5: A vertex star (one central "hub" node that connects to all the other "spoke" nodes) S5 = nx.star_graph(4) adjacencyMatrixS5 = nx.adjacency_matrix(S5) print('Adjacency matrix for S5') print(adjacencyMatrixS5.todense()) # P5: A simple path of 5 vertices P5=nx.path_graph(5) adjacencyMatrixP5 = nx.adjacency_matrix(P5) print('Adjacency matrix for P5') print(adjacencyMatrixP5.todense())
def is_K33_possible( G ): #check whether we have enough edges and vertices left to construct K33 K33 = nx.complete_multipartite_graph(3, 3) return len(G.nodes()) >= len(K33.nodes()) and len(G.edges()) >= len( K33.edges())
def gen_bipartite(params): n = int(params['n']) m = int(params['m']) return nx.complete_multipartite_graph(n, m), 'bipartite_n-{}_m-{}'.format( n, m)
def test_result_k_multipartite_10_10(self): assert (calc_and_compare(NX.complete_multipartite_graph([10, 10])))
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 complete_multipartite_graph(nn): return nx.complete_multipartite_graph(*nn)
def test_line_inverse_line_multipartite(self): G = nx.complete_multipartite_graph(3, 4, 5) H = nx.line_graph(G) J = nx.inverse_line_graph(H) assert nx.is_isomorphic(G, J)
def gen_laplacian(data_num=DATA_NUM, opt=27, cache=False): label = None if cache: print('Loading cached graph') graph = pk.load(open('tmp/g.pk', 'rb')) else: print('Generating graph opt {}'.format(opt)) if 1 == opt: graph = gen_rand_graph(data_num=data_num) if 2 == opt: top_num = random.randint(1, data_num) bottom_num = data_num - top_num graph = nx.bipartite.random_graph(top_num, bottom_num, 0.9) label = [d['bipartite'] for n, d in graph.nodes(data=True)] elif 3 == opt: graph = nx.balanced_tree(4, 5) elif 4 == opt: graph = nx.complete_graph(data_num) elif 5 == opt: no1 = random.randint(1, data_num) no2 = random.randint(1, int(data_num / no1)) no3 = data_num / no1 / no2 graph = nx.complete_multipartite_graph(no1, no2, no3) elif 6 == opt: graph = nx.circular_ladder_graph(data_num) elif 7 == opt: graph = nx.cycle_graph(data_num) elif 8 == opt: graph = nx.dorogovtsev_goltsev_mendes_graph(5) elif 9 == opt: top_num = int(random.random() * data_num) bottom_num = data_num / top_num graph = nx.grid_2d_graph(top_num, bottom_num) elif 10 == opt: no1 = random.randint(1, data_num) no2 = random.randint(1, int(data_num / no1)) no3 = data_num / no1 / no2 graph = nx.grid_graph([no1, no2, no3]) elif 11 == opt: graph = nx.hypercube_graph(10) elif 12 == opt: graph = nx.ladder_graph(data_num) elif 13 == opt: top_num = int(random.random() * data_num) bottom_num = data_num - top_num graph = nx.lollipop_graph(top_num, bottom_num) elif 14 == opt: graph = nx.path_graph(data_num) elif 15 == opt: graph = nx.star_graph(data_num) elif 16 == opt: graph = nx.wheel_graph(data_num) elif 17 == opt: graph = nx.margulis_gabber_galil_graph(35) elif 18 == opt: graph = nx.chordal_cycle_graph(data_num) elif 19 == opt: graph = nx.fast_gnp_random_graph(data_num, random.random()) elif 20 == opt: # jump eigen value graph = nx.gnp_random_graph(data_num, random.random()) elif 21 == opt: # disconnected graph graph = nx.dense_gnm_random_graph(data_num, data_num / 2) elif 22 == opt: # disconnected graph graph = nx.gnm_random_graph(data_num, data_num / 2) elif 23 == opt: graph = nx.erdos_renyi_graph(data_num, data_num / 2) elif 24 == opt: graph = nx.binomial_graph(data_num, data_num / 2) elif 25 == opt: graph = nx.newman_watts_strogatz_graph(data_num, 5, random.random()) elif 26 == opt: graph = nx.watts_strogatz_graph(data_num, 5, random.random()) elif 26 == opt: # smooth eigen graph = nx.connected_watts_strogatz_graph(data_num, 5, random.random()) elif 27 == opt: # smooth eigen graph = nx.random_regular_graph(5, data_num) elif 28 == opt: # smooth eigen graph = nx.barabasi_albert_graph(data_num, 5) elif 29 == opt: # smooth eigen graph = nx.powerlaw_cluster_graph(data_num, 5, random.random()) elif 30 == opt: # smooth eigen graph = nx.duplication_divergence_graph(data_num, random.random()) elif 31 == opt: p = random.random() q = random.random() graph = nx.random_lobster(data_num, p, q) elif 32 == opt: p = random.random() q = random.random() k = random.random() graph = nx.random_shell_graph([(data_num / 3, 50, p), (data_num / 3, 40, q), (data_num / 3, 30, k)]) elif 33 == opt: # smooth eigen top_num = int(random.random() * data_num) bottom_num = data_num - top_num graph = nx.k_random_intersection_graph(top_num, bottom_num, 3) elif 34 == opt: graph = nx.random_geometric_graph(data_num, .1) elif 35 == opt: graph = nx.waxman_graph(data_num) elif 36 == opt: graph = nx.geographical_threshold_graph(data_num, .5) elif 37 == opt: top_num = int(random.random() * data_num) bottom_num = data_num - top_num graph = nx.uniform_random_intersection_graph( top_num, bottom_num, .5) elif 39 == opt: graph = nx.navigable_small_world_graph(data_num) elif 40 == opt: graph = nx.random_powerlaw_tree(data_num, tries=200) elif 41 == opt: graph = nx.karate_club_graph() elif 42 == opt: graph = nx.davis_southern_women_graph() elif 43 == opt: graph = nx.florentine_families_graph() elif 44 == opt: graph = nx.complete_multipartite_graph(data_num, data_num, data_num) # OPT 1 # norm_lap = nx.normalized_laplacian_matrix(graph).toarray() # OPT 2: renormalized # pk.dump(graph, open('tmp/g.pk', 'wb')) # plot_graph(graph, label) # note difference: normalized laplacian and normalzation by eigenvalue norm_lap, eigval, eigvec = normalize_lap(graph) return graph, norm_lap, eigval, eigvec
nx.draw(G, with_labels=True) fig.text(0.02, 0.15, "barbell graph", fontweight='bold') fig.text(0.02, 0.1, "two complete_graphs of " + str(n) + "(m1) nodes") fig.text(0.02, 0.05, "3(m2) nodes between them") plt.show() #binomial tree G = nx.binomial_tree(n) fig = plt.figure() nx.draw(G, with_labels=True) fig.text(0.02, 0.1, "binomial tree", fontweight='bold') fig.text(0.02, 0.05, "n(node count) = " + str(n)) plt.show() #complete multipartite graph G = nx.complete_multipartite_graph(1, 2, 3) fig = plt.figure() nx.draw(G, with_labels=True) fig.text(0.02, 0.1, "complete multipartite graph", fontweight='bold') fig.text(0.02, 0.05, "three subsets whose node counts are 1, 2, and 3") plt.show() #circular ladder graph G = nx.circular_ladder_graph(n) fig = plt.figure() nx.draw(G, with_labels=True) fig.text(0.02, 0.95, "circular ladder graph", fontweight='bold') fig.text(0.02, 0.90, "n(node count) = " + str(n)) plt.show() #circulant graph
import networkx as nx import copy import random import time Graph = nx.complete_multipartite_graph(30, 28, 29) #задание графа - генератор all_time = 0 all_edges = list(nx.generate_edgelist(Graph, data=False)) edges = [] for edge in all_edges: u, v = edge.split() edges.append([int(u), int(v)]) nodes = list(Graph.nodes) nx.draw(Graph, with_labels=True) start_time = time.time() def contract(nodes, edges): #алгоритм while len(nodes) > 2: ind = random.randrange(0, len(edges)) [u, v] = edges.pop(ind) nodes.remove(v) edge = [] for i in range(len(edges)): if edges[i][0] == v: edges[i][0] = u elif edges[i][1] == v: edges[i][1] = u if edges[i][0] != edges[i][1]:
def complete_bipartite_graph(n1, n2): return nx.complete_multipartite_graph(n1, n2)
def test_result_k_multipartite_5_5_5_5_5(self): assert (calc_and_compare( NX.complete_multipartite_graph([5, 5, 5, 5, 5])))
def calculate_complete_multipartite_graphs(sizes, boxes): for nb in range(2, boxes + 1): for p in itertools.combinations_with_replacement(sizes, nb): g = nx.complete_multipartite_graph(*p) yield g, p