def generic_hypergraph(number_of_nodes, edges_params, has_to_be_connected=True): nodes = range(1, number_of_nodes + 1) connected = False hypergraph = None while not connected and has_to_be_connected: hyper_edges = [] for cardinality, count in edges_params: edges_subset = random_combinations(nodes, cardinality, count) hyper_edges += edges_subset hypergraph = HyperGraph() hypergraph.add_nodes_from(nodes) hypergraph.add_edges_from(hyper_edges) connected = is_connected(hypergraph) return hypergraph
def uniform_hypergraph(n=6, number_of_edges=None, k=3, has_to_be_connected=True): """Generate hypergraph with constant cardinality of edges. :n - number of nodes, :number_of_edges - how many hyper edges will be created, :k - cardinality of hyper edges. """ nodes = range(1, n + 1) if number_of_edges is None: number_of_edges = int(math.sqrt(n)) connected = False hypergraph = None while not connected and has_to_be_connected: hyper_edges = random_combinations(nodes, k, number_of_edges) hypergraph = HyperGraph() hypergraph.add_nodes_from(nodes) hypergraph.add_edges_from(hyper_edges) connected = is_connected(hypergraph) return hypergraph