Skip to main content

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): If True, the algorithm minimizes the assignment costs instead of maximizing the benefit. Defaults to False.
  • shuffle (bool): If True, rows are shuffled before the greedy initialization to potentially improve solution diversity. Defaults to False.
  • maximum_iterations (int): The maximum number of optimization iterations to perform. If set to 0, no limit is applied. Defaults to 0.
  • stagnation_limit (int): The number of consecutive iterations allowed where the maximum improvement remains below a specified tolerance before terminating early. A value of 0 disables stagnation detection. Defaults to 0.
  • stagnation_tolerance (float): The relative improvement threshold used to detect stagnation. Stagnation is triggered if the maximum benefit improvement stays below initial_max_delta * stagnation_tolerance for stagnation_limit consecutive iterations. Defaults to 1e-3.
  • row_batch_size (int): The number of rows to swap in each iteration, allowing batched updates to improve efficiency. Defaults to 1 (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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asymmetric_greedy_search-0.1.0.tar.gz (47.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asymmetric_greedy_search-0.1.0-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

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

Hashes for asymmetric_greedy_search-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8bc0ce7588ba18825b25df3e6f684944b333fab3f5cf55ca9ff9c1e742511c1f
MD5 8476330ef7e7982a9882855c27ffa267
BLAKE2b-256 23528e24a250235085069494970ff706001a1840aceefeed6836b2ef7a31583b

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymmetric_greedy_search-0.1.0.tar.gz:

Publisher: publish.yml on kaboroevich/asymmetric-greedy-search

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asymmetric_greedy_search-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for asymmetric_greedy_search-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 80d3d18a58470feeec7822f3b754d58ec1dbda546fcb03cb7c5b48cffd948e58
MD5 3d47c2f5b0616969f222e36e9e3c559d
BLAKE2b-256 2213fd700ed38c832f47cf46c5f7e6a2b0fccf3307ef7cec7c41f5d14f9da728

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page