Artin reciprocity law: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Mark viking
en>Ncsinger
 
Line 1: Line 1:
The '''Hungarian method''' is a [[combinatorial optimization]] [[algorithm]] that solves the [[assignment problem]] in [[polynomial time]] and which anticipated later [[primal-dual method]]s. It was developed and published by [[Harold Kuhn]] in 1955, who gave the name "Hungarian method" because the algorithm was largely based on the earlier works of two [[Hungary|Hungarian]] mathematicians: [[Dénes Kőnig]] and [[Jenő Egerváry]].<ref name="kuhn1955">Harold W. Kuhn, "The Hungarian Method for the assignment problem", ''[[Naval Research Logistics Quarterly]]'', '''2''':83&ndash;97, 1955.  Kuhn's original publication.</ref><ref name="kuhn1956">Harold W. Kuhn, "Variants of the Hungarian method for assignment problems", ''Naval Research Logistics Quarterly'', '''3''': 253&ndash;258, 1956.</ref>
Hello and welcome. My name is Numbers Wunder. California is exactly where her home is but she needs to transfer simply because of her family members. Supervising is my occupation. To collect coins is what his family and him enjoy.<br><br>Also visit my website [http://www.hotporn123.com/blog/150819 www.hotporn123.com]
 
[[James Munkres]] reviewed the algorithm in 1957 and observed that it is [[Time complexity#Strongly_and_weakly_polynomial_time|(strongly) polynomial]].<ref name="munkres">J. Munkres, "Algorithms for the Assignment and Transportation Problems", ''[[Journal of the Society for Industrial and Applied Mathematics]]'', '''5'''(1):32&ndash;38, 1957 March.</ref> Since then the algorithm has been known also as '''Kuhn–Munkres algorithm''' or '''Munkres assignment algorithm'''. The [[Computational_complexity_theory#Time_and_space_complexity|time complexity]] of the original algorithm was <math>O(n^4)</math>, however [[Jack Edmonds|Edmonds]] and [[Richard Karp|Karp]], and independently Tomizawa noticed that it can be modified to achieve an <math>O(n^3)</math> running time. [[L. R. Ford, Jr.|Ford]] and [[D. R. Fulkerson|Fulkerson]] extended the method to general transportation problems. In 2006, it was discovered that [[Carl Gustav Jacobi]] had
solved the assignment problem in the 19th century, and the solution had been published posthumously in 1890 in Latin.<ref>http://www.lix.polytechnique.fr/~ollivier/JACOBI/jacobiEngl.htm</ref>
 
==Layman’s Explanation of the Assignment Problem==
Say you have three workers: '''Jim''', '''Steve''' and '''Alan'''.
You need to have one of them clean the bathroom, another sweep the floors & the third wash the windows.
What’s the best (minimum-cost) way to assign the jobs?
First we need a [[Matrix (mathematics)|matrix]] of the costs of the workers doing the jobs.
{| class="wikitable" border="1"
|-
!
! Clean bathroom
! Sweep floors
! Wash windows
|-
| Jim
| $1
| $3
| $3
|-
| Steve
| $3
| $2
| $3
|-
| Alan
| $3
| $3
| $2
|}
 
Then the Hungarian method, when applied to the above table would give us the minimum cost it can be done with: Jim cleans the bathroom, Steve sweeps the floors and Alan washes the windows.
 
==Setting==
We are given a nonnegative ''n''×''n'' [[Matrix (mathematics)|matrix]], where the element in the ''i''-th row and ''j''-th column represents the cost of assigning the ''j''-th job to the ''i''-th worker. We have to find an assignment of the jobs to the workers that has minimum cost. If the goal is to find the assignment that yields the maximum cost, the problem can be altered to fit the setting by replacing each cost with the maximum cost subtracted by the cost.
 
The algorithm is easier to describe if we formulate the problem using a bipartite graph. We have a [[complete bipartite graph]] ''G=(S, T; E)'' with ''n'' worker vertices (''S'') and ''n'' job vertices (''T''), and each edge has a nonnegative cost ''c(i,j)''. We want to find a [[perfect matching]] with minimum cost.
 
Let us call a function <math>y: (S \cup T) \mapsto \mathbb{R}</math> a '''potential''' if <math>y(i)+y(j) \leq c(i, j)</math> for each <math>i \in S, j \in T</math>. The value of potential ''y'' is <math>\sum_{v\in S\cup T} y(v)</math>. It can be seen that the cost of each perfect matching is at least the value of each potential. The Hungarian method finds a perfect matching and a potential with equal cost/value which proves the optimality of both. In fact it finds a perfect matching of '''tight edges''': an edge ''ij'' is called tight for a potential ''y'' if <math>y(i)+y(j) = c(i, j)</math>. Let us denote the [[Glossary of graph theory#Subgraphs|subgraph]] of tight edges by <math>G_y</math>. The cost of a perfect matching in <math>G_y</math> (if there is one) equals the value of ''y''.
 
==The algorithm in terms of bipartite graphs==
During the algorithm we maintain a potential ''y'' and an [[Glossary_of_graph_theory#Direction|orientation]] of <math>G_y</math> (denoted by <math>\overrightarrow{G_y}</math>) which has the property that the edges oriented from ''T'' to ''S'' form a matching ''M''. Initially, ''y'' is 0 everywhere, and all edges are oriented from ''S'' to ''T'' (so ''M'' is empty). In each step, either we modify ''y'' so that its value increases, or modify the orientation to obtain a matching with more edges. We maintain the invariant that all the edges of ''M'' are tight.  We are done if ''M'' is a perfect matching.
 
In a general step, let <math>R_S \subseteq S</math> and <math>R_T \subseteq T</math> be the vertices not covered by ''M'' (so
<math>R_S</math> consists of the vertices in ''S'' with no incoming edge and <math>R_T</math> consists of the vertices in ''T'' with no outgoing edge). Let <math>Z</math> be the set of vertices reachable in <math>\overrightarrow{G_y}</math> from <math>R_S</math> by a directed path only following edges that are tight. This can be computed by [[breadth-first search]].
 
If <math>R_T \cap Z</math> is nonempty, then reverse the orientation of a directed path in <math>\overrightarrow{G_y}</math> from <math>R_S</math> to <math>R_T</math>. Thus the size of the corresponding matching increases by 1.
 
If <math>R_T \cap Z</math> is empty, then let <math>\Delta := \min \{c(i,j)-y(i)-y(j): i \in Z \cap S, j \in T \setminus Z\}</math>. <math>\Delta</math> is positive because there are no tight edges between <math>Z \cap S</math> and <math>T \setminus Z</math>. Increase ''y'' by <math>\Delta</math> on the vertices of <math>Z \cap S</math> and decrease ''y'' by <math>\Delta</math> on the vertices of <math>Z \cap T</math>. The resulting ''y'' is still a potential. The graph <math>G_y</math> changes, but it still contains ''M''. We orient the new edges from ''S'' to ''T''. By the definition of <math>\Delta</math> the set ''Z'' of vertices reachable from <math>R_S</math> increases (note that the number of tight edges does not necessarily increase).
 
We repeat these steps until ''M'' is a perfect matching, in which case it gives a minimum cost assignment. The running time of this version of the method is <math>O(n^4)</math>: ''M'' is augmented ''n'' times, and in a phase where ''M'' is unchanged, there are at most ''n'' potential changes (since ''Z'' increases every time). The time needed for a potential change is <math>O(n^2)</math>.
 
==Matrix interpretation==
Given <math>n</math> workers and tasks, and an ''n''×''n''  matrix containing the cost of assigning each worker to a task, find the cost minimizing assignment.
 
First the problem is written in the form of a matrix as given below
 
:<math>\begin{bmatrix}
a1 & a2 & a3 & a4\\
b1 & b2 & b3 & b4\\
c1 & c2 & c3 & c4\\
d1 & d2 & d3 & d4\end{bmatrix}</math>
 
where a, b, c and d are the workers who have to perform tasks 1, 2, 3 and 4. a1, a2, a3, a4 denote the penalties incurred when worker "a" does task 1, 2, 3, 4 respectively. The same holds true for the other symbols as well. The matrix is square, so each worker can perform only one task.
 
'''Step 1'''
 
Then we perform row operations on the matrix. To do this, the lowest of all ''a<sub>i</sub>'' (i belonging to 1-4) is taken and is subtracted from each element in that row. This will lead to at least one zero in that row (We get multiple zeros when there are two equal elements which also happen to be the lowest in that row). This procedure is repeated for all rows. We now have a matrix with at least one zero per row. Now we try to assign tasks to agents such that each agent is doing only one task and  the penalty incurred in each case is zero. This is illustrated below.
 
{|class="wikitable" style="text-align:center"
|-
|0  ||a2'||0' ||a4'
|-
|b1'||b2'||b3'||0'
|-
|0' ||c2'||c3'||c4'
|-
|d1'||0' ||d3'||d4'
|}
 
The zeros that are indicated as 0' are the assigned tasks.
 
'''Step 2'''
 
Sometimes it may turn out that the matrix at this stage cannot be used for assigning, as is the case in for the matrix below.
 
{|class="wikitable" style="text-align:center"
|-
|0  ||a2'||a3'||a4'
|-
|b1'||b2'||b3'||0
|-
|0  ||c2'||c3'||c4'
|-
|d1'||0  ||d3'||d4'
|}
 
In the above case, no assignment can be made. Note that task 1 is done efficiently by both agent a and c. Both can't be assigned the same task. Also note that no one does task 3 efficiently.
To overcome this, we repeat the above procedure for all columns (i.e. the minimum element in each column is subtracted from all the elements in that column) and then check if an assignment is possible.
 
'''Step 3'''
 
In most situations this will give the result, but if it is still not possible to assign then all zeros in the matrix must be covered by marking as few rows and/or columns as possible. The following procedure is one way to accomplish this:
 
Initially assign as many tasks as possible then do the following (assign tasks in rows 2, 3 and 4)
 
{|class="wikitable" style="text-align:center"
|-
|0  ||a2'||a3'||a4'
|-
|b1'||b2'||b3'||0'
|-
|0' ||c2'||c3'||c4'
|-
|d1'||0' ||0||d4'
|}
 
Mark all rows having no assignments (row 1). Then mark all columns having zeros in marked row(s) (column 1). Then mark all rows having assignments in marked columns (row 3). Repeat this until a closed loop is obtained.
 
<!-- this might need to make the borders go away, if the current appearance is thought to be ugly -->
{|class="wikitable" style="text-align:center"
|- style="background: white"
|&times;  || || || ||
|-
|0  ||a2'||a3'||a4'
|style="background: white"|&times;
|-
|b1'||b2'||b3'||0'
|style="background: white"|
|-
|0' ||c2'||c3'||c4'
|style="background: white"|&times;
|-
|d1'||0' ||0||d4'
|style="background: white"|
|}
 
Now draw lines through all marked columns and unmarked rows.
 
{|class="wikitable" style="text-align:center"
|- style="background: white"
|&times;  || || || ||
|-
|style="background:lightgrey"|0  ||a2'||a3'||a4'
|style="background: white"|&times;
|- style="background:lightgrey"
|b1'||b2'||b3'||0'
|-
|style="background:lightgrey"|0' ||c2'||c3'||c4'
|style="background: white"|&times;
|- style="background:lightgrey"
|d1'||0' ||0||d4'
|}
 
The aforementioned detailed description is just one way to draw the minimum number of lines to cover all the 0's. Other methods work as well.
 
'''Step 4'''
 
From the elements that are left, find the lowest value. Subtract this from every unmarked element and add it to every element covered by two lines.
 
Repeat the procedure (steps 3–4) until an assignment is possible; this is when the minimum number of lines used to cover all the 0's is equal to the max(number of people, number of assignments), assuming dummy variables (usually the max cost) are used to fill in when the number of people is greater than the number of assignments.
 
Basically you find the second minimum cost among the two rows. The procedure is repeated until you are able to distinguish among the workers in terms of least cost.
 
==Bibliography==
* R.E. Burkard, M. Dell'Amico, S. Martello: ''Assignment Problems'' (Revised reprint). SIAM, Philadelphia (PA.) 2012. ISBN 978-1-61197-222-1
* M. Fischetti, "Lezioni di Ricerca Operativa", Edizioni Libreria Progetto Padova, Italia, 1995.
* [[Ravindra K. Ahuja|R. Ahuja]], [[Thomas L. Magnanti|T. Magnanti]], [[James B. Orlin|J. Orlin]], "Network Flows", Prentice Hall, 1993.
 
==References==
{{Reflist}}
 
==External links==
* Bruff, Derek, "The Assignment Problem and the Hungarian Method", [http://www.math.harvard.edu/archive/20_spring_05/handouts/assignment_overheads.pdf]
* Mordecai J. Golin, [http://www.cse.ust.hk/~golin/COMP572/Notes/Matching.pdf Bipartite Matching and the Hungarian Method], Course Notes, [[Hong Kong University of Science and Technology]].
* [[R. A. Pilgrim]], ''[http://csclab.murraystate.edu/bob.pilgrim/445/munkres.html Munkres' Assignment Algorithm. Modified for Rectangular Matrices]'', Course notes, [[Murray State University]].
* [[Mike Dawes]], ''[http://www.math.uwo.ca/~mdawes/courses/344/kuhn-munkres.pdf The Optimal Assignment Problem]'', Course notes, [[University of Western Ontario]].
* [http://www.cs.elte.hu/egres/tr/egres-04-14.pdf On Kuhn's Hungarian Method – A tribute from Hungary], [[András Frank]], Egervary Research Group, Pazmany P. setany 1/C, H1117, Budapest, Hungary.
* Lecture: [https://www.youtube.com/watch?v=BUGIhEecipE Fundamentals of Operations Research - Assignment Problem - Hungarian Algorithm], Prof. G. Srinivasan, Department of Management Studies, IIT Madras.
* Extension: [http://www.roboticsproceedings.org/rss06/p16.html Assignment sensitivity analysis (with O(n^4) time complexity)], Liu, Shell.
* [http://www.hungarianalgorithm.com/solve.php Solve any Assignment Problem online], provides a step by step explanation of the Hungarian Algorithm.
 
===Implementations===
(Note that not all of these satisfy the <math>O(n^3)</math> time constraint.)
* [https://github.com/maandree/hungarian-algorithm-n3/blob/master/hungarian.c C implementation with <math>O(n^3)</math> time complexity]
* [https://github.com/KevinStern/software-and-algorithms/blob/master/src/main/java/blogspot/software_and_algorithms/stern_library/optimization/HungarianAlgorithm.java Java implementation of <math>O(n^3)</math> time variant]
* [http://konstantinosnedas.com/dev/soft/munkres.htm Java implementation]
* [http://software.clapper.org/munkres/ Python implementation] (see also [https://github.com/xtof-durr/makeSimple/blob/master/Munkres/kuhnMunkres.py here])
* [http://github.com/evansenter/gene/blob/f515fd73cb9d6a22b4d4b146d70b6c2ec6a5125b/objects/extensions/hungarian.rb Ruby implementation with unit tests]
* [http://noldorin.com/blog/2009/09/hungarian-algorithm-in-csharp/ C# implementation]
* [http://www.fantascienza.net/leonardo/so/hungarian.d D implementation with unit tests (port of the Java <math>O(n^3)</math> version)]
* [http://www.ifors.ms.unimelb.edu.au/tutorial/hungarian/welcome_frame.html Online interactive implementation] Please note that this implements a variant of the algorithm as described above.
* [http://web.axelero.hu/szilardandras/gaps.html Graphical implementation with options] ([[Java applet]])
* [http://www.netlib.org/utk/lsi/pcwLSI/text/node220.html Serial and parallel implementations.]
* [http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=6543 Implementation in Matlab and C]
* [https://metacpan.org/module/Algorithm::Munkres Perl implementation]
* [http://www.koders.com/lisp/fid7C3730AF4E356C65F93F20A6410814CBF5F40854.aspx?s=iso+3166 Lisp implementation]
* [http://students.cse.tamu.edu/lantao/codes/codes.php C++ (STL) implementation (multi-functional bipartite graph version)]
* [http://saebyn.info/2007/05/22/munkres-code-v2/ C++ implementation]
* [http://dlib.net/optimization.html#max_cost_assignment C++ implementation of the <math>O(n^3)</math> algorithm] (BSD style open source licensed)
* [http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=hungarianAlgorithm Another C++ implementation with unit tests]
* [http://timefinder.svn.sourceforge.net/viewvc/timefinder/trunk/timefinder-algo/src/main/java/de/timefinder/algo/roomassignment/ Another Java implementation with JUnit tests (Apache 2.0)]
* [http://www.mathworks.com/matlabcentral/fileexchange/11609 MATLAB implementation]
* [https://launchpad.net/lib-bipartite-match C implementation]
* [http://twofourone.blogspot.com/2009/01/hungarian-algorithm-in-javascript.html Javascript implementation]
* [http://cran.r-project.org/web/packages/clue/clue.pdf  The clue R package proposes an implementation, solve_LSAP]
{{Use dmy dates|date=September 2010}}
 
{{DEFAULTSORT:Hungarian Algorithm}}
[[Category:Matching]]
[[Category:Combinatorial optimization]]

Latest revision as of 22:49, 9 January 2015

Hello and welcome. My name is Numbers Wunder. California is exactly where her home is but she needs to transfer simply because of her family members. Supervising is my occupation. To collect coins is what his family and him enjoy.

Also visit my website www.hotporn123.com