diff --git a/app/solver/__init__.py b/app/solver/__init__.py index 5193d53..c40d95c 100644 --- a/app/solver/__init__.py +++ b/app/solver/__init__.py @@ -7,9 +7,9 @@ import numpy as np from app._typing import NDArray -from ._wrap import matrix, spmatrix -from ._wrap.glpk import ilp -from ._wrap.glpk import set_global_options as set_glpk_options +from ._cvxopt_wrap import matrix, spmatrix +from ._cvxopt_wrap.glpk import ilp +from ._cvxopt_wrap.glpk import set_global_options as set_glpk_options set_glpk_options({"msg_lev": "GLP_MSG_ERR"}) @@ -139,19 +139,19 @@ class _BIPSolver: @staticmethod def solution_mat_clusters(solution_mat: NDArray): - n = solution_mat.shape[0] + n: int = solution_mat.shape[0] labels = np.arange(1, n + 1) for i in range(n): for j in range(i + 1, n): if solution_mat[i, j] > 0: labels[j] = labels[i] - - clusters = defaultdict(list) + # a dictionary that with empty list as default value for non-existing keys + clusters: dict[int, list[int]] = defaultdict(list) for i, label in enumerate(labels): - clusters[label].append(i) + clusters[int(label)].append(i) return list(clusters.values()) - def solve(self, affinity_matrix, rtn_matrix=False): + def solve(self, affinity_matrix: NDArray, rtn_matrix=False): n_nodes = affinity_matrix.shape[0] if n_nodes <= 1: solution_x, sol_matrix = ( diff --git a/app/solver/_wrap/__init__.py b/app/solver/_cvxopt_wrap/__init__.py similarity index 100% rename from app/solver/_wrap/__init__.py rename to app/solver/_cvxopt_wrap/__init__.py diff --git a/app/solver/_wrap/glpk.py b/app/solver/_cvxopt_wrap/glpk.py similarity index 100% rename from app/solver/_wrap/glpk.py rename to app/solver/_cvxopt_wrap/glpk.py