[docs]defrandom_hypergraph(num_nodes:int,size_distr:dict,node_attrs:dict=None,seed=None)->ASH:""" Generates a random hypergraph with the specified number of nodes and size distribution. :param num_nodes: The number of nodes in the hypergraph. :param size_distr: A dictionary where keys are hyperedge sizes and values are their probabilities. :param seed: Optional seed for random number generation. :return: An ASH object representing the generated hypergraph. """ifseedisnotNone:random.seed(seed)h=ASH()foriinrange(num_nodes):profile=NProfile(node_id=i,**({attr:random.choice(values)forattr,valuesinnode_attrs.items()}ifnode_attrselse{}))h.add_node(i,start=0,end=0,attr_dict=profile)forsize,countinsize_distr.items():for_inrange(count):# Randomly select nodes for the hyperedgenodes=random.sample(range(num_nodes),size)h.add_hyperedge(nodes,start=0,end=0)# Optionally, add node attributesifnode_attrs:foriinrange(num_nodes):profile=NProfile(id=i,**{attr:random.choice(values)forattr,valuesinnode_attrs.items()})returnh
[docs]defrandom_ash(num_nodes:int,size_distr:dict,time_steps:int,node_attrs:dict=None,seed=None,)->ASH:""" Generates a random ASH (Attributed Simple Hypergraph) with the specified number of nodes, size distribution, and time steps. :param num_nodes: The number of nodes in the ASH. :param size_distr: A dictionary where keys are hyperedge sizes and values are their probabilities. :param time_steps: The number of time steps for the ASH. :param node_attrs: Optional dictionary of attribute-to-values :param seed: Optional seed for random number generation. :return: An ASH object representing the generated hypergraph. """ifseedisnotNone:random.seed(seed)G=ASH()# example node_attrs: {'color': ['red', 'blue', 'green'], 'age': [1, 2, 3]}# add nodesforiinrange(num_nodes):profile=NProfile(node_id=i,start=0,end=time_steps-1,**({attr:random.choice(values)forattr,valuesinnode_attrs.items()}ifnode_attrselse{}))G.add_node(i,start=0,end=time_steps-1,attr_dict=profile)forsize,countinsize_distr.items():for_inrange(count):# Randomly select nodes for the hyperedgenodes=random.sample(range(num_nodes),size)# Add the hyperedge to the ASHG.add_hyperedge(nodes,start=0,end=time_steps-1)returnG