A Python implementation of the Asymmetric Greedy Search heuristic solution to the linear sum assignment problem.
Project description
Asymmetric Greedy Search
A Python implementation of the Asymmetric Greedy Search (AGS) algorithm, a fast heuristic for solving the Linear Sum Assignment Problem, based on the work of Brown et al. (2017).
Features
This package provides an efficient alternative to exact methods like the Hungarian algorithm, particularly for large, rectangular (asymmetric) matrices where exact solutions may be computationally expensive. It includes both NumPy and Numba backends and extends the original algorithm with features such as:
- Optional randomized greedy initialization
- Support for both cost minimization and benefit maximization
- Optional batched row updates between global swap benefit recalculations
Installation
pip install git+https://github.com/kaboroevich/asymmetric-greedy-search.git
Usage Example
from asymmetric_greedy_search import AsymmetricGreedySearch
import numpy as np
# Create a random benefit matrix (maximize benefit)
np.random.seed(57)
benefit = np.random.rand(100, 120)
ags = AsymmetricGreedySearch(backend='numba')
row_ind, assignment = ags.optimize(benefit)
score = benefit[row_ind, assignment].sum()
print(f"Total benefit: {score}")
Parameters
AsymmetricGreedySearch(backend = "numpy")
- backend (
str, optional): Specifies the computational backend to use for the algorithm.
Options are:"numpy"(default): Uses a NumPy-based implementation, suitable for general use."numba": Uses a Numba-accelerated implementation for improved performance on large problems.
AsymmetricGreedySearch.optimize(benefit, minimize=False, shuffle=False, maximum_iterations=0, stagnation_limit=0, stagnation_tolerance=1e-3, row_batch_size=1)
Runs the Asymmetric Greedy Search optimization on the provided benefit matrix.
- benefit (
numpy.ndarray): A 2D array representing the benefit or cost matrix for row-column assignments. - minimize (
bool): IfTrue, the algorithm minimizes the assignment costs instead of maximizing the benefit. Defaults toFalse. - shuffle (
bool): IfTrue, rows are shuffled before the greedy initialization to potentially improve solution diversity. Defaults toFalse. - maximum_iterations (
int): The maximum number of optimization iterations to perform. If set to0, no limit is applied. Defaults to0. - stagnation_limit (
int): The number of consecutive iterations allowed where the maximum improvement remains below a specified tolerance before terminating early. A value of0disables stagnation detection. Defaults to0. - stagnation_tolerance (
float): The relative improvement threshold used to detect stagnation. Stagnation is triggered if the maximum benefit improvement stays belowinitial_max_delta * stagnation_toleranceforstagnation_limitconsecutive iterations. Defaults to1e-3. - row_batch_size (
int): The number of rows to swap in each iteration, allowing batched updates to improve efficiency. Defaults to1(no batching).
Returns:
A tuple containing two NumPy arrays:
- The first array contains row indices.
- The second array contains the assigned column indices corresponding to each row.
Benchmarking
The examples/lsa_benchmark.ipynb notebook benchmarks AGS against SciPy's linear_sum_assignment, comparing runtime and assignment quality on synthetic distance matrices of increasing size.
AGS achieves solutions within a few percent of optimal (LSA) while offering orders-of-magnitude faster runtime on certain large matrices.
References
Brown, Peter, Yuedong Yang, Yaoqi Zhou, and Wayne Pullan. "A heuristic for the time constrained asymmetric linear sum assignment problem." Journal of Combinatorial Optimization 33 (2017): 551-566.
https://doi.org/10.1007/s10878-015-9979-2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asymmetric_greedy_search-0.1.0.tar.gz.
File metadata
- Download URL: asymmetric_greedy_search-0.1.0.tar.gz
- Upload date:
- Size: 47.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bc0ce7588ba18825b25df3e6f684944b333fab3f5cf55ca9ff9c1e742511c1f
|
|
| MD5 |
8476330ef7e7982a9882855c27ffa267
|
|
| BLAKE2b-256 |
23528e24a250235085069494970ff706001a1840aceefeed6836b2ef7a31583b
|
Provenance
The following attestation bundles were made for asymmetric_greedy_search-0.1.0.tar.gz:
Publisher:
publish.yml on kaboroevich/asymmetric-greedy-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
asymmetric_greedy_search-0.1.0.tar.gz -
Subject digest:
8bc0ce7588ba18825b25df3e6f684944b333fab3f5cf55ca9ff9c1e742511c1f - Sigstore transparency entry: 244448394
- Sigstore integration time:
-
Permalink:
kaboroevich/asymmetric-greedy-search@81112acf93f23a3ddf5d5a7a37e380ed0c861698 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kaboroevich
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@81112acf93f23a3ddf5d5a7a37e380ed0c861698 -
Trigger Event:
release
-
Statement type:
File details
Details for the file asymmetric_greedy_search-0.1.0-py3-none-any.whl.
File metadata
- Download URL: asymmetric_greedy_search-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80d3d18a58470feeec7822f3b754d58ec1dbda546fcb03cb7c5b48cffd948e58
|
|
| MD5 |
3d47c2f5b0616969f222e36e9e3c559d
|
|
| BLAKE2b-256 |
2213fd700ed38c832f47cf46c5f7e6a2b0fccf3307ef7cec7c41f5d14f9da728
|
Provenance
The following attestation bundles were made for asymmetric_greedy_search-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on kaboroevich/asymmetric-greedy-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
asymmetric_greedy_search-0.1.0-py3-none-any.whl -
Subject digest:
80d3d18a58470feeec7822f3b754d58ec1dbda546fcb03cb7c5b48cffd948e58 - Sigstore transparency entry: 244448397
- Sigstore integration time:
-
Permalink:
kaboroevich/asymmetric-greedy-search@81112acf93f23a3ddf5d5a7a37e380ed0c861698 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kaboroevich
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@81112acf93f23a3ddf5d5a7a37e380ed0c861698 -
Trigger Event:
release
-
Statement type: