in src/qbsolv_community.py [0:0]
def create_qubo_dict(nx_G, k, alpha=5):
"""
Create a QUBO matrix in dict format for community detection
:param nx_G: networkX graph
:param k: int, number of communities to detect
:param alpha: int, constraint coefficient to force a solution with one node for one community assignment only
:return: QUBO sparse matrix in dict format
"""
qubo_matrix_sparse = qubo_matrix_community_sparse(nx_G, k, alpha=alpha)
indices = list(zip(qubo_matrix_sparse.row, qubo_matrix_sparse.col))
values = qubo_matrix_sparse.data
qubo_sparse = defaultdict(int)
for idx, val in zip(indices, values):
qubo_sparse[idx] = val
print(f"The size of the QUBO matrix in dictionary format for {k}-community is {len(qubo_sparse)}")
return qubo_sparse