{"id":16836877,"url":"https://github.com/fil/lap-jv","last_synced_at":"2025-10-18T04:22:43.348Z","repository":{"id":66392301,"uuid":"77936283","full_name":"Fil/lap-jv","owner":"Fil","description":"Linear Assignment Problem — A Javascript implementation of R. Jonker and A. Volgenant’s algorithm (LAPJV)","archived":false,"fork":false,"pushed_at":"2024-07-04T07:01:01.000Z","size":67,"stargazers_count":32,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-25T03:13:13.443Z","etag":null,"topics":["assignment","lap-jv"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-03T17:00:04.000Z","updated_at":"2024-11-07T01:00:08.000Z","dependencies_parsed_at":"2025-02-18T18:35:44.219Z","dependency_job_id":"6ec9bac3-88f2-47ad-9bf2-5da2be8614b9","html_url":"https://github.com/Fil/lap-jv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fil%2Flap-jv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fil%2Flap-jv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fil%2Flap-jv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fil%2Flap-jv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fil","download_url":"https://codeload.github.com/Fil/lap-jv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345266,"owners_count":21088244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assignment","lap-jv"],"created_at":"2024-10-13T12:15:15.125Z","updated_at":"2025-10-18T04:22:38.300Z","avatar_url":"https://github.com/Fil.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## LAP-JV\n### Linear Assignment Problem — algorithm by R. Jonker and A. Volgenant\n\n“A shortest augmenting path algorithm for dense and sparse linear assignment problems,” by R. Jonker and A. Volgenant, _Computing_ (1987) 38: 325. doi:10.1007/BF02278710\n \nPorted to javascript by Philippe Rivière, from the C++ implementation found at https://github.com/yongyanghz/LAPJV-algorithm-c\n\nAdded an epsilon to avoid infinite loops caused by rounding errors.\n\n\n## Usage\n\nIn the [Linear Assignment Problem](https://en.wikipedia.org/wiki/Assignment_problem), you have _n_ agents and _n_ tasks, and need to assign one task to each agent, at minimal cost.\n\nFirst, compute the cost matrix: how expensive it is to assign agent _i_ (rows) to task _j_ (columns).\n\nThe LAP-JV algorithm will give an optimal solution:\n\n```javascript\n  n = 3, costs = [[1,2,3], [4,2,1], [2,2,2]];\n  //               ^ _ _    _ _ ^    _ ^ _\n  solution = lap(n, costs);\n\n  console.log(solution.col);\n  // [0, 2, 1]\n  console.log(solution.cost);\n  // 4\n```\n\nHere agent 0 is assigned to task 0, agent 1 to task 2, agent 2 to task 1, resulting in a total cost of `1 + 1 + 2 = 4`.\n\n\n**Cost callback**\n\nFor performance and usability reasons, the `lap` function now accepts a cost callback `cost(i,j)` instead of a cost matrix:\n```javascript\n   var pos = new Float32Array(1000).map(d =\u003e Math.random() * 1000);\n   lap(pos.length, (i,j) =\u003e (pos[i] - j) * (pos[i] - j));\n```\n\n## \n\nThe algorithm runs in `O(n^2)`. You can run it [directly](http://bl.ocks.org/Fil/6ead5eea43ec506d5550f095edc45e3f) or as a javascript worker, as in the following example:\n\n[![](https://gist.githubusercontent.com/Fil/d9752d8c41cc2cc176096ce475233966/raw/88c1e7e4d62df8145a68808b7252cd5013e0394f/thumbnail.png)](https://observablehq.observablehq.cloud/pangea/varia/lap-jv)\n\nIn the example above, we assign _n_ points to a grid of _n_ positions. `costs[i][j]` is the square distance between point _i_'s original coordinates and position _j_'s coordinates. The algorithm minimizes the total cost, i.e. the sum of square displacements.\n\n\n## \n\nComments and patches at [Fil/lap-jv](https://github.com/Fil/lap-jv).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffil%2Flap-jv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffil%2Flap-jv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffil%2Flap-jv/lists"}