Google OR-Tools

  • Google OR-Tools
  • Español – América Latina
  • Português – Brasil
  • Tiếng Việt

Linear Sum Assignment Solver

This section describes the linear sum assignment solver , a specialized solver for the simple assignment problem, which can be faster than either the MIP or CP-SAT solver. However, the MIP and CP-SAT solvers can handle a much wider array of problems, so in most cases they are the best option.

Cost matrix

The costs for workers and task are given in the table below.

The following sections present a Python program that solves an assignment problem using the linear sum assignment solver.

Import the libraries

The code that imports the required library is shown below.

Define the data

The following code creates the data for the program.

The array is the cost matrix , whose i , j entry is the cost for worker i to perform task j . There are four workers, corresponding to the rows of the matrix, and four tasks, corresponding to the columns.

Create the solver

The program uses the linear assignment solver, a specialized solver for the assignment problem.

The following code creates the solver.

Add the constraints

The following code adds the costs to the solver by looping over workers and tasks.

Invoke the solver

The following code invokes the solver.

Display the results

The following code displays the solution.

The output below shows the optimal assignment of workers to tasks.

The following graph shows the solution as the dashed edges in the graph. The numbers next to the dashed edges are their costs. The total wait time of this assignment is the sum of the costs for the dashed edges, which is 265.

In graph theory, a set of edges in a bipartite graph that matches every node on the left with exactly one node on the right is called a perfect matching .

The entire program

Here is the entire program.

Solution when workers can't perform all tasks

In the previous example, we assumed that all workers can perform all tasks. But this not always the case - a worker might be unable to perform one or more tasks for various reasons. However, it is easy to modify the program above to handle this.

As an example, suppose that worker 0 is unable to perform task 3. To modify the program to take this into account, make the following changes:

  • Change the 0, 3 entry of the cost matrix to the string 'NA' . (Any string will work.) cost = [[90, 76, 75, 'NA'], [35, 85, 55, 65], [125, 95, 90, 105], [45, 110, 95, 115]]
  • In the section of the code that assigns costs to the solver, add the line if cost[worker][task] != 'NA': , as shown below. for worker in range(0, rows): for task in range(0, cols): if cost[worker][task] != 'NA': assignment.AddArcWithCost(worker, task, cost[worker][task]) The added line prevents any edge whose entry in the cost matrix is 'NA' from being added to the solver.

After making these changes and running the modified code, you see the following output:

Notice that the total cost is higher now than it was for the original problem. This is not surprising, since in the original problem the optimal solution assigned worker 0 to task 3, while in the modified problem that assignment is not allowed.

To see what happens if more workers are unable to perform tasks, you can replace more entries of the cost matrix with 'NA' , to denote additional workers who can't perform certain tasks:

When you run the program this time, you get a negative result:

This means there is no way to assign workers to tasks so that each worker performs a different task. You can see why this is so by looking at the graph for the problem (in which there are no edges corresponding to values of 'NA' in the cost matrix).

Since the nodes for the three workers 0, 1, and 2 are only connected to the two nodes for tasks 0 and 1, it not possible to assign distinct tasks to these workers.

The Marriage Theorem

There is a well-known result in graph theory, called The Marriage Theorem , which tells us exactly when you can assign each node on the left to a distinct node on the right, in a bipartite graph like the one above. Such an assignment is called a perfect matching . In a nutshell, the theorem says this is possible if there is no subset of nodes on the left (like the one in the previous example ) whose edges lead to a smaller set of nodes on the right.

More precisely, the theorem says that a bipartite graph has a perfect matching if and only if for any subset S of the nodes on the left side of the graph, the set of nodes on the right side of the graph that are connected by an edge to a node in S is at least as large as S.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2023-01-18 UTC.

Help | Advanced Search

Computer Science > Data Structures and Algorithms

Title: linear sum assignment with edition.

Abstract: We consider the problem of transforming a set of elements into another by a sequence of elementary edit operations, namely substitutions, removals and insertions of elements. Each possible edit operation is penalized by a non-negative cost and the cost of a transformation is measured by summing the costs of its operations. A solution to this problem consists in defining a transformation having a minimal cost, among all possible transformations. To compute such a solution, the classical approach consists in representing removal and insertion operations by augmenting the two sets so that they get the same size. This allows to express the problem as a linear sum assignment problem (LSAP), which thus finds an optimal bijection (or permutation, perfect matching) between the two augmented sets. While the LSAP is known to be efficiently solvable in polynomial time complexity, for instance with the Hungarian algorithm, useless time and memory are spent to treat the elements which have been added to the initial sets. In this report, we show that the problem can be formalized as an extension of the LSAP which considers only one additional element in each set to represent removal and insertion operations. A solution to the problem is no longer represented as a bijection between the two augmented sets. We show that the considered problem is a binary linear program (BLP) very close to the LSAP. While it can be solved by any BLP solver, we propose an adaptation of the Hungarian algorithm which improves the time and memory complexities previously obtained by the approach based on the LSAP. The importance of the improvement increases as the size of the two sets and their absolute difference increase. Based on the analysis of the problem presented in this report, other classical algorithms can be adapted.

Submission history

Access paper:.

  • Download PDF
  • Other Formats

References & Citations

  • Google Scholar
  • Semantic Scholar

DBLP - CS Bibliography

Bibtex formatted citation.

BibSonomy logo

Bibliographic and Citation Tools

Code, data and media associated with this article, recommenders and search tools.

  • Institution

arXivLabs: experimental projects with community collaborators

arXivLabs is a framework that allows collaborators to develop and share new arXiv features directly on our website.

Both individuals and organizations that work with arXivLabs have embraced and accepted our values of openness, community, excellence, and user data privacy. arXiv is committed to these values and only works with partners that adhere to them.

Have an idea for a project that will add value for arXiv's community? Learn more about arXivLabs .

Book cover

International Conference on Applied Intelligence and Informatics

AII 2022: Applied Intelligence and Informatics pp 90–101 Cite as

Tackling the Linear Sum Assignment Problem with Graph Neural Networks

  • Carlo Aironi 10 ,
  • Samuele Cornell 10 &
  • Stefano Squartini 10  
  • Conference paper

427 Accesses

1 Citations

Part of the Communications in Computer and Information Science book series (CCIS,volume 1724)

Linear Assignment Problems are fundamental combinatorial optimization problems that appear throughout domains such as logistics, robotics and telecommunications. In general, solving assignment problems to optimality is computationally infeasible even for contexts of small dimensionality, and so heuristic algorithms are often employed to find near-optimal solutions. The handcrafting of a heuristic usually requires expert-knowledge to exploit the problem structure to be addressed, however if the problem description changes slightly, a previously derived heuristic may no longer be appropriate.

This work explores a more general-purpose learning approach, based on the description of the problem through a bipartite graph, and the use of a Message Passing Graph Neural Network model, to attain the correct assignment permutation.

The simulation results indicate that the proposed structure allows for a significant increase in classification accuracy if compared with two different DNN approaches based on Dense Networks and Convolutional Neural Networks, furthermore, the GNN has proved to be very efficient with regard to the processing time and memory requirements, thanks to intrinsic parameter-sharing capability.

  • Linear assignment problem
  • Graph neural networks
  • Deep neural networks

This is a preview of subscription content, log in via an institution .

Buying options

  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
  • Available as EPUB and PDF
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Bertsekas, D.P.: The auction algorithm: a distributed relaxation method for the assignment problem. Ann. Oper. Res. 14 (1), 105–123 (1988)

Article   MathSciNet   MATH   Google Scholar  

Burkard, R., Dragoti-Cela, E.: Linear assignment problems and extensions. Supplement Volume A, 1 edn., pp. 75–149. Kluwer Academic Publishers, Netherlands (1999)

Google Scholar  

Clapper, B.M.: Munkres implementation for python. https://github.com/bmc/munkres . Accessed 10 May 2022

Fey, M., Lenssen, J.E.: Fast graph representation learning with PyTorch geometric. In: ICLR Workshop on Representation Learning on Graphs and Manifolds (2019)

Fujita, Y., Kanda, N., Horiguchi, S., Xue, Y., Nagamatsu, K., Watanabe, S.: End-to-end neural speaker diarization with self-attention. In: 2019 IEEE Automatic Speech Recognition and Understanding Workshop (ASRU), pp. 296–303. IEEE (2019)

Gori, M., Monfardini, G., Scarselli, F.: A new model for learning in graph domains. In: International Joint Conference on Neural Networks, vol. 2, pp. 729–734. IEEE (2005)

Haralick, R.M., Shapiro, L.G.: Image segmentation techniques. Comput. Vision Graph. Image Process. 29 (1), 100–132 (1985)

Article   Google Scholar  

Hirata, N.S., Julca-Aguilar, F.D.: Matching based ground-truth annotation for online handwritten mathematical expressions. Pattern Recogn. 48 (3), 837–848 (2015)

Article   MATH   Google Scholar  

Karmarkar, N., Ramakrishnan, K.: Computational results of an interior point algorithm for large scale linear programming. Math. Program. 52 (1), 555–586 (1991)

de Kerret, P., Gesbert, D., Filippone, M.: Decentralized deep scheduling for interference channels. arXiv preprint arXiv:1711.00625 (2017)

Kuhn, H.W.: The Hungarian method for the assignment problem. Naval Res. Logist. Q. 2 (1–2), 83–97 (1955)

Lee, M., Xiong, Y., Yu, G., Li, G.Y.: Deep neural networks for linear sum assignment problems. IEEE Wirel. Commun. Lett. 7 (6), 962–965 (2018)

Lian, W., Zhang, L.: A concave optimization algorithm for matching partially overlapping point sets. Pattern Recogn. 103 , 107322 (2020)

Lu, X., Ni, Q., Li, W., Zhang, H.: Dynamic user grouping and joint resource allocation with multi-cell cooperation for uplink virtual MIMO systems. IEEE Trans. Wireless Commun. 16 (6), 3854–3869 (2017)

Munkres, J.: Algorithms for the assignment and transportation problems. J. Soc. Ind. Appl. Math. 5 (1), 32–38 (1957)

Naiem, A., El-Beltagy, M., Ab, P.: Deep greedy switching: a fast and simple approach for linear assignment problems. In: 7th International Conference of Numerical Analysis and Applied Mathematics, p. 9999 (2009)

Scarselli, F., Gori, M., Tsoi, A.C., Hagenbuchner, M., Monfardini, G.: The graph neural network model. IEEE Trans. Neural Netw. 20 (1), 61–80 (2008)

Smith, K., Gatica-Perez, D., Odobez, J.M., Ba, S.: Evaluating multi-object tracking. In: 2005 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR 2005)-Workshops, p. 36. IEEE (2005)

Song, H., Fang, X., Fang, Y.: Unlicensed spectra fusion and interference coordination for LTE systems. IEEE Trans. Mob. Comput. 15 (12), 3171–3184 (2016)

Sun, H., Chen, X., Shi, Q., Hong, M., Fu, X., Sidiropoulos, N.D.: Learning to optimize: training deep neural networks for interference management. IEEE Trans. Signal Process. 66 (20), 5438–5453 (2018)

Sun, H., Chen, X., Shi, Q., Hong, M., Fu, X., Sidiropoulos, N.D.: Learning to optimize: training deep neural networks for wireless resource management. In: 2017 IEEE 18th International Workshop on Signal Processing Advances in Wireless Communications (SPAWC), pp. 1–6. IEEE (2017)

Yu, D., Kolbæk, M., Tan, Z.H., Jensen, J.: Permutation invariant training of deep models for speaker-independent multi-talker speech separation. In: 2017 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), pp. 241–245. IEEE (2017)

Yu, G., Xu, L., Feng, D., Yin, R., Li, G.Y., Jiang, Y.: Joint mode selection and resource allocation for device-to-device communications. IEEE Trans. Commun. 62 (11), 3814–3824 (2014)

Zhou, J., et al.: Graph neural networks: a review of methods and applications. AI Open 1 , 57–81 (2020)

Download references

Author information

Authors and affiliations.

Department of Information Engineering, Universitá Politecnica delle Marche, Ancona, Italy

Carlo Aironi, Samuele Cornell & Stefano Squartini

You can also search for this author in PubMed   Google Scholar

Corresponding author

Correspondence to Carlo Aironi .

Editor information

Editors and affiliations.

Nottingham Trent University, Nottingham, UK

Mufti Mahmud

University Mediterranea of Reggio Calabria, Reggio Calabria, Italy

Cosimo Ieracitano

Jahangirnagar University, Dhaka, Bangladesh

M. Shamim Kaiser

Nadia Mammone

Francesco Carlo Morabito

Rights and permissions

Reprints and permissions

Copyright information

© 2022 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Cite this paper.

Aironi, C., Cornell, S., Squartini, S. (2022). Tackling the Linear Sum Assignment Problem with Graph Neural Networks. In: Mahmud, M., Ieracitano, C., Kaiser, M.S., Mammone, N., Morabito, F.C. (eds) Applied Intelligence and Informatics. AII 2022. Communications in Computer and Information Science, vol 1724. Springer, Cham. https://doi.org/10.1007/978-3-031-24801-6_7

Download citation

DOI : https://doi.org/10.1007/978-3-031-24801-6_7

Publisher Name : Springer, Cham

Online ISBN : 978-3-031-24801-6

eBook Packages : Computer Science Computer Science (R0)

Share this paper

Anyone you share the following link with will be able to read this content:

Sorry, a shareable link is not currently available for this article.

Provided by the Springer Nature SharedIt content-sharing initiative

  • Publish with us

Policies and ethics

  • Find a journal
  • Track your research

A differentiable approximation for the Linear Sum Assignment Problem with Edition

Ieee account.

  • Change Username/Password
  • Update Address

Purchase Details

  • Payment Options
  • Order History
  • View Purchased Documents

Profile Information

  • Communications Preferences
  • Profession and Education
  • Technical Interests
  • US & Canada: +1 800 678 4333
  • Worldwide: +1 732 981 0060
  • Contact & Support
  • About IEEE Xplore
  • Accessibility
  • Terms of Use
  • Nondiscrimination Policy
  • Privacy & Opting Out of Cookies

A not-for-profit organization, IEEE is the world's largest technical professional organization dedicated to advancing technology for the benefit of humanity. © Copyright 2024 IEEE - All rights reserved. Use of this web site signifies your agreement to the terms and conditions.

Help Center Help Center

  • Help Center
  • Trial Software
  • Product Updates
  • Documentation

Solve linear assignment problem

Since R2019a

Description

M = matchpairs( Cost , costUnmatched ) solves the linear assignment problem for the rows and columns of the matrix Cost . Each row is assigned to a column in such a way that the total cost is minimized. costUnmatched specifies the cost per row of not assigning each row, and also the cost per column of not having a row assigned to each column.

[ M , uR , uC ] = matchpairs( Cost , costUnmatched ) additionally returns indices for unmatched rows in uR and indices for unmatched columns in uC .

[ ___ ] = matchpairs( Cost , costUnmatched , goal ) specifies the goal of the optimization using any of the output argument combinations in previous syntaxes. goal can be 'min' or 'max' to produce matches that either minimize or maximize the total cost.

collapse all

Assign Flights with Minimal Cost

Assign salespeople to flights such that the total cost of transportation is minimized.

A company has four salespeople who need to travel to key cities around the country. The company must book their flights, and wants to spend as little money as possible. These salespeople are based in different parts of the country, so the cost for them to fly to each city varies.

This table shows the cost for each salesperson to fly to each key city.

Dallas Chicago New   York   City St.   Louis Fred $ 6 0 0 $ 6 7 0 $ 9 6 0 $ 5 6 0 Beth $ 9 0 0 $ 2 8 0 $ 9 7 0 $ 5 4 0 Sue $ 3 1 0 $ 3 5 0 $ 9 5 0 $ 8 2 0 Greg $ 3 2 5 $ 2 9 0 $ 6 0 0 $ 5 4 0

Each city represents a sales opportunity. If a city is missed, then the company loses out on an average revenue gain of $2,000.

Create a cost matrix to represent the cost of each salesperson flying to each city.

Use matchpairs to assign the salespeople to the cities with minimal cost. Specify the cost of unassignment as 1000, since the cost of unassignment is counted twice if a row and a column remain unmatched.

matchpairs calculates the least expensive way to get a salesperson to each city.

Dallas Chicago New   York   City St.   Louis Fred $ 6 0 0 $ 6 7 0 $ 9 6 0 $ 560 Beth $ 9 0 0 $ 280 $ 9 7 0 $ 5 4 0 Sue $ 310 $ 3 5 0 $ 9 5 0 $ 8 2 0 Greg $ 3 2 5 $ 2 9 0 $ 600 $ 5 4 0

Unequal Numbers of Rows and Columns

Match rows to columns when you have many more columns than rows in the cost matrix.

Create a 3-by-8 cost matrix. Since you have only three rows, matchpairs can produce at most three matches with the eight columns.

Use matchpairs to match the rows and columns of the cost matrix. To get the maximum number of matches, use a large cost of unassignment (relative to the magnitude of the entries in the cost matrix). Specify three outputs to return the indices of unmatched rows and columns.

Five of the columns in C are not matched with any rows.

Assign Taxis to Maximize Profit

Assign taxis to routes such that the profit is maximized.

A taxi company has several ride requests from across the city. The company wants to dispatch its limited number of taxis in a way that makes the most money.

This table shows the estimated taxi fare for each of five ride requests. Only three of the five ride requests can be filled.

Ride   1 Ride   2 Ride   3 Ride   4 Ride   5 Cab   A $ 5 . 7 0 $ 6 . 3 0 $ 3 . 1 0 $ 4 . 8 0 $ 3 . 5 0 Cab   B $ 5 . 8 0 $ 6 . 4 0 $ 3 . 3 0 $ 4 . 7 0 $ 3 . 2 0 Cab   C $ 5 . 7 0 $ 6 . 3 0 $ 3 . 2 0 $ 4 . 9 0 $ 3 . 4 0

Create a profits matrix to represent the profits of each taxi ride.

Use matchpairs to match the taxis to the most profitable rides. Specify three outputs to return any unmatched rows and columns, and the 'max' option to maximize the profits. Specify the cost of unassignment as zero, since the company makes no money from unfilled taxis or ride requests.

matchpairs calculates the most profitable rides to fill. The solution leaves ride requests 3 and 5 unfilled.

Calculate the total profits for the calculated solution. Since costUnmatched is zero, you only need to add together the profits from each match.

Track Point Positions over Time

Use matchpairs to track the movement of several points by minimizing the total changes in distance.

Plot a grid of points at time t = 0 in green. At time t = 1 , some of the points move a small amount in a random direction.

Figure contains an axes object. The axes object contains 2 objects of type line. One or more of the lines displays its values using only markers

Use matchpairs to match the points at t = 0 with the points at t = 1 . To do this, first calculate a cost matrix where C(i,j) is the Euclidean distance from point i to point j .

Next, use matchpairs to match the rows and columns in the cost matrix. Specify the cost of unassignment as 1. With such a low cost of unassignment relative to the entries in the cost matrix, it is likely matchpairs will leave some points unmatched.

The values M(:,2) correspond to the original points ( x 0 , y 0 ) , while the values M(:,1) correspond to the moved points ( x 1 , y 1 ) .

Plot the matched pairs of points. The points that moved farther than 2*costUnmatched away from the original point remain unmatched.

Figure contains an axes object. The axes object contains 7 objects of type line. One or more of the lines displays its values using only markers

Input Arguments

Cost — cost matrix matrix.

Cost matrix. Each entry Cost(i,j) specifies the cost of assigning row i to column j .

Data Types: single | double

costUnmatched — Cost of not matching scalar

Cost of not matching, specified as a scalar. matchpairs compares the value of 2*costUnmatched to the entries in Cost to determine whether it is more beneficial for a row or column to remain unmatched. Use this parameter to make matches more or less likely in the algorithm. For more information, see linear assignment problem .

Example: M = matchpairs(C,10) specifies a cost of 10 for not matching a row or column of C .

goal — Optimization goal 'min' (default) | 'max'

Optimization goal, specified as either 'min' or 'max' . The optimization goal specifies whether the total cost should be minimized or maximized.

Example: M = matchpairs(Cost,costUnmatched,'max') specifies that the rows and columns of Cost should be matched together to maximize the total cost.

Output Arguments

M — matches matrix.

Matches, returned as a matrix. M is a p -by- 2 matrix, where M(i,1) and M(i,2) are the row and column indices of a matched pair in the cost matrix. The rows of M are sorted with the second column in ascending order.

Each row and column can be matched a single time only, so each M(i,1) value and each M(i,2) value is unique.

M contains p matches, and p is less than or equal to the maximum number of matches min(size(Cost)) .

The cost of the matches in M is sum([Cost(M(1,1),M(1,2)), Cost(M(2,1),M(2,2)), ..., Cost(M(p,1),M(p,2))]) .

uR — Unassigned rows column vector

Unassigned rows, returned as a column vector of indices. The entries in uR indicate which rows in Cost are unassigned. Each entry in uR and uC contributes to the total cost of the solution according to costUnassigned .

uC — Unassigned columns column vector

Unassigned columns, returned as a column vector of indices. The entries in uC indicate which columns in Cost are unassigned. Each entry in uR and uC contributes to the total cost of the solution according to costUnassigned .

Linear Assignment Problem

The linear assignment problem is a way of assigning rows to columns such that each row is assigned to a column and the total cost of the assignments is minimized (or maximized). The cost of assigning each row to each column is captured in a cost matrix . The entry Cost(i,j) is the cost of assigning row i to column j .

The cost of unassignment assigns a cost to any row or column that is not matched. This practice allows for minimum-cost solutions that do not assign all rows or columns. If a row and column are not matched, this increases the total cost by 2*costUnmatched .

The total cost of a solution M is the sum of the cost of all matched pairs added to the cost of all unmatched pairs:

T C = ∑ i = 1 p Cost ( M ( i , 1 ) , M ( i , 2 ) ) + costUnmatched   ⋅   ( m + n − 2 p )

In code the total cost is

Cost is an m -by- n matrix.

M is a p -by- 2 matrix, where M(i,1) and M(i,2) are the row and column of a matched pair.

(m+n-2*p) is the total number of unmatched rows and columns.

[1] Duff, I.S. and J. Koster. "On Algorithms For Permuting Large Entries to the Diagonal of a Sparse Matrix." SIAM J. Matrix Anal. & Appl. 22(4), 2001. pp 973–996.

Extended Capabilities

C/c++ code generation generate c and c++ code using matlab® coder™..

Usage notes and limitations:

Code generation does not support sparse matrix inputs for this function.

Version History

Introduced in R2019a

equilibrate | sprank | dmperm

Open Example

You have a modified version of this example. Do you want to open this example with your edits?

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (English)

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

  • América Latina (Español)
  • Canada (English)
  • United States (English)
  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)

Contact your local office

minilsap 0.2.2

pip install minilsap Copy PIP instructions

Released: Jul 9, 2023

Python module to solve the linear sum assignment problem (LSAP) efficiently

Project links

  • Open issues:

View statistics for this project via Libraries.io , or by using our public dataset on Google BigQuery

License: BSD License (BSD 3-Clause License)

Maintainer: Tamas Nepusz

Tags lsap, munkres, kuhn-munkres, linear sum assignment problem

Requires: Python >=3.7

Maintainers

Avatar for ntamas from gravatar.com

Classifiers

  • OSI Approved :: BSD License
  • Python :: 3
  • Python :: 3.7

Project description

A Python module to solve the linear sum assignment problem (LSAP) efficiently. Extracted from SciPy, without significant modifications.

This module is useful in cases when you need an efficient LSAP solver but you do not want to depend on the full SciPy library.

Currently, the module depends on NumPy for array management. This may be relaxed in the future if Python's stable API gets extended with functions to manage Python buffer objects.

The code in this repository is licensed under the 3-clause BSD license, except for files including a different license header.

The LSAP solver copied from SciPy is also licensed under the 3-clause BSD license.

Project details

Release history release notifications | rss feed.

Jul 9, 2023

Feb 7, 2022

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages .

Source Distribution

Uploaded Jul 9, 2023 source

Built Distributions

Uploaded Jul 9, 2023 cp37

Hashes for minilsap-0.2.2.tar.gz

Hashes for minilsap-0.2.2-cp37-abi3-win_amd64.whl, hashes for minilsap-0.2.2-cp37-abi3-win32.whl, hashes for minilsap-0.2.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl, hashes for minilsap-0.2.2-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl, hashes for minilsap-0.2.2-cp37-abi3-macosx_10_9_universal2.whl.

  • português (Brasil)

Supported by

the linear sum assignment problem

Search code, repositories, users, issues, pull requests...

Provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications

Tackling the Linear Sum Assignment problem with Graph Neural Networks

aircarlo/GNN_LSAP

Folders and files, repository files navigation.

This repository contains the Python implementation of the framework described in: Tackling the Linear Sum Assignment Problem with Graph Neural Networks - Carlo Aironi, Samuele Cornell, and Stefano Squartini , where Linear Sum Assignment Problems of different dimensions are faced with a data-driven approach based on Graph Neural Networks, and accuracy is compared against two existing DNN-based frameworks.

To replicate the experiments, type python main.py followed by --help to know the startup arguments.

Requirements

  • scipy 1.8.1
  • pytorch 1.11.0
  • torch-geometric 2.0.4
  • torch-cluster 1.6.0
  • torch-scatter 2.0.9
  • torch-sparse 0.6.13
  • Python 100.0%

scipy.optimize.linear_sum_assignment ¶

Solve the linear sum assignment problem.

The cost matrix of the bipartite graph.

Calculates a maximum weight matching if true.

An array of row indices and one of corresponding column indices giving the optimal assignment. The cost of the assignment can be computed as cost_matrix[row_ind, col_ind].sum() . The row indices will be sorted; in the case of a square cost matrix they will be equal to numpy.arange(cost_matrix.shape[0]) .

for sparse inputs

The linear sum assignment problem [1] is also known as minimum weight matching in bipartite graphs. A problem instance is described by a matrix C, where each C[i,j] is the cost of matching vertex i of the first partite set (a “worker”) and vertex j of the second set (a “job”). The goal is to find a complete assignment of workers to jobs of minimal cost.

Formally, let X be a boolean matrix where \(X[i,j] = 1\) iff row i is assigned to column j. Then the optimal assignment has cost

where, in the case where the matrix X is square, each row is assigned to exactly one column, and each column to exactly one row.

This function can also solve a generalization of the classic assignment problem where the cost matrix is rectangular. If it has more rows than columns, then not every row needs to be assigned to a column, and vice versa.

This implementation is a modified Jonker-Volgenant algorithm with no initialization, described in ref. [2] .

New in version 0.17.0.

https://en.wikipedia.org/wiki/Assignment_problem

DF Crouse. On implementing 2D rectangular assignment algorithms. IEEE Transactions on Aerospace and Electronic Systems , 52(4):1679-1696, August 2016, DOI:10.1109/TAES.2016.140952

IMAGES

  1. Bipartite graph formulation of a linear sum assignment problem (LSAP

    the linear sum assignment problem

  2. Linear Equations

    the linear sum assignment problem

  3. Question Video: Evaluating the Sum of Two Linear Functions at a Given

    the linear sum assignment problem

  4. (PDF) Linear Sum Assignment with Edition

    the linear sum assignment problem

  5. Linear sum of two subspace

    the linear sum assignment problem

  6. Problem sums of linear equation class VIII Maths Live Recording Online

    the linear sum assignment problem

COMMENTS

  1. scipy.optimize.linear_sum_assignment

    The linear sum assignment problem [1] is also known as minimum weight matching in bipartite graphs. A problem instance is described by a matrix C, where each C [i,j] is the cost of matching vertex i of the first partite set (a 'worker') and vertex j of the second set (a 'job').

  2. Assignment problem

    If the total cost of the assignment for all tasks is equal to the sum of the costs for each agent (or the sum of the costs for each task, which is the same thing in this case), then the problem is called linear assignment.

  3. scipy.optimize.linear_sum_assignment

    Solve the linear sum assignment problem. The linear sum assignment problem is also known as minimum weight matching in bipartite graphs. A problem instance is described by a matrix C, where each C [i,j] is the cost of matching vertex i of the first partite set (a "worker") and vertex j of the second set (a "job").

  4. PDF Linear Sum Assignment with Edition

    Assigning the elements of some set to the elements of another, such that the resulting assignment satisfy some optimality conditions, is a fundamental combinatorial problem encountered in a wide variety of scienti c elds [10, 4]. This report focusses on linear sum assignment problems, also known as weighted bipartite graph matching problems.

  5. Linear Sum Assignment Solver

    This section describes the linear sum assignment solver, a specialized solver for the simple assignment problem, which can be faster than either the MIP or CP-SAT solver. However, the MIP...

  6. Assignment Problems

    The linear sum assignment problem (LSAP) is one of the most famous problems in linear programming and in combinatorial optimization. Informally speaking, we are given an n × n cost matrix C = ( c i j) and we want to match each row to a different column in such a way that the sum of the corresponding entries is minimized.

  7. [1603.04380] Linear Sum Assignment with Edition

    Linear Sum Assignment with Edition. We consider the problem of transforming a set of elements into another by a sequence of elementary edit operations, namely substitutions, removals and insertions of elements. Each possible edit operation is penalized by a non-negative cost and the cost of a transformation is measured by summing the costs of ...

  8. Tackling the Linear Sum Assignment Problem with Graph Neural ...

    Linear assignment [2] is a fundamental problem of combinatorial optimization; it aims to assign the elements of some finite set to the elements of another set. This is done under one-to-one matching constraints such that the resulting assignment satisfies some optimality conditions, like a minimum cost, or, in a dual way, a maximum profit.

  9. Tackling the Linear Sum Assignment Problem with Graph Neural ...

    Let the sum of the costs be the objective to be minimized, it is called Linear Sum Assignment Problem (LSAP). This kind of problem is found in many computer vision applications such as point matching [ 13 ], handwritten characters and mathematical expressions recognition [ 8 ], multi-object tracking (MOT) [ 18] and object segmentation [ 7 ].

  10. Deep Neural Networks for Linear Sum Assignment Problems

    Specifically, the linear sum assignment problems (LSAPs) are solved by the deep neural networks (DNNs). Since LSAP is a combinatorial optimization problem, it is first decomposed into several sub-assignment problems. Each of them is a classification problem and can be solved effectively with DNNs.

  11. A differentiable approximation for the Linear Sum Assignment Problem

    The Linear Sum Assignment Problem with Edition (LSAPE) extends this problem by allowing the mapping of sets of different sizes and adding the possibility to reject some matchings. This problem is set up by a rectangular cost matrix whose last column and last line encode the costs of rejecting the match of an element of respectively the first ...

  12. scipy.optimize.linear_sum_assignment

    The linear sum assignment problem is also known as minimum weight matching in bipartite graphs. A problem instance is described by a matrix C, where each C[i,j] is the cost of matching vertex i of the first partite set (a 'worker') and vertex j of the second set (a 'job'). The goal is to find a complete assignment of workers to jobs of ...

  13. Tackling the Linear Sum Assignment Problem with Graph ...

    Tackling the Linear Sum Assignment Problem with Graph Neural Networks Authors: Carlo Aironi Samuele Cornell Stefano Squartini Università Politecnica delle Marche Abstract Linear Assignment...

  14. GitHub

    The script benchmarks the performance of Python3 linear assignment problem solvers for random cost matrices of different sizes. These solvers are: linear_sum_assignment - a Python implementation of the Hungarian algorithm provided in SciPy https://github.com/scipy/scipy/

  15. Solve linear assignment problem

    M = matchpairs (Cost,costUnmatched) solves the linear assignment problem for the rows and columns of the matrix Cost. Each row is assigned to a column in such a way that the total cost is minimized. costUnmatched specifies the cost per row of not assigning each row, and also the cost per column of not having a row assigned to each column.

  16. The Assignment Problem, a NumPy function?

    7 Answers Sorted by: 17 There is now a numpy implementation of the munkres algorithm in scikit-learn under sklearn/utils/linear_assignment_.py its only dependency is numpy.

  17. minilsap · PyPI

    minilsap. A Python module to solve the linear sum assignment problem (LSAP) efficiently. Extracted from SciPy, without significant modifications. This module is useful in cases when you need an efficient LSAP solver but you do not want to depend on the full SciPy library. Currently, the module depends on NumPy for array management.

  18. GitHub

    GNN_LSAP. This repository contains the Python implementation of the framework described in: Tackling the Linear Sum Assignment Problem with Graph Neural Networks - Carlo Aironi, Samuele Cornell, and Stefano Squartini, where Linear Sum Assignment Problems of different dimensions are faced with a data-driven approach based on Graph Neural Networks, and accuracy is compared against two existing ...

  19. scipy.optimize.linear_sum_assignment

    The linear sum assignment problem is also known as minimum weight matching in bipartite graphs. A problem instance is described by a matrix C, where each C[i,j] is the cost of matching vertex i of the first partite set (a "worker") and vertex j of the second set (a "job"). The goal is to find a complete assignment of workers to jobs of ...

  20. scipy.optimize.linear_sum_assignment

    The linear sum assignment problem is also known as minimum weight matching in bipartite graphs. A problem instance is described by a matrix C, where each C[i,j] is the cost of matching vertex i of the first partite set (a "worker") and vertex j of the second set (a "job"). The goal is to find a complete assignment of workers to jobs of ...