put-asunder 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {put_asunder-0.2.2 → put_asunder-0.2.4}/PKG-INFO +10 -3
- {put_asunder-0.2.2 → put_asunder-0.2.4}/README.md +9 -2
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/__init__.py +1 -1
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/algorithms/RCCS.py +1 -1
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/algorithms/community.py +124 -55
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/column_generation/decomposition.py +9 -14
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/column_generation/subproblem.py +16 -39
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/config.py +8 -9
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/load_balancing/column_generation/LB.py +13 -7
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/nlbnp/case_studies/runner.py +13 -5
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/nlbnp/workflow.py +24 -4
- {put_asunder-0.2.2 → put_asunder-0.2.4}/put_asunder.egg-info/PKG-INFO +10 -3
- {put_asunder-0.2.2 → put_asunder-0.2.4}/pyproject.toml +1 -1
- {put_asunder-0.2.2 → put_asunder-0.2.4}/LICENSE +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/algorithms/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/algorithms/core_periphery.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/algorithms/louvain_modified.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/algorithms/modular_VFD.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/algorithms/signed_louvain/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/algorithms/signed_louvain/community_detection.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/algorithms/signed_louvain/util.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/algorithms/spectral.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/branch_and_price/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/branch_and_price/branching_tree.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/branch_and_price/symmetry_detection.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/column_generation/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/column_generation/master.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/evaluation/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/evaluation/metrics.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/legacy/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/legacy/notebook_compat.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/utils/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/utils/graph.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/utils/partition_generation.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/visualization/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/visualization/graphs.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/base/visualization/matrices.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/load_balancing/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/load_balancing/algorithms/VFD.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/load_balancing/algorithms/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/load_balancing/column_generation/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/load_balancing/column_generation/master.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/load_balancing/utils/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/load_balancing/utils/partition_generation.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/nlbnp/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/nlbnp/algorithms/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/nlbnp/algorithms/core_periphery.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/nlbnp/algorithms/refinement.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/nlbnp/case_studies/__init__.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/nlbnp/case_studies/circle_cutting.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/nlbnp/case_studies/cpcong.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/orchestrator.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/solvers.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/types.py +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/put_asunder.egg-info/SOURCES.txt +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/put_asunder.egg-info/dependency_links.txt +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/put_asunder.egg-info/requires.txt +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/put_asunder.egg-info/top_level.txt +0 -0
- {put_asunder-0.2.2 → put_asunder-0.2.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: put-asunder
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Asunder: Constrained Network Structure Detection on Undirected Graphs.
|
|
5
5
|
Author-email: Allman Group <allmanaa@umich.edu>, Fortune Adekogbe <fortunea@umich.edu>
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -65,13 +65,20 @@ Base install:
|
|
|
65
65
|
python3 -m pip install put-asunder
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
Graph extras (supports ``leidenalg`` and ``igraph`` algorithms):
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
python3 -m pip install "put-asunder[graph]"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
Graph and visualization (``matplotlib`` and ``seaborn``) extras:
|
|
69
76
|
|
|
70
77
|
```bash
|
|
71
78
|
python3 -m pip install "put-asunder[graph,viz]"
|
|
72
79
|
```
|
|
73
80
|
|
|
74
|
-
Legacy heuristics (best-effort on Python 3.13 and 3.14):
|
|
81
|
+
Legacy core periphery heuristics (best-effort on Python 3.13 and 3.14):
|
|
75
82
|
|
|
76
83
|
```bash
|
|
77
84
|
python3 -m pip install "put-asunder[legacy]"
|
|
@@ -16,13 +16,20 @@ Base install:
|
|
|
16
16
|
python3 -m pip install put-asunder
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Graph extras (supports ``leidenalg`` and ``igraph`` algorithms):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
python3 -m pip install "put-asunder[graph]"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Graph and visualization (``matplotlib`` and ``seaborn``) extras:
|
|
20
27
|
|
|
21
28
|
```bash
|
|
22
29
|
python3 -m pip install "put-asunder[graph,viz]"
|
|
23
30
|
```
|
|
24
31
|
|
|
25
|
-
Legacy heuristics (best-effort on Python 3.13 and 3.14):
|
|
32
|
+
Legacy core periphery heuristics (best-effort on Python 3.13 and 3.14):
|
|
26
33
|
|
|
27
34
|
```bash
|
|
28
35
|
python3 -m pip install "put-asunder[legacy]"
|
|
@@ -7,7 +7,7 @@ from asunder.orchestrator import CSDDecomposition, run_csd_decomposition
|
|
|
7
7
|
from asunder.solvers import create_solver
|
|
8
8
|
from asunder.types import DecompositionResult, IterationRecord
|
|
9
9
|
|
|
10
|
-
__version__ = "0.2.
|
|
10
|
+
__version__ = "0.2.4"
|
|
11
11
|
|
|
12
12
|
def run_evaluation(*args, **kwargs):
|
|
13
13
|
"""
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Reduced Cost Community Search: A greedy and local search heuristic for finding
|
|
1
|
+
"""Reduced Cost Community Search: A greedy and local search heuristic for finding communities that maximize the reduced cost."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -10,7 +10,6 @@ from scipy import sparse
|
|
|
10
10
|
|
|
11
11
|
from asunder.base.algorithms.signed_louvain import community_detection as cd
|
|
12
12
|
from asunder.base.algorithms.signed_louvain import util as slouvain_util
|
|
13
|
-
from asunder.base.utils.graph import group_nodes_by_community
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
def _import_sknetwork():
|
|
@@ -179,7 +178,7 @@ def best_girvan_newman_partition(G, max_levels=10):
|
|
|
179
178
|
return best_communities, best_mod
|
|
180
179
|
|
|
181
180
|
|
|
182
|
-
def run_modularity(modified_A, algo="louvain", package="networkx", seed=42, resolution=1, verbose=False
|
|
181
|
+
def run_modularity(modified_A, algo="louvain", package="networkx", seed=42, resolution=1, verbose=False):
|
|
183
182
|
"""
|
|
184
183
|
Run modularity-style community detection and return ``(partition, score)``.
|
|
185
184
|
|
|
@@ -198,24 +197,20 @@ def run_modularity(modified_A, algo="louvain", package="networkx", seed=42, reso
|
|
|
198
197
|
Resolution parameter (gamma) used in modularity based methods.
|
|
199
198
|
verbose : bool
|
|
200
199
|
Controls the verbosity of the output. Default is False.
|
|
201
|
-
|
|
202
|
-
Enables/disables refinement procedure.
|
|
203
|
-
refine_params : dict[str, Any]
|
|
204
|
-
Refinement parameters, typically including the refinement function and any associated arguments.
|
|
205
|
-
|
|
200
|
+
|
|
206
201
|
Returns
|
|
207
202
|
-------
|
|
208
203
|
zii: ndarray of int, shape (N, N)
|
|
209
|
-
2D graph
|
|
204
|
+
2D graph partition.
|
|
210
205
|
metric: float
|
|
211
206
|
Modularity score of ``zii`` computed using the provided adjacency / weight matrix.
|
|
212
207
|
"""
|
|
213
|
-
assert modified_A.min() >= 0, "Adjacency / weight matrix includes negative values." #
|
|
208
|
+
assert modified_A.min() >= 0, "Adjacency / weight matrix includes negative values." # TODO: may need to drop this.
|
|
214
209
|
assert algo in ["louvain", "leiden", "greedy", "girvan_newman"]
|
|
215
210
|
modG = nx.from_numpy_array(modified_A.astype([("weight", "float")]))
|
|
216
211
|
metric = None
|
|
217
212
|
|
|
218
|
-
if package
|
|
213
|
+
if package == "igraph":
|
|
219
214
|
ig = _import_igraph()
|
|
220
215
|
ig_graph = ig.Graph.Weighted_Adjacency(modified_A.tolist(), mode="UNDIRECTED", attr="weight")
|
|
221
216
|
else:
|
|
@@ -234,28 +229,7 @@ def run_modularity(modified_A, algo="louvain", package="networkx", seed=42, reso
|
|
|
234
229
|
else:
|
|
235
230
|
raise NotImplementedError(f"Invalid package: {package}")
|
|
236
231
|
elif algo == "leiden":
|
|
237
|
-
if package == "
|
|
238
|
-
la = _import_leidenalg()
|
|
239
|
-
partition = la.find_partition(
|
|
240
|
-
ig_graph, la.ModularityVertexPartition, seed=seed, weights="weight"
|
|
241
|
-
)
|
|
242
|
-
resolution = None
|
|
243
|
-
# TODO: Add CPMVertexPartition which handles positive and negative weights and has resolution parameter.
|
|
244
|
-
# TODO:Test negative weight handling
|
|
245
|
-
# g_pos = ig_graph.subgraph_edges(ig_graph.es.select(weight_gt=0), delete_vertices=False)
|
|
246
|
-
# g_neg = ig_graph.subgraph_edges(ig_graph.es.select(weight_lt=0), delete_vertices=False)
|
|
247
|
-
# g_neg.es['weight'] = [-w for w in g_neg.es['weight']]
|
|
248
|
-
# part_pos = la.ModularityVertexPartition(g_pos, weights='weight')
|
|
249
|
-
# part_neg = la.ModularityVertexPartition(g_neg, weights='weight')
|
|
250
|
-
|
|
251
|
-
# optimiser = la.Optimiser()
|
|
252
|
-
# diff = optimiser.optimise_partition_multiplex([part_pos, part_neg], layer_weights=[1, -1])
|
|
253
|
-
# partition = part_pos
|
|
254
|
-
membership = {}
|
|
255
|
-
for node, comm in zip(ig_graph.vs.indices, partition.membership):
|
|
256
|
-
membership.setdefault(comm, []).append(node)
|
|
257
|
-
communities = list(membership.values())
|
|
258
|
-
elif package == "sknetwork":
|
|
232
|
+
if package == "sknetwork":
|
|
259
233
|
_, Leiden, _, _, _, _ = _import_sknetwork()
|
|
260
234
|
partition = Leiden(resolution=resolution).fit_predict(modified_A)
|
|
261
235
|
communities = {}
|
|
@@ -295,19 +269,12 @@ def run_modularity(modified_A, algo="louvain", package="networkx", seed=42, reso
|
|
|
295
269
|
for node in community:
|
|
296
270
|
oneD_z[node] = i
|
|
297
271
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
raise ValueError("refine_params is required when refine=True")
|
|
301
|
-
zii = refine_params["refine_func"](A=modified_A, partition=oneD_z, **refine_params["kwargs"])
|
|
302
|
-
_, communities = group_nodes_by_community(np.array(zii))
|
|
303
|
-
# TODO: Recompute metric or decide to leave as None.
|
|
304
|
-
else:
|
|
305
|
-
zii = np.equal.outer(oneD_z, oneD_z).astype(int)
|
|
306
|
-
metric = nx.community.modularity(modG, communities, resolution=resolution if resolution is not None else 1)
|
|
272
|
+
zii = np.equal.outer(oneD_z, oneD_z).astype(int)
|
|
273
|
+
metric = nx.community.modularity(modG, communities, resolution=resolution if resolution is not None else 1)
|
|
307
274
|
return zii, metric
|
|
308
275
|
|
|
309
276
|
|
|
310
|
-
def run_lpa(modified_A
|
|
277
|
+
def run_lpa(modified_A):
|
|
311
278
|
"""
|
|
312
279
|
Run label propagation clustering and return ``(partition, modularity)``.
|
|
313
280
|
|
|
@@ -316,25 +283,17 @@ def run_lpa(modified_A, refine=True):
|
|
|
316
283
|
modified_A : ndarray of float, shape (N, N)
|
|
317
284
|
Augmented adjacency / weight matrix reflecting the original adjacency / weight matrix with dual-modified weights. Negative weights are not allowed.
|
|
318
285
|
The original adjacency / weight matrix can also be parsed.
|
|
319
|
-
refine : bool
|
|
320
|
-
Enables/disables refinement procedure.
|
|
321
286
|
|
|
322
287
|
Returns
|
|
323
288
|
-------
|
|
324
289
|
zii: ndarray of int, shape (N, N)
|
|
325
|
-
2D graph
|
|
290
|
+
2D graph partition.
|
|
326
291
|
float
|
|
327
292
|
Modularity score of ``zii`` computed using the provided adjacency / weight matrix.
|
|
328
293
|
"""
|
|
329
294
|
_, _, PropagationClustering, get_modularity, _, _ = _import_sknetwork()
|
|
330
295
|
algorithm = PropagationClustering()
|
|
331
|
-
|
|
332
|
-
result = algorithm.fit_predict_proba(modified_A)
|
|
333
|
-
partition = np.zeros(shape=(result.shape[0],))
|
|
334
|
-
for i in range(result.shape[0]):
|
|
335
|
-
partition[i] = -1 if np.max(result[i]) < 0.8 else np.argmax(result[i])
|
|
336
|
-
else:
|
|
337
|
-
partition = algorithm.fit_predict(modified_A)
|
|
296
|
+
partition = algorithm.fit_predict(modified_A)
|
|
338
297
|
|
|
339
298
|
communities = {}
|
|
340
299
|
for i, val in enumerate(partition):
|
|
@@ -360,7 +319,7 @@ def run_igraph_spinglass(modified_A):
|
|
|
360
319
|
Returns
|
|
361
320
|
-------
|
|
362
321
|
ndarray of int, shape (N, N)
|
|
363
|
-
2D graph
|
|
322
|
+
2D graph partition.
|
|
364
323
|
"""
|
|
365
324
|
ig = _import_igraph()
|
|
366
325
|
ig_graph = ig.Graph.Weighted_Adjacency(modified_A.tolist(), mode="UNDIRECTED", attr="weight")
|
|
@@ -388,7 +347,7 @@ def run_igraph(modified_A, algo="infomap", resolution=1):
|
|
|
388
347
|
Returns
|
|
389
348
|
-------
|
|
390
349
|
zii: ndarray of int, shape (N, N)
|
|
391
|
-
2D graph
|
|
350
|
+
2D graph partition.
|
|
392
351
|
metric: float
|
|
393
352
|
Modularity score of ``zii`` computed using the provided adjacency / weight matrix.
|
|
394
353
|
"""
|
|
@@ -404,6 +363,9 @@ def run_igraph(modified_A, algo="infomap", resolution=1):
|
|
|
404
363
|
clustering = ig_graph.community_voronoi(weights="weight")
|
|
405
364
|
elif algo == "walktrap":
|
|
406
365
|
clustering = ig_graph.community_walktrap(weights="weight").as_clustering()
|
|
366
|
+
elif algo == "cpm_leiden":
|
|
367
|
+
# Resolution-limit free and handles negative weights
|
|
368
|
+
clustering = ig_graph.community_leiden(objective_function="CPM", weights='weight', resolution=resolution)
|
|
407
369
|
else:
|
|
408
370
|
raise NotImplementedError("Invalid Igraph Algorithm")
|
|
409
371
|
oneD_z = clustering.membership
|
|
@@ -411,6 +373,113 @@ def run_igraph(modified_A, algo="infomap", resolution=1):
|
|
|
411
373
|
metric = ig_graph.modularity(clustering, weights="weight", resolution=resolution if algo == "multilevel" else 1)
|
|
412
374
|
return zii, metric
|
|
413
375
|
|
|
376
|
+
def run_leidenalg(modified_A, algo='leiden', seed=42, resolution=1, verbose=False):
|
|
377
|
+
"""
|
|
378
|
+
Run Leiden algorithm to optimize varying quality functions and return ``(partition, score)``.
|
|
379
|
+
|
|
380
|
+
Parameters
|
|
381
|
+
----------
|
|
382
|
+
modified_A : ndarray of float, shape (N, N)
|
|
383
|
+
Augmented adjacency / weight matrix reflecting the original adjacency / weight matrix with dual-modified weights.
|
|
384
|
+
The original adjacency / weight matrix can also be parsed.
|
|
385
|
+
algo : str
|
|
386
|
+
Algorithm to be used for community detection. It describes the quality being maximized and whether signed graphs are allowed or not.
|
|
387
|
+
seed : int | None
|
|
388
|
+
Random seed value.
|
|
389
|
+
resolution : int or float
|
|
390
|
+
Resolution parameter (gamma) used.
|
|
391
|
+
verbose : bool
|
|
392
|
+
Controls the verbosity of the output. Default is False.
|
|
393
|
+
|
|
394
|
+
Returns
|
|
395
|
+
-------
|
|
396
|
+
zii: ndarray of int, shape (N, N)
|
|
397
|
+
2D graph partition.
|
|
398
|
+
metric: float
|
|
399
|
+
Quality of ``zii`` computed using the provided adjacency / weight matrix. This could be modularity, CPM or surprise.
|
|
400
|
+
"""
|
|
401
|
+
assert algo in ['leiden', 'signed_leiden', 'cpm_leiden', 'surprise_leiden', 'signed_surprise_leiden']
|
|
402
|
+
la = _import_leidenalg()
|
|
403
|
+
ig = _import_igraph()
|
|
404
|
+
# create modified graph
|
|
405
|
+
ig_graph = ig.Graph.Weighted_Adjacency(modified_A.tolist(), mode='UNDIRECTED', attr='weight')
|
|
406
|
+
|
|
407
|
+
metric = None
|
|
408
|
+
if algo == "leiden":
|
|
409
|
+
partition = la.find_partition(
|
|
410
|
+
ig_graph,
|
|
411
|
+
la.RBConfigurationVertexPartition,
|
|
412
|
+
resolution_parameter=resolution,
|
|
413
|
+
seed=seed,
|
|
414
|
+
weights='weight'
|
|
415
|
+
)
|
|
416
|
+
metric = partition.quality() / modified_A.sum()
|
|
417
|
+
elif algo == "signed_leiden":
|
|
418
|
+
# uses multiplex community detection to handle negative weights
|
|
419
|
+
g_pos = ig_graph.subgraph_edges(ig_graph.es.select(weight_gt=0), delete_vertices=False)
|
|
420
|
+
g_neg = ig_graph.subgraph_edges(ig_graph.es.select(weight_lt=0), delete_vertices=False)
|
|
421
|
+
g_neg.es['weight'] = [-w for w in g_neg.es['weight']]
|
|
422
|
+
|
|
423
|
+
layer_partitions = la.find_partition_multiplex(
|
|
424
|
+
graphs=[g_pos, g_neg],
|
|
425
|
+
partition_type=la.RBConfigurationVertexPartition,
|
|
426
|
+
layer_weights=[1, -1],
|
|
427
|
+
weights='weight',
|
|
428
|
+
resolution_parameter=resolution,
|
|
429
|
+
seed=seed
|
|
430
|
+
)
|
|
431
|
+
partition = layer_partitions[0]
|
|
432
|
+
|
|
433
|
+
part_pos = la.RBConfigurationVertexPartition(g_pos, weights='weight', initial_membership=layer_partitions[0], resolution_parameter=resolution)
|
|
434
|
+
part_neg = la.RBConfigurationVertexPartition(g_neg, weights='weight', initial_membership=layer_partitions[0], resolution_parameter=resolution)
|
|
435
|
+
m_pos = sum(g_pos.es['weight'])
|
|
436
|
+
m_neg = sum(g_neg.es['weight'])
|
|
437
|
+
metric = (1 * part_pos.quality() / m_pos) + (-1 * part_neg.quality() / m_neg)
|
|
438
|
+
elif algo == "cpm_leiden":
|
|
439
|
+
# Constant Potts Model (CPM). Resolution-limit free and handles negative weights.
|
|
440
|
+
partition = la.find_partition(
|
|
441
|
+
ig_graph,
|
|
442
|
+
la.CPMVertexPartition,
|
|
443
|
+
resolution_parameter=resolution,
|
|
444
|
+
seed=seed,
|
|
445
|
+
weights='weight'
|
|
446
|
+
)
|
|
447
|
+
metric = partition.quality()
|
|
448
|
+
elif algo == "surprise_leiden":
|
|
449
|
+
partition = la.find_partition(
|
|
450
|
+
ig_graph,
|
|
451
|
+
la.SurpriseVertexPartition,
|
|
452
|
+
seed=seed,
|
|
453
|
+
weights='weight'
|
|
454
|
+
)
|
|
455
|
+
metric = partition.quality()
|
|
456
|
+
elif algo == "signed_surprise_leiden":
|
|
457
|
+
# uses multiplex community detection to handle negative weights
|
|
458
|
+
g_pos = ig_graph.subgraph_edges(ig_graph.es.select(weight_gt=0), delete_vertices=False)
|
|
459
|
+
g_neg = ig_graph.subgraph_edges(ig_graph.es.select(weight_lt=0), delete_vertices=False)
|
|
460
|
+
g_neg.es['weight'] = [-w for w in g_neg.es['weight']]
|
|
461
|
+
|
|
462
|
+
layer_partitions = la.find_partition_multiplex(
|
|
463
|
+
graphs=[g_pos, g_neg],
|
|
464
|
+
partition_type=la.SurpriseVertexPartition,
|
|
465
|
+
layer_weights=[1, -1],
|
|
466
|
+
weights='weight',
|
|
467
|
+
seed=seed
|
|
468
|
+
)
|
|
469
|
+
part_pos = la.SurpriseVertexPartition(g_pos, weights='weight', initial_membership=layer_partitions[0])
|
|
470
|
+
part_neg = la.SurpriseVertexPartition(g_neg, weights='weight', initial_membership=layer_partitions[0])
|
|
471
|
+
partition = layer_partitions[0]
|
|
472
|
+
metric = (1 * part_pos.quality()) + (-1 * part_neg.quality())
|
|
473
|
+
else:
|
|
474
|
+
raise(NotImplementedError("Invalid Leidenalg Algorithm."))
|
|
475
|
+
|
|
476
|
+
# process result to get partitions
|
|
477
|
+
oneD_z = np.array(
|
|
478
|
+
partition if algo.startswith("signed") else partition.membership
|
|
479
|
+
)
|
|
480
|
+
zii = np.equal.outer(oneD_z, oneD_z).astype(int)
|
|
481
|
+
return zii, metric
|
|
482
|
+
|
|
414
483
|
|
|
415
484
|
def run_signed_louvain(modified_A, seed=42):
|
|
416
485
|
"""
|
|
@@ -427,7 +496,7 @@ def run_signed_louvain(modified_A, seed=42):
|
|
|
427
496
|
Returns
|
|
428
497
|
-------
|
|
429
498
|
zii: ndarray of int, shape (N, N)
|
|
430
|
-
2D graph
|
|
499
|
+
2D graph partition.
|
|
431
500
|
float
|
|
432
501
|
Modularity score of ``zii`` computed using the provided adjacency / weight matrix.
|
|
433
502
|
"""
|
|
@@ -33,7 +33,6 @@ def CSD_decomposition(
|
|
|
33
33
|
# initial feasible column generator
|
|
34
34
|
ifc_params: dict = {},
|
|
35
35
|
# refinement
|
|
36
|
-
refine_in_subproblem=False,
|
|
37
36
|
refine_params: dict={},
|
|
38
37
|
use_refined_column=False,
|
|
39
38
|
refine_post_loop=True,
|
|
@@ -70,11 +69,11 @@ def CSD_decomposition(
|
|
|
70
69
|
contract_graph : bool
|
|
71
70
|
Boolean that determines whether must links are handled via graph contraction or not.
|
|
72
71
|
stopping_window : int
|
|
73
|
-
Maximum number of allowed
|
|
72
|
+
Maximum number of allowed stagnant CG iterations. After this, CG is terminated.
|
|
74
73
|
check_flat_pricing : bool
|
|
75
74
|
Boolean that determines whether to check for flat/stagnant pricing or not.
|
|
76
75
|
algo : str
|
|
77
|
-
Name of heuristic subproblem used to replace the ILP subproblem. Third-party algorithms combine adjacency and dual information
|
|
76
|
+
Name of heuristic subproblem used to replace the ILP subproblem. Third-party algorithms combine adjacency and dual information into a unified input while custom algorithms treat adjacency and duals as separate inputs. Supported third-party algorithms are listed under the ``package`` parameter.
|
|
78
77
|
Available custom algorithm options include:
|
|
79
78
|
|
|
80
79
|
``"spectral"``:
|
|
@@ -82,7 +81,7 @@ def CSD_decomposition(
|
|
|
82
81
|
``"full_louvain"``:
|
|
83
82
|
Modified but Louvain-like algorithm.
|
|
84
83
|
``"RCCS"``:
|
|
85
|
-
This means Reduced Cost Community Search and is a greedy and local search heuristic for finding
|
|
84
|
+
This means Reduced Cost Community Search and is a greedy and local search heuristic for finding communities that maximize the reduced cost.
|
|
86
85
|
package : str or None
|
|
87
86
|
Package from which non-custom heuristic subproblem is selected. Package and algorithm options include:
|
|
88
87
|
|
|
@@ -91,19 +90,19 @@ def CSD_decomposition(
|
|
|
91
90
|
``"sknetwork"``:
|
|
92
91
|
``"louvain"``, ``"leiden"``, ``"lpa"``
|
|
93
92
|
``"igraph"``:
|
|
94
|
-
``"leiden"``, ``"greedy"``, ``"infomap"``, ``"lpa"``, ``"multilevel"``, ``"voronoi"``, ``"walktrap"``
|
|
95
|
-
``leidenalg``:
|
|
96
|
-
``"leiden"``
|
|
93
|
+
``"leiden"``, ``"greedy"``, ``"infomap"``, ``"lpa"``, ``"multilevel"``, ``"voronoi"``, ``"walktrap"``, ``"cpm_leiden"``
|
|
94
|
+
``"leidenalg"``:
|
|
95
|
+
``"leiden"``, ``"signed_leiden"``, ``"cpm_leiden"``, ``"surprise_leiden"``, ``"signed_surprise_leiden"``
|
|
97
96
|
``None``:
|
|
98
97
|
``"signed_louvain"``, ``"spinglass"``
|
|
98
|
+
|
|
99
|
+
Algorithms that start with ``"cpm"``, ``"signed"``, and ``"spinglass"`` are signed.
|
|
99
100
|
seed : int or None
|
|
100
101
|
Random seed value.
|
|
101
102
|
extract_dual : bool
|
|
102
103
|
Boolean that determines whether we extract duals from the master problem or not.
|
|
103
104
|
ifc_params : dict[str, callable or dict or int]
|
|
104
105
|
Number of initial feasible columns (ifc), initial feasible column generator, and its corresponding arguments (excluding seed values).
|
|
105
|
-
refine_in_subproblem : bool
|
|
106
|
-
Boolean value that determines whether a refinement operation is run in the subproblem.
|
|
107
106
|
refine_params : dict[str, callable or dict]
|
|
108
107
|
Refinement function and its corresponding arguments (excluding seed values).
|
|
109
108
|
use_refined_column : bool
|
|
@@ -225,12 +224,10 @@ def CSD_decomposition(
|
|
|
225
224
|
A, a, m, duals, verbose=verbose
|
|
226
225
|
)
|
|
227
226
|
else:
|
|
228
|
-
if algo in {"spectral", "full_louvain", "
|
|
227
|
+
if algo in {"spectral", "full_louvain", "RCCS"}:
|
|
229
228
|
# uses custom heuristic subproblem
|
|
230
229
|
sub_obj_val, z_sol = sp_function(
|
|
231
230
|
A, a, m, duals, algo=algo,
|
|
232
|
-
refine=refine_in_subproblem,
|
|
233
|
-
refine_params=refine_params,
|
|
234
231
|
verbose=verbose,
|
|
235
232
|
seed=seed
|
|
236
233
|
)
|
|
@@ -239,8 +236,6 @@ def CSD_decomposition(
|
|
|
239
236
|
sub_obj_val, z_sol = sp_function(
|
|
240
237
|
A, a, m, duals,
|
|
241
238
|
algo=algo, package=package,
|
|
242
|
-
refine=refine_in_subproblem,
|
|
243
|
-
refine_params=refine_params,
|
|
244
239
|
verbose=verbose,
|
|
245
240
|
seed=seed
|
|
246
241
|
)
|
|
@@ -5,9 +5,9 @@ from __future__ import annotations
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
|
|
7
7
|
from asunder.base.algorithms.community import (
|
|
8
|
-
probability_to_integer_labels,
|
|
9
8
|
run_igraph,
|
|
10
9
|
run_igraph_spinglass,
|
|
10
|
+
run_leidenalg,
|
|
11
11
|
run_lpa,
|
|
12
12
|
run_modularity,
|
|
13
13
|
run_signed_louvain,
|
|
@@ -43,8 +43,6 @@ def heuristic_subproblem(
|
|
|
43
43
|
duals,
|
|
44
44
|
algo="louvain",
|
|
45
45
|
package="networkx",
|
|
46
|
-
refine=False,
|
|
47
|
-
refine_params=None,
|
|
48
46
|
verbose=False,
|
|
49
47
|
gamma=1,
|
|
50
48
|
exact_rc=True,
|
|
@@ -68,10 +66,6 @@ def heuristic_subproblem(
|
|
|
68
66
|
Name of third-party heuristic subproblem used to replace the ILP subproblem.
|
|
69
67
|
package : str
|
|
70
68
|
Package from which third-party heuristic subproblem is selected. See ``CSD_decomposition`` for more detail.
|
|
71
|
-
refine : bool
|
|
72
|
-
Boolean value that determines whether a refinement operation is run in the subproblem.
|
|
73
|
-
refine_params : dict[str, callable or dict]
|
|
74
|
-
Refinement function and its corresponding arguments.
|
|
75
69
|
verbose : int or bool
|
|
76
70
|
Controls the level of detail in the printed output.
|
|
77
71
|
``-1``: No output
|
|
@@ -80,9 +74,9 @@ def heuristic_subproblem(
|
|
|
80
74
|
gamma : int
|
|
81
75
|
Resolution parameter which controls the scale and size of the detected clusters.
|
|
82
76
|
Should be left as default (``1``) if:
|
|
83
|
-
``algo`` is ``
|
|
84
|
-
``algo`` is ``greedy`` or ``multilevel`` and ``package`` is ``igraph``
|
|
85
|
-
``algo`` is ``girvan_newman`` and ``package`` is ``networkx``
|
|
77
|
+
``"algo"`` is ``"surprise_leiden"`` or ``"signed_surprise_leiden"`` and ``"package"`` is ``"leidenalg"``
|
|
78
|
+
``"algo"`` is ``"greedy"`` or ``"multilevel"`` and ``"package"`` is ``"igraph"``
|
|
79
|
+
``"algo"`` is ``"girvan_newman"`` and ``"package"`` is ``"networkx"``
|
|
86
80
|
seed : int or None
|
|
87
81
|
Random seed value
|
|
88
82
|
Returns
|
|
@@ -109,30 +103,28 @@ def heuristic_subproblem(
|
|
|
109
103
|
modA = A - (m * dualW)
|
|
110
104
|
mod_a = modA.sum(axis=0)
|
|
111
105
|
mod_m = np.sum(mod_a)
|
|
106
|
+
# negative weights will basically lead to a separation of nodes on that edge. The issue however
|
|
107
|
+
# is that when m or 2m becomes negative, modularity logic flips completely and tightly connected
|
|
108
|
+
# components are treated as bad splits.
|
|
112
109
|
modA_positive = modA.copy()
|
|
113
110
|
modA_positive[modA_positive < 0] = 0
|
|
114
111
|
|
|
115
|
-
if package == "igraph" and algo not in {"
|
|
116
|
-
zii, metric = run_igraph(modA, algo=algo, resolution=gamma)
|
|
112
|
+
if package == "igraph" and algo not in {"greedy", "leiden"}:
|
|
113
|
+
zii, metric = run_igraph(modA if algo == "cpm_leiden" else modA_positive, algo=algo, resolution=gamma)
|
|
114
|
+
elif package == "leidenalg":
|
|
115
|
+
zii, metric = run_leidenalg(modA if algo.startswith("signed") or algo == "cpm_leiden" else modA_positive, algo=algo, seed=seed, resolution=gamma, verbose=verbose)
|
|
117
116
|
elif algo == "spinglass":
|
|
118
117
|
zii = run_igraph_spinglass(modA)
|
|
119
118
|
metric = compute_f_star(modA, mod_a, mod_m, zii)
|
|
120
119
|
elif algo == "signed_louvain":
|
|
121
120
|
zii, metric = run_signed_louvain(modA, seed=seed)
|
|
122
|
-
elif algo == "lpa":
|
|
123
|
-
|
|
124
|
-
zii, metric = run_lpa(modA)
|
|
125
|
-
elif package == "igraph":
|
|
126
|
-
zii, metric = run_igraph(modA, algo=algo)
|
|
127
|
-
else:
|
|
128
|
-
raise NotImplementedError(f"Invalid package entered: {package}")
|
|
121
|
+
elif algo == "lpa" and package == "sknetwork":
|
|
122
|
+
zii, metric = run_lpa(modA_positive)
|
|
129
123
|
else:
|
|
130
124
|
zii, metric = run_modularity(
|
|
131
125
|
modA_positive,
|
|
132
126
|
algo=algo,
|
|
133
127
|
package=package,
|
|
134
|
-
refine=refine,
|
|
135
|
-
refine_params=refine_params,
|
|
136
128
|
resolution=gamma,
|
|
137
129
|
verbose=verbose,
|
|
138
130
|
seed=seed
|
|
@@ -261,8 +253,6 @@ def custom_heuristic_subproblem(
|
|
|
261
253
|
duals,
|
|
262
254
|
algo="full_louvain",
|
|
263
255
|
verbose=False,
|
|
264
|
-
refine=False,
|
|
265
|
-
refine_params=None,
|
|
266
256
|
max_iterations=50,
|
|
267
257
|
tolerance=1e-8,
|
|
268
258
|
seed=42
|
|
@@ -288,10 +278,6 @@ def custom_heuristic_subproblem(
|
|
|
288
278
|
``-1``: No output
|
|
289
279
|
``False`` | ``0``: Minimal output
|
|
290
280
|
``True`` | ``1``: Detailed output
|
|
291
|
-
refine : bool
|
|
292
|
-
Boolean value that determines whether a refinement operation is run in the subproblem.
|
|
293
|
-
refine_params : dict[str, callable or dict]
|
|
294
|
-
Refinement function and its corresponding arguments.
|
|
295
281
|
max_iterations : int
|
|
296
282
|
Maximum number of iterations.
|
|
297
283
|
tolerance : float
|
|
@@ -328,13 +314,8 @@ def custom_heuristic_subproblem(
|
|
|
328
314
|
louvain_model.fit(A, duals)
|
|
329
315
|
else:
|
|
330
316
|
louvain_model.fit_modified_one_level(A, duals, max_iter=max_iterations, tol=tolerance)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
z_sol = partition_vector_to_2d_matrix(ilabels)
|
|
334
|
-
metric = None
|
|
335
|
-
else:
|
|
336
|
-
z_sol = partition_vector_to_2d_matrix(louvain_model.labels_)
|
|
337
|
-
metric = louvain_model.obj_val_
|
|
317
|
+
z_sol = partition_vector_to_2d_matrix(louvain_model.labels_)
|
|
318
|
+
metric = louvain_model.obj_val_
|
|
338
319
|
else:
|
|
339
320
|
if algo == "RCCS":
|
|
340
321
|
res = search_partition_by_reduced_cost(adjacency=A, duals=duals, random_seed=seed)
|
|
@@ -343,11 +324,7 @@ def custom_heuristic_subproblem(
|
|
|
343
324
|
metric = res["best_reduced_cost"] + constant_terms # for normalization sake
|
|
344
325
|
else:
|
|
345
326
|
z_sol, metric = full_spectral_bisection(A, a, m, dualW, refinement=True, verbose=verbose)
|
|
346
|
-
|
|
347
|
-
z_refine = refine_params["refine_func"](A=A, partition=z_sol, **refine_params["kwargs"])
|
|
348
|
-
if z_refine is not None:
|
|
349
|
-
z_sol = z_refine
|
|
350
|
-
metric = None
|
|
327
|
+
|
|
351
328
|
if metric is None:
|
|
352
329
|
modularity_contribution = compute_f_star(A, a, m, z_sol)
|
|
353
330
|
dual_contribution = (dualW * z_sol).sum()
|
|
@@ -27,11 +27,11 @@ class CSDDecompositionConfig:
|
|
|
27
27
|
contract_graph : bool
|
|
28
28
|
Boolean that determines whether must links are handled via graph contraction or not.
|
|
29
29
|
stopping_window : int
|
|
30
|
-
Maximum number of allowed
|
|
30
|
+
Maximum number of allowed stagnant CG iterations. After this, CG is terminated.
|
|
31
31
|
check_flat_pricing : bool
|
|
32
32
|
Boolean that determines whether to check for flat/stagnant pricing or not.
|
|
33
33
|
algo : str
|
|
34
|
-
Name of heuristic subproblem used to replace the ILP subproblem. Third-party algorithms combine adjacency and dual information
|
|
34
|
+
Name of heuristic subproblem used to replace the ILP subproblem. Third-party algorithms combine adjacency and dual information into a unified input while custom algorithms treat adjacency and duals as separate inputs. Supported third-party algorithms are listed under the ``package`` parameter.
|
|
35
35
|
Available custom algorithm options include:
|
|
36
36
|
|
|
37
37
|
``"spectral"``:
|
|
@@ -39,7 +39,7 @@ class CSDDecompositionConfig:
|
|
|
39
39
|
``"full_louvain"``:
|
|
40
40
|
Modified but Louvain-like algorithm.
|
|
41
41
|
``"RCCS"``:
|
|
42
|
-
This means Reduced Cost Community Search and is a greedy and local search heuristic for finding
|
|
42
|
+
This means Reduced Cost Community Search and is a greedy and local search heuristic for finding communities that maximize the reduced cost.
|
|
43
43
|
package : str or None
|
|
44
44
|
Package from which non-custom heuristic subproblem is selected. Package and algorithm options include:
|
|
45
45
|
|
|
@@ -48,19 +48,19 @@ class CSDDecompositionConfig:
|
|
|
48
48
|
``"sknetwork"``:
|
|
49
49
|
``"louvain"``, ``"leiden"``, ``"lpa"``
|
|
50
50
|
``"igraph"``:
|
|
51
|
-
``"leiden"``, ``"greedy"``, ``"infomap"``, ``"lpa"``, ``"multilevel"``, ``"voronoi"``, ``"walktrap"``
|
|
52
|
-
``leidenalg``:
|
|
53
|
-
``"leiden"``
|
|
51
|
+
``"leiden"``, ``"greedy"``, ``"infomap"``, ``"lpa"``, ``"multilevel"``, ``"voronoi"``, ``"walktrap"``, ``"cpm_leiden"``
|
|
52
|
+
``"leidenalg"``:
|
|
53
|
+
``"leiden"``, ``"signed_leiden"``, ``"cpm_leiden"``, ``"surprise_leiden"``, ``"signed_surprise_leiden"``
|
|
54
54
|
``None``:
|
|
55
55
|
``"signed_louvain"``, ``"spinglass"``
|
|
56
|
+
|
|
57
|
+
Algorithms that start with ``"cpm"``, ``"signed"``, and ``"spinglass"`` are signed.
|
|
56
58
|
seed : int or None
|
|
57
59
|
Random seed value.
|
|
58
60
|
extract_dual : bool
|
|
59
61
|
Boolean that determines whether we extract duals from the master problem or not.
|
|
60
62
|
ifc_params : dict[str, callable or dict or int]
|
|
61
63
|
Number of initial feasible columns (ifc), initial feasible column generator, and its corresponding arguments.
|
|
62
|
-
refine_in_subproblem : bool
|
|
63
|
-
Boolean value that determines whether a refinement operation is run in the subproblem.
|
|
64
64
|
refine_params : dict[str, callable or dict]
|
|
65
65
|
Refinement function and its corresponding arguments.
|
|
66
66
|
use_refined_column : bool
|
|
@@ -95,7 +95,6 @@ class CSDDecompositionConfig:
|
|
|
95
95
|
seed: int | None = 42
|
|
96
96
|
extract_dual: bool = False
|
|
97
97
|
ifc_params: Dict[str, Any] = field(default_factory=dict)
|
|
98
|
-
refine_in_subproblem: bool = False
|
|
99
98
|
refine_params: Dict[str, Any] = field(default_factory=dict)
|
|
100
99
|
use_refined_column: bool = False
|
|
101
100
|
refine_post_loop: bool = True
|
|
@@ -4,7 +4,10 @@ import networkx as nx
|
|
|
4
4
|
import numpy as np
|
|
5
5
|
|
|
6
6
|
from asunder.base.column_generation.master import compute_f_star
|
|
7
|
-
from asunder.base.column_generation.subproblem import
|
|
7
|
+
from asunder.base.column_generation.subproblem import (
|
|
8
|
+
custom_heuristic_subproblem,
|
|
9
|
+
heuristic_subproblem,
|
|
10
|
+
)
|
|
8
11
|
from asunder.base.utils.graph import group_nodes_by_community, map_community_labels
|
|
9
12
|
from asunder.config import CSDDecompositionConfig
|
|
10
13
|
from asunder.load_balancing.algorithms.VFD import refine_partition
|
|
@@ -16,6 +19,7 @@ from asunder.load_balancing.utils.partition_generation import (
|
|
|
16
19
|
from asunder.orchestrator import run_csd_decomposition
|
|
17
20
|
from asunder.types import DecompositionResult
|
|
18
21
|
|
|
22
|
+
_CUSTOM_HEURISTIC_ALGOS = {"spectral", "full_louvain", "RCCS"}
|
|
19
23
|
|
|
20
24
|
def LoadBalancer(
|
|
21
25
|
G,
|
|
@@ -49,7 +53,7 @@ def LoadBalancer(
|
|
|
49
53
|
R_bounds : tuple[int, int] | None
|
|
50
54
|
Minimum and maximum number of nodes per community (community size constraint).
|
|
51
55
|
algo : str
|
|
52
|
-
Name of heuristic subproblem used to replace the ILP subproblem. Third-party algorithms combine adjacency and dual information
|
|
56
|
+
Name of heuristic subproblem used to replace the ILP subproblem. Third-party algorithms combine adjacency and dual information into a unified input while custom algorithms treat adjacency and duals as separate inputs. Supported third-party algorithms are listed under the ``package`` parameter.
|
|
53
57
|
Available custom algorithm options include:
|
|
54
58
|
|
|
55
59
|
``"spectral"``:
|
|
@@ -57,7 +61,7 @@ def LoadBalancer(
|
|
|
57
61
|
``"full_louvain"``:
|
|
58
62
|
Modified but Louvain-like algorithm.
|
|
59
63
|
``"RCCS"``:
|
|
60
|
-
This means Reduced Cost Community Search and is a greedy and local search heuristic for finding
|
|
64
|
+
This means Reduced Cost Community Search and is a greedy and local search heuristic for finding communities that maximize the reduced cost.
|
|
61
65
|
package : str or None
|
|
62
66
|
Package from which non-custom heuristic subproblem is selected. Package and algorithm options include:
|
|
63
67
|
|
|
@@ -66,11 +70,13 @@ def LoadBalancer(
|
|
|
66
70
|
``"sknetwork"``:
|
|
67
71
|
``"louvain"``, ``"leiden"``, ``"lpa"``
|
|
68
72
|
``"igraph"``:
|
|
69
|
-
``"leiden"``, ``"greedy"``, ``"infomap"``, ``"lpa"``, ``"multilevel"``, ``"voronoi"``, ``"walktrap"``
|
|
70
|
-
``leidenalg``:
|
|
71
|
-
``"leiden"``
|
|
73
|
+
``"leiden"``, ``"greedy"``, ``"infomap"``, ``"lpa"``, ``"multilevel"``, ``"voronoi"``, ``"walktrap"``, ``"cpm_leiden"``
|
|
74
|
+
``"leidenalg"``:
|
|
75
|
+
``"leiden"``, ``"signed_leiden"``, ``"cpm_leiden"``, ``"surprise_leiden"``, ``"signed_surprise_leiden"``
|
|
72
76
|
``None``:
|
|
73
77
|
``"signed_louvain"``, ``"spinglass"``
|
|
78
|
+
|
|
79
|
+
Algorithms that start with ``"cpm"``, ``"signed"``, and ``"spinglass"`` are signed.
|
|
74
80
|
ifc_generator : str
|
|
75
81
|
``"random"`` if the initial feasible column should be randomly generated (default).
|
|
76
82
|
``"ordered"`` if the initial feasible column should be generated with some structure-based ordering.
|
|
@@ -172,7 +178,7 @@ def LoadBalancer(
|
|
|
172
178
|
A, a=a, m=m,
|
|
173
179
|
config=config,
|
|
174
180
|
master_fn=solve_master_problem,
|
|
175
|
-
subproblem_fn=heuristic_subproblem,
|
|
181
|
+
subproblem_fn=custom_heuristic_subproblem if algorithm in _CUSTOM_HEURISTIC_ALGOS else heuristic_subproblem,
|
|
176
182
|
)
|
|
177
183
|
elapsed = time.perf_counter() - start
|
|
178
184
|
if result.final_partition is None:
|
|
@@ -30,8 +30,9 @@ from asunder.nlbnp.algorithms.refinement import refine_partition_linear_group
|
|
|
30
30
|
from asunder.nlbnp.case_studies.circle_cutting import build_circle_cutting_graph
|
|
31
31
|
from asunder.nlbnp.case_studies.cpcong import build_cpcong_graph
|
|
32
32
|
|
|
33
|
-
NX_ALGOS = ["louvain", "
|
|
34
|
-
IGRAPH_ALGOS = ["infomap", "lpa", "multilevel", "voronoi", "walktrap"]
|
|
33
|
+
NX_ALGOS = ["louvain", "greedy", "girvan_newman"]
|
|
34
|
+
IGRAPH_ALGOS = ["infomap", "lpa", "multilevel", "voronoi", "walktrap", "cpm_leiden"]
|
|
35
|
+
LEIDENALG_ALGOS = ['leiden', 'signed_leiden', 'cpm_leiden', 'surprise_leiden', 'signed_surprise_leiden']
|
|
35
36
|
|
|
36
37
|
|
|
37
38
|
def run_evaluation(problem="cpcong", build_params=None, style="CP", algos=None, repeat=3):
|
|
@@ -146,7 +147,15 @@ def run_evaluation(problem="cpcong", build_params=None, style="CP", algos=None,
|
|
|
146
147
|
if attr.get("var_type") == "integer"
|
|
147
148
|
]
|
|
148
149
|
for algo in algos:
|
|
149
|
-
|
|
150
|
+
# algorithms that occur in multiple packages are only selected once based on the block below.
|
|
151
|
+
if algo in NX_ALGOS:
|
|
152
|
+
package = "networkx" if algo in NX_ALGOS else ("igraph" if algo in IGRAPH_ALGOS else None)
|
|
153
|
+
elif algo in IGRAPH_ALGOS:
|
|
154
|
+
package = "igraph"
|
|
155
|
+
elif algo in LEIDENALG_ALGOS:
|
|
156
|
+
package = "leidenalg"
|
|
157
|
+
else:
|
|
158
|
+
package = None
|
|
150
159
|
ifc_params = {"generator": make_simple_partition, "num": 1, "args": {"N": n}}
|
|
151
160
|
refine_params = {
|
|
152
161
|
"refine_func": refine_partition_linear_group,
|
|
@@ -159,13 +168,12 @@ def run_evaluation(problem="cpcong", build_params=None, style="CP", algos=None,
|
|
|
159
168
|
a,
|
|
160
169
|
m,
|
|
161
170
|
solve_master_problem,
|
|
162
|
-
custom_heuristic_subproblem if algo in ["full_louvain", "spectral", "
|
|
171
|
+
custom_heuristic_subproblem if algo in ["full_louvain", "spectral", "RCCS"] else heuristic_subproblem,
|
|
163
172
|
additional_constraints=additional_constraints,
|
|
164
173
|
algo=algo,
|
|
165
174
|
package=package,
|
|
166
175
|
extract_dual=True,
|
|
167
176
|
ifc_params=ifc_params,
|
|
168
|
-
refine_in_subproblem=False,
|
|
169
177
|
refine_params=refine_params,
|
|
170
178
|
use_refined_column=True,
|
|
171
179
|
final_master_solve=False,
|
|
@@ -25,7 +25,7 @@ from asunder.nlbnp.algorithms.refinement import refine_partition_linear_group
|
|
|
25
25
|
from asunder.orchestrator import run_csd_decomposition
|
|
26
26
|
from asunder.types import DecompositionResult, MasterProblemFn, SubproblemFn
|
|
27
27
|
|
|
28
|
-
_CUSTOM_HEURISTIC_ALGOS = {"spectral", "full_louvain", "
|
|
28
|
+
_CUSTOM_HEURISTIC_ALGOS = {"spectral", "full_louvain", "RCCS"}
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
def _items_or_empty(items: Sequence[Any] | None) -> list[Any]:
|
|
@@ -179,9 +179,30 @@ def run_nonlinear_branch_and_price(
|
|
|
179
179
|
must_link, cannot_link : sequence of tuple, optional
|
|
180
180
|
Pairwise constraints using graph node labels or adjacency indices.
|
|
181
181
|
algorithm : str
|
|
182
|
-
|
|
182
|
+
Name of heuristic subproblem used to replace the ILP subproblem. Third-party algorithms combine adjacency and dual information into a unified input while custom algorithms treat adjacency and duals as separate inputs. Supported third-party algorithms are listed under the ``package`` parameter.
|
|
183
|
+
Available custom algorithm options include:
|
|
184
|
+
|
|
185
|
+
``"spectral"``:
|
|
186
|
+
Modified iterative bisection algorithm based on Mark Newman's eigenvector-based method.
|
|
187
|
+
``"full_louvain"``:
|
|
188
|
+
Modified but Louvain-like algorithm.
|
|
189
|
+
``"RCCS"``:
|
|
190
|
+
This means Reduced Cost Community Search and is a greedy and local search heuristic for finding communities that maximize the reduced cost.
|
|
183
191
|
package : str or None
|
|
184
|
-
|
|
192
|
+
Package from which non-custom heuristic subproblem is selected. Package and algorithm options include:
|
|
193
|
+
|
|
194
|
+
``"networkx"``:
|
|
195
|
+
``"louvain"``, ``"greedy"``, ``"girvan_newman"``
|
|
196
|
+
``"sknetwork"``:
|
|
197
|
+
``"louvain"``, ``"leiden"``, ``"lpa"``
|
|
198
|
+
``"igraph"``:
|
|
199
|
+
``"leiden"``, ``"greedy"``, ``"infomap"``, ``"lpa"``, ``"multilevel"``, ``"voronoi"``, ``"walktrap"``, ``"cpm_leiden"``
|
|
200
|
+
``"leidenalg"``:
|
|
201
|
+
``"leiden"``, ``"signed_leiden"``, ``"cpm_leiden"``, ``"surprise_leiden"``, ``"signed_surprise_leiden"``
|
|
202
|
+
``None``:
|
|
203
|
+
``"signed_louvain"``, ``"spinglass"``
|
|
204
|
+
|
|
205
|
+
Algorithms that start with ``"cpm"``, ``"signed"``, and ``"spinglass"`` are signed.
|
|
185
206
|
seed : int or None
|
|
186
207
|
Random seed.
|
|
187
208
|
ifc_params : dict or None
|
|
@@ -285,7 +306,6 @@ def run_nonlinear_branch_and_price(
|
|
|
285
306
|
cfg.seed = seed
|
|
286
307
|
cfg.extract_dual = extract_dual
|
|
287
308
|
cfg.ifc_params = ifc_params
|
|
288
|
-
cfg.refine_in_subproblem = False
|
|
289
309
|
cfg.refine_params = refine_params
|
|
290
310
|
cfg.use_refined_column = use_refined_column and refine
|
|
291
311
|
cfg.refine_post_loop = refine_post_loop and refine
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: put-asunder
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Asunder: Constrained Network Structure Detection on Undirected Graphs.
|
|
5
5
|
Author-email: Allman Group <allmanaa@umich.edu>, Fortune Adekogbe <fortunea@umich.edu>
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -65,13 +65,20 @@ Base install:
|
|
|
65
65
|
python3 -m pip install put-asunder
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
Graph extras (supports ``leidenalg`` and ``igraph`` algorithms):
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
python3 -m pip install "put-asunder[graph]"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
Graph and visualization (``matplotlib`` and ``seaborn``) extras:
|
|
69
76
|
|
|
70
77
|
```bash
|
|
71
78
|
python3 -m pip install "put-asunder[graph,viz]"
|
|
72
79
|
```
|
|
73
80
|
|
|
74
|
-
Legacy heuristics (best-effort on Python 3.13 and 3.14):
|
|
81
|
+
Legacy core periphery heuristics (best-effort on Python 3.13 and 3.14):
|
|
75
82
|
|
|
76
83
|
```bash
|
|
77
84
|
python3 -m pip install "put-asunder[legacy]"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/load_balancing/column_generation/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{put_asunder-0.2.2 → put_asunder-0.2.4}/asunder/load_balancing/utils/partition_generation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|