Skip to main content

Munk

Repository PyPi License

Maximum and minimum cost assignments using the Hungarian/Munkres algorithm for n × m cost matrices.

Install

pip install munk

Looking for a JavaScript implementation? Check out @alg/munkres on JSR.

Examples

Munk proves min/max cost and assignment functions.

The cost functions return the cost of a maximum or minimum assignment:

from munk import min_cost, max_cost

cost_matrix = [
    [8, 4, 7],
    [5, 2, 3],
    [9, 4, 8],
]
print(min_cost(cost_matrix))  # 15
print(max_cost(cost_matrix))  # 18

Often, people refer to "minimising cost matrices" and "maximising profit matrices", Munk makes no distinction between profits and costs—a matrix of values is provided and the values in an assignment are either minimised (min_cost) or maximised (max_cost).

The assignment functions return the indices in the cost matrix for a minimum or maximum assignment:

from munk import min_assignment, max_assignment

cost_matrix = [
    [8, 4, 7],
    [5, 2, 3],
    [9, 4, 8],
]
print(min_assignment(cost_matrix))  # [(0, 0), (1, 2), (2, 1)]
print(max_assignment(cost_matrix))  # [(0, 0), (1, 1), (2, 2)]

All cost and assignment functions handle any n × m matrices:

from munk import min_assignment, max_assignment

wide = [
    [4, 5, 8, 7],
    [2, 12, 6, 5],
    [7, 8, 3, 9],
]

long = [
    [11, 13, 13],
    [7, 21, 13],
    [10, 7, 15],
    [17, 11, 13],
    [10, 13, 14],
]

print(min_assignment(wide))  # [(0, 1), (1, 0), (2, 2)]
print(max_assignment(long))  # [(1, 1), (2, 2), (3, 0)]

Metadata

Release files for munk 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for munk 0.0.4
File Size Uploaded Provenance
munk-0.0.4.tar.gz 8.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for munk 0.0.4
File Interpreter ABI Platform
munk-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / munk-0.0.4.tar.gz

Download URL munk-0.0.4.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a09398846f21d80c0af21eeb7f0daf09f23590e8144e9e0df844d8c3fb999be1
BLAKE2b-256 checksum
How to use checksums
5062e28a313a2833936b4fc35b7dd639e5007a7b4363a19f6031e95e34fb32d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.1

Release files / munk-0.0.4-py3-none-any.whl

Download URL munk-0.0.4-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
660f15d08c9d4c962e06c78b29a22fb1fec7eef75ec7124b97db0967be6c0930
BLAKE2b-256 checksum
How to use checksums
8df3fa8d1dd6bb937fa31cf0d6c5fed6f730a1634a8e06d6f072ac3806928df2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.1

Security for munk 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page