Skip to main content

Linear sum assignment problem solver using Jonker-Volgenant algorithm. Fork to support numpy 2.x

Project description

Build Status PyPI

Linear Assignment Problem solver using Jonker-Volgenant algorithm

This project is the rewrite of pyLAPJV which supports Python 3 and updates the core code. The performance is twice as high as the original thanks to the optimization of the augmenting row reduction phase using Intel AVX2 intrinsics. It is a native Python 3 module and does not work with Python 2.x, stick to pyLAPJV otherwise.

Blog post

Linear assignment problem is the bijection between two sets with equal cardinality which optimizes the sum of the individual mapping costs taken from the fixed cost matrix. It naturally arises e.g. when we want to fit t-SNE results into a rectangular regular grid. See this awesome notebook for the details about why LAP matters: CloudToGrid.

Jonker-Volgenant algorithm is described in the paper:

R. Jonker and A. Volgenant, "A Shortest Augmenting Path Algorithm for Dense and Sparse Linear Assignment Problems," Computing, vol. 38, pp. 325-340, 1987.

This paper is not publicly available though a brief description exists on sciencedirect.com. JV is faster in than the Hungarian algorithm in practice, though the complexity is the same - O(n3).

The C++ source of the algorithm comes from http://www.magiclogic.com/assignment.html It has been reworked and partially optimized with OpenMP 4.0 SIMD.

Installing

pip3 install lapjv

Tested on Linux and Windows. macOS is not supported, please do not report macOS build errors in the issues. Feel free to PR macOS support, but I warn that it will be a rough ride.

Usage

Refer to test.py for the complete code.

from lapjv import lapjv
row_ind, col_ind, _ = lapjv(cost_matrix)

The assignment matrix by row is row_ind: the value at n-th place is the assigned column index to the n-th row. col_ind is the reverse of row_ind: mapping from columns to row indexes.

Note: a bijection is only possible for sets with equal cardinality. If you need to map A vectors to B vectors, derive the square symmetric (A+B) x (A+B) matrix: take the first A rows and columns from A and the remaining [A..A+B] rows and columns from B. Set the A->A and B->B costs to some maximum distance value, big enough so that you don't see assignment errors.

Illegal instruction

This error appears if your CPU does not support the AVX2 instruction set. We do not ship builds for different CPUs so you need to build the package yourself:

pip3 install git+https://github.com/src-d/lapjv

NAN-s

NAN-s in the cost matrix lead to completely undefined result. It is the caller's responsibility to check them.

License

MIT Licensed,see LICENSE

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

lapjv_numpy2-1.3.26.tar.gz (11.1 kB view details)

Uploaded Source

Built Distributions

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

lapjv_numpy2-1.3.26-cp311-cp311-win_amd64.whl (27.9 kB view details)

Uploaded CPython 3.11Windows x86-64

lapjv_numpy2-1.3.26-cp311-cp311-musllinux_1_1_x86_64.whl (727.5 kB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ x86-64

lapjv_numpy2-1.3.26-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (162.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lapjv_numpy2-1.3.26-cp310-cp310-win_amd64.whl (27.9 kB view details)

Uploaded CPython 3.10Windows x86-64

lapjv_numpy2-1.3.26-cp310-cp310-musllinux_1_1_x86_64.whl (726.7 kB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

lapjv_numpy2-1.3.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (161.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lapjv_numpy2-1.3.26-cp39-cp39-win_amd64.whl (27.9 kB view details)

Uploaded CPython 3.9Windows x86-64

lapjv_numpy2-1.3.26-cp39-cp39-musllinux_1_1_x86_64.whl (726.6 kB view details)

Uploaded CPython 3.9musllinux: musl 1.1+ x86-64

lapjv_numpy2-1.3.26-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (161.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file lapjv_numpy2-1.3.26.tar.gz.

File metadata

  • Download URL: lapjv_numpy2-1.3.26.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for lapjv_numpy2-1.3.26.tar.gz
Algorithm Hash digest
SHA256 9a5cc36bbcd365678b660940a169ccb8ee660cffeda49b0de479bb0eda7aa5c6
MD5 004098994d00230bcea77bb4021e6226
BLAKE2b-256 7aa611c7472936b3d0dda0c53518c5350acfff518a97b1f3e12ac1e5bf04a795

See more details on using hashes here.

File details

Details for the file lapjv_numpy2-1.3.26-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for lapjv_numpy2-1.3.26-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 acd32fc7ea8285a95e20aa1c250216ac461275f070dcf6ca116da6d7ce69766d
MD5 e4ab286371e51b5ec8317e3a009ee19a
BLAKE2b-256 cbd42d1a4cdcd8ae289f4feea98412e1947182d05386711337985aa528e41de1

See more details on using hashes here.

File details

Details for the file lapjv_numpy2-1.3.26-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lapjv_numpy2-1.3.26-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 763fbfd28a19b0de366cbca892aeafcd3febf6d830137191b0a0ffc0a4e1ab98
MD5 52ab75735a3e38ccd502160ecb35feb2
BLAKE2b-256 b45c568040c6b8f30aada53d4e03252842be19c1ab4f6e9a3b65fc246773bc66

See more details on using hashes here.

File details

Details for the file lapjv_numpy2-1.3.26-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lapjv_numpy2-1.3.26-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 925f1b428d1caf8b94e6cd94a674146783fdea2ef57d7cb53d29d625247cebff
MD5 98ef1298f4c31c630a8d5bc83d798cf9
BLAKE2b-256 21f5f44c19234e6dd2c3536326d66deba3b61579b3610a34d10748e2e3c883c5

See more details on using hashes here.

File details

Details for the file lapjv_numpy2-1.3.26-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for lapjv_numpy2-1.3.26-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 dbf87a0b62dd6d6ca8a42b0e8dc4ec8a8b65b854de3aa7d9a5caf8af739258b0
MD5 283ef48c3f2d9b05b920e67b3f4588fc
BLAKE2b-256 1ad9c9ff433da9c14ab3ddccbf482d8dc0016d85e783f7545b6ddd792334bf73

See more details on using hashes here.

File details

Details for the file lapjv_numpy2-1.3.26-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lapjv_numpy2-1.3.26-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e17893e8f761b836b60f55d25c2573c092d480f39bb4635320e99257e4e7ac9b
MD5 3171d29949441b7b7d01e2a6b4115d36
BLAKE2b-256 62744087ab880bcc434477748c3f5c88c506c90ecdb76e0ec433506fe46effa1

See more details on using hashes here.

File details

Details for the file lapjv_numpy2-1.3.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lapjv_numpy2-1.3.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7ca651313bfd55b00f5b8274e0d85e2af8c4ccce0563f47d238b240ce6ef2db
MD5 75f5b99b2275fb87fe370e9e0b3b3206
BLAKE2b-256 c7a4fdf8d8a28c8aacca276acd4f7842f8d175715b97e0c2d44f0e1ce4a8290b

See more details on using hashes here.

File details

Details for the file lapjv_numpy2-1.3.26-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for lapjv_numpy2-1.3.26-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 849d01e00ead97589e0fa185d4b84e765b081fd7003adc732a5fd49508ac35b6
MD5 799b0c4d489573132a8b3f462ebe9c9b
BLAKE2b-256 838b01e8822f10d5b723f1f5cc6fd2f8c7ccee1c752671f48ffc2b3617a12c38

See more details on using hashes here.

File details

Details for the file lapjv_numpy2-1.3.26-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lapjv_numpy2-1.3.26-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8954c4af1e7d32c3edc76f3f60d55e38667082f0b76735f718c8f9ceb68fd25f
MD5 ee73f16b8f8488e2aa2d16e43ecd2e98
BLAKE2b-256 fa95e3fd34f48c0318180b9a4353464ab271cade223733877b7468e92166ecdb

See more details on using hashes here.

File details

Details for the file lapjv_numpy2-1.3.26-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lapjv_numpy2-1.3.26-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 22b37766ef9cad8393bf4fc1228c5253db567d3af4078fa117b33a097282ba9b
MD5 4e6c080d5f37ac979278cb5a9fd172d7
BLAKE2b-256 7ecfbbdf678478610af75efc3144e432ce123b82ca0da6b07eb4263b067219f0

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