-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathexample_random_generators_advanced.py
More file actions
49 lines (36 loc) · 1.47 KB
/
Copy pathexample_random_generators_advanced.py
File metadata and controls
49 lines (36 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Advanced random multilayer graph generators.
Demonstrates the multilayer Erdos-Renyi generator and highlights other
available generators (Barabasi-Albert, SBM variants). Prerequisites:
py3plex installed; no optional dependencies required.
"""
from __future__ import annotations
from py3plex.core.multinet import multi_layer_network
from py3plex.algorithms.advanced_random_generators import multilayer_erdos_renyi
DEFAULT_SEED = 42
def main() -> int:
"""Generate a multilayer ER graph and convert it to py3plex."""
print("=== Random Graph Generators Demo ===\n")
print("Generating multilayer Erdos-Renyi network...")
graph = multilayer_erdos_renyi(
n=20,
p=0.2,
num_layers=3,
interlayer_prob=0.1,
seed=DEFAULT_SEED,
)
print(f"\nGenerated multilayer ER network:")
print(f" Nodes: {graph.number_of_nodes()}")
print(f" Edges: {graph.number_of_edges()}")
net = multi_layer_network(network_type="multilayer", directed=False)
net.load_network(graph, input_type="nx")
print(f"\nConverted to py3plex network:")
print(f" {net}")
print("\nAvailable generators:")
print(" - multilayer_erdos_renyi: Random edges")
print(" - multilayer_barabasi_albert: Scale-free networks")
print(" - multilayer_stochastic_block_model: Community structure")
print(" - multilayer_sbm_with_dependencies: Layer-dependent communities\n")
return 0
if __name__ == "__main__":
raise SystemExit(main())