Skip to main content

A fast maximum weight bipartite matching algorithm from 'A Faster Algorithm for Maximum Weight Matching on Unrestricted Bipartite Graphs'

Project description

Kwok

A Cython-based implementation of "A Faster Algorithm for Maximum Weight Matching on Unrestricted Bipartite Graphs" that supports multiple Python versions and platforms.

About

Kwok implements a fast maximum weight bipartite matching algorithm based on the paper "A Faster Algorithm for Maximum Weight Matching on Unrestricted Bipartite Graphs" (https://arxiv.org/abs/2502.20889). The algorithm achieves runtime O(E^1.4 + LR) estimated from experimental tests on random graphs where |L| <= |R|.

The algorithm is particularly efficient for dense graphs and outperforms traditional implementations of the Hungarian algorithm in many practical scenarios.

Installation

pip install kwok

Usage

import kwok

# Example usage
L_size = 3  # Number of vertices in left partition
R_size = 3  # Number of vertices in right partition
adj = [
    [(0, 10), (1, 5), (2, 1)],  # Edges from left vertex 0
    [(0, 2), (1, 15), (2, 0)],  # Edges from left vertex 1
    [(0, 0), (1, 8), (2, 12)]   # Edges from left vertex 2
]

# Solve the matching problem
matching = kwok.kwok(L_size, R_size, adj)
print("Left pairs:", matching.left_pairs)
print("Right pairs:", matching.right_pairs)
print("Total weight:", matching.total_weight)

API Reference

kwok(L_size, R_size, adj)

Computes the maximum weight matching in a bipartite graph.

Parameters:

  • L_size (int): Number of vertices in left partition (L)
  • R_size (int): Number of vertices in right partition (R)
  • adj (list): Adjacency list where each element is a list of (vertex, weight) tuples representing edges from a vertex in L to vertices in R

Returns:

  • Matching: A dataclass with the following attributes:
    • left_pairs (list): Maps L vertices to their matched R vertices (-1 if unmatched)
    • right_pairs (list): Maps R vertices to their matched L vertices (-1 if unmatched)
    • total_weight (int|float): Total weight of the matching

Note: Integer weights are not required, but using integers may improve performance.

Development

To build the package locally:

pip install -e .

Building wheels with cibuildwheel

To build wheels for multiple Python versions and platforms, we use cibuildwheel.

cibuildwheel is a powerful tool that:

  • Builds wheels for CPython and PyPy on Windows, macOS, and Linux
  • Handles platform-specific wheels (including manylinux)
  • Tests the built wheels in isolated environments
  • Integrates with CI services like GitHub Actions

Local testing with cibuildwheel

To test cibuildwheel locally:

pip install cibuildwheel
python -m cibuildwheel --platform linux

Available platforms are: linux, windows, and macos.

CI integration

This project is configured to automatically build wheels using GitHub Actions. See the .github/workflows/build_wheels.yml file for the configuration.

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

kwok-0.1.0.tar.gz (80.6 kB view details)

Uploaded Source

Built Distributions

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

kwok-0.1.0-cp311-cp311-win_amd64.whl (39.9 kB view details)

Uploaded CPython 3.11Windows x86-64

kwok-0.1.0-cp310-cp310-win_amd64.whl (39.9 kB view details)

Uploaded CPython 3.10Windows x86-64

kwok-0.1.0-cp39-cp39-win_amd64.whl (40.0 kB view details)

Uploaded CPython 3.9Windows x86-64

kwok-0.1.0-cp38-cp38-win_amd64.whl (40.5 kB view details)

Uploaded CPython 3.8Windows x86-64

kwok-0.1.0-cp37-cp37m-win_amd64.whl (41.7 kB view details)

Uploaded CPython 3.7mWindows x86-64

kwok-0.1.0-cp36-cp36m-win_amd64.whl (40.0 kB view details)

Uploaded CPython 3.6mWindows x86-64

File details

Details for the file kwok-0.1.0.tar.gz.

File metadata

  • Download URL: kwok-0.1.0.tar.gz
  • Upload date:
  • Size: 80.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kwok-0.1.0.tar.gz
Algorithm Hash digest
SHA256 61fee4ac21fe70de742d86f49bd6a8bba0df828fd0259f605510f650caecdb90
MD5 a9d6c0361fca10b71c8370b5b8ae3781
BLAKE2b-256 7628accf3c655ce0b29963f48fbebc848ca137ad82c0992e79459269aae8a187

See more details on using hashes here.

File details

Details for the file kwok-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: kwok-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 39.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kwok-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9f02a8f6ef803b5c32f24cc42149addca2293f63e7da3edb1b8168ce25ed7894
MD5 67afa79f6d8d01d41142e53e9f26fd67
BLAKE2b-256 009c37b18a2b70333bacfd409f03ce21a2745908059ae59614c8b9f0c4b7d1b6

See more details on using hashes here.

File details

Details for the file kwok-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: kwok-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 39.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kwok-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7a520bb731b3cc0c45c3e56362400e63555f42691b21fba84e5a5f39300ebb04
MD5 feca91ea2ed3db3d5f61a600b7f3aeb4
BLAKE2b-256 cff856f2009afd831cbcaa8a58cbd214a8cb36faa0462a663f721059eda86a3c

See more details on using hashes here.

File details

Details for the file kwok-0.1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: kwok-0.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 40.0 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kwok-0.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4868264f491d45aca27f3fbb6e0761b0567e3b1741632c69b04505f3b4ec9dda
MD5 85f2cfd3460b526dbd1547b214bb17d6
BLAKE2b-256 bf582051dc9436be2130302784e491b35f3b2453148ba1f62b52597f132a4ef9

See more details on using hashes here.

File details

Details for the file kwok-0.1.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: kwok-0.1.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 40.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kwok-0.1.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 2d21d88b6eb2330986633ee32bc68b13b6d785dd1bb053312369f2dc1539b22c
MD5 bc174a4c3d46362c37146500d407e0dc
BLAKE2b-256 61d26bdb1ca28f5f53bb040387148ad11d5af4f5ae37be4a0a0440859a0e7533

See more details on using hashes here.

File details

Details for the file kwok-0.1.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: kwok-0.1.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 41.7 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kwok-0.1.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 00c60387ea3d606e25b81b0591bfd2dfd227eaa92d09df674cbbd986cf3b66bb
MD5 a03e5155b8be6e1eefb830db5b9904f8
BLAKE2b-256 86f49b53218c850bb70a8a740402401e0a89f439ad69c62b4dd0311a5f640be7

See more details on using hashes here.

File details

Details for the file kwok-0.1.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: kwok-0.1.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 40.0 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kwok-0.1.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 f2760ce77753e753383651d637ebde7745d7d143b6eb1af6d097c1b23a7c5955
MD5 9b494b090b35926c525d3261f293133e
BLAKE2b-256 7e342a25a9ba6ab7e0600190bd121978bac9fb78d528c388dcb6aaf900dfe925

See more details on using hashes here.

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