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-1.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-1.1.0-cp313-cp313-win_amd64.whl (40.5 kB view details)

Uploaded CPython 3.13Windows x86-64

kwok-1.1.0-cp312-cp312-win_amd64.whl (41.0 kB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.7mWindows x86-64

kwok-1.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-1.1.0.tar.gz.

File metadata

  • Download URL: kwok-1.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-1.1.0.tar.gz
Algorithm Hash digest
SHA256 adf44f40bcb71bf6ed6c5931a51db68bd1876d5d74dd940d51de2d5f9648b271
MD5 eb9afe22cb00227fafe5967bb2628981
BLAKE2b-256 1191a1225e0ba25434e4c383174869e4f910e3983f5650003bd463b869676471

See more details on using hashes here.

File details

Details for the file kwok-1.1.0-cp313-cp313-win_amd64.whl.

File metadata

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

File hashes

Hashes for kwok-1.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 eb7dc635a31633b9ae262e4dcc7090716d207b09efb3ab99d2d1c40a798f778e
MD5 a0b00cf0228c5cc9dc2cd2137834969f
BLAKE2b-256 56951fab032ab849ef177a877b887f0702614acd721ea17dd3347b48bc6d1b5d

See more details on using hashes here.

File details

Details for the file kwok-1.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: kwok-1.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 41.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kwok-1.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0a2a06734894bc36044ba897191d3a159b1800efac2d21c19e2babd4aa58e24c
MD5 4ec0d9fd2a5647189e1841ee35840ec1
BLAKE2b-256 43488d09ee065e9887341330bc1176cf5b77b1fc89011d3ad3a19296a40094f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kwok-1.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-1.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f569e4b251884a576aeeaabfe03379accc431bbf094bc3b5c3514ba0d606adc4
MD5 4f617bf6bf38f23eb554265bc3fedee9
BLAKE2b-256 4a448e6de92a10d2d3470a8808448919efae4999820c28766b94529b7b35f85d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kwok-1.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-1.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c6bc56ab7349fcecad0784b9d2db05bbfc0eba5acc890f7f07a5f0f6568fc64a
MD5 11a1dfba49137a10a516bbfa90ccff2b
BLAKE2b-256 8f7ce2d9892c106ee83232a5023e1c0f5a01ecba816e0149ccef6ee4dc1b50dd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kwok-1.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-1.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d624c0a074a7add34142b57e864c4588379353a2cf57b175cf3c1c978c7f7119
MD5 e9f64e0c26ca9e80ef1656d585e7b633
BLAKE2b-256 f6c4d81578fbd4b185e580baf096ab66eab54e4f98f482f59f262a3e8b52cf10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kwok-1.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-1.1.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a8dca66518326da45d8ec7d14c8c45d6d57e8331602847062aee7d8489e5fabf
MD5 9f6bd852d43302a456bca7a6a9cd35cb
BLAKE2b-256 98c1b6ace1a340f1764cd2c2dc3ef85d4277ec3967693f141da34d074d53fb3f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kwok-1.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-1.1.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 aa4e53ebb85f99d40f393a738f256dd79461692a6012ec45db1f8c6b6acadc01
MD5 d8b052c62b7c302ad6116d0276212690
BLAKE2b-256 406d86463ee1e02d411acecc41f9df9627fbf89ec8b196e4dbcb9b15e8c22f9b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kwok-1.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-1.1.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 60e920b45b8786e13dd3af4b2ca7464a55d6f0782e689c3cb4b50e5ef1c886a4
MD5 f976cfcf832b91a78763ce4da5fc0684
BLAKE2b-256 d5a8c51cd38abd6f5c9195461e809f12f72c19643faefd266259d776b061217c

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