import pandas as pd
import numpy as np
nodes = range(1, 21)
group1 = range(1, 11)
group2 = range(11, 20)
bridge = 20
leaders_group1 = [2, 5]
leaders_group2 = [15]
edges = []
for group in [group1, group2]:
for i in group:
for j in group:
if i < j and np.random.rand() < 0.7:
weight = np.random.uniform(0.3, 1.5) \
if i not in leaders_group1 + leaders_group2 and j not in leaders_group1 + leaders_group2 \
else np.random.uniform(0.3, 3.0)
edges.append((i, j, weight))
group1_members = np.random.choice(group1, size=int(0.3 * len(group1)), replace=False)
group2_members = np.random.choice(group2, size=int(0.3 * len(group2)), replace=False)
for i in group1_members:
for j in group2_members:
edges.append((i, j, np.random.uniform(0.3, 1)))
for leader in leaders_group1 + leaders_group2:
edges.append((bridge, leader, np.random.uniform(5, 8)))
for group in [group1, group2]:
members = np.random.choice(list(set(group) - set(leaders_group1 + leaders_group2)),
size=int(0.4 * len(group)), replace=False)
for member in members:
edges.append((bridge, member, np.random.uniform(0.5, 2)))
edges_df = pd.DataFrame(edges, columns=['Source', 'Target', 'Weight'])