# Assignment problem

Contents
[hide]
y y y y y

1 Algorithms and generalizations 2 Example 3 Formal mathematical definition 4 See also 5 Further reading

 Algorithms and generalizations
The Hungarian algorithm is one of many algorithms that have been devised that solve the linear assignment problem within time bounded by a polynomial expression of the number of agents. The assignment problem is a special case of the transportation problem, which is a special case of the minimum cost flow problem, which in turn is a special case of a linear program. While it is possible to solve any of these problems using the simplex algorithm, each specialization has more efficient algorithms designed to take advantage of its special structure. If the cost function involves quadratic inequalities it is called the quadratic assignment problem.

However. so that the cost function is written down as: The problem is "linear" because the cost function to be optimized as well as all the constraints contain only linear terms. is minimized. or maximizing profit rather than minimizing cost. with a cost of 0 for the taxi assigned to it. A and T. Then a fourth dummy task can be invented. together with a weight function C : A × T Find a bijection f : A T such that the cost function: R. The assignment problem can then be solved in the usual way and still give the best solution to the problem. Usually the weight function is viewed as a square real-valued matrix C. Example Suppose that a taxi firm has three taxis (the agents) available. and three customers (the tasks) wishing to be picked up as soon as possible. of equal size. In the above example. Similar tricks can be played in order to allow more tasks than agents. The problem can be expressed as a standard linear program with the objective function subject to the constraints . tasks to which multiple agents must be assigned (for instance. so for each taxi the "cost" of picking up a particular customer will depend on the time taken for the taxi to reach the pickup point. perhaps called "sitting still doing nothing". the assignment problem can be made rather more flexible than it first appears. but still only three customers.  Formal mathematical definition The formal definition of the assignment problem (or linear assignment problem) is Given two sets. The firm prides itself on speedy pickups. The solution to the assignment problem will be whichever combination of taxis and customers results in the least total cost. a group of more customers than will fit in one taxi). suppose that there are four taxis available.

James Munkres reviewed the algorithm in 1957 and observed that it is (strongly) polynomial. search The Hungarian method is a combinatorial optimization algorithm which solves the assignment problem in polynomial time and which anticipated later primal-dual methods. however Edmonds and Karp. and the second constraint requires that every task is assigned exactly one agent. . The variable xij represents the assignment of agent i to task j. taking value 1 if the assignment is done and 0 otherwise. This formulation allows also fractional variable values. This is because the constraint matrix is totally unimodular. and independently Tomizawa noticed that it can be modified to achieve an O(n3) running time. Ford and Fulkerson extended the method to general transportation problems. Hungarian algorithm From Wikipedia. The first constraint requires that every agent is assigned to exactly one task. who gave the name "Hungarian method" because the algorithm was largely based on the earlier works of two Hungarian mathematicians: Dénes K nig and Jen Egerváry. and published posthumously in 1890 in Latin. In 2006.[1] Contents [hide] y y y y y y y 1 Layman¶s Explanation 2 Setting 3 The algorithm in terms of bipartite graphs 4 Matrix interpretation 5 Bibliography 6 References 7 External links . the free encyclopedia Jump to: navigation. It was developed and published by Harold Kuhn in 1955. .for for for . Since then the algorithm has been known also as Kuhn-Munkres algorithm or Munkres assignment algorithm. The time complexity of the original algorithm was O(n4). it was discovered that Carl Gustav Jacobi had solved the assignment problem in the 19th century. but there is always an optimal solution where the variables take integer values.

1 Implementations  Layman¶s Explanation Say you have three workers: Jim. when applied to the above table would give us the minimum cost it can be done with: Jim cleans the bathroom. What¶s the best (minimumcost) way to assign the jobs? First we need a matrix of the costs of the workers doing the jobs. We want to find a perfect matching with minimum cost. Steve and Alan.o 7.[2] The algorithm is easier to describe if we formulate the problem using a bipartite graph. T.  The algorithm in terms of bipartite graphs . another sweep the floors & the third wash the windows.j). It can be seen that the cost of each perfect matching is at least the value of each potential. We have a complete bipartite graph G=(S. the problem can be altered to fit the setting by replacing each cost with the maximum cost subtracted by the cost. The cost of a perfect matching in Gy (if there is one) equals the value of y. Steve sweeps the floors and Alan washes the windows. If the goal is to find the assignment that yields the maximum cost. Clean bathroom Sweep floors Wash windows \$1 \$2 \$3 \$3 \$3 \$3 \$2 Jim Steve \$3 Alan \$3 Then the Hungarian algorithm. The Hungarian method finds a perfect matching and a potential with equal cost/value which proves the optimality of both. and each edge has a nonnegative cost c(i. 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. In fact it finds a perfect matching of tight edges: an edge ij is called tight for a potential y if y(i) + y(j) = c(i. We have to find an assignment of the jobs to the workers that has minimum cost.j). The value of potential y is .  Setting We are given a nonnegative n×n matrix. Let us call a function a potential if for each . E) with n worker vertices (S) and n job vertices (T). You need to have one of them clean the bathroom. Let us denote the subgraph of tight edges by Gy.

The resulting y is still a potential. either we modify y so that its value increases. but it still contains M. then reverse the orientation of a directed path in Thus the size of the corresponding matching increases by 1.  Matrix interpretation Given n workers and tasks. . there are at most n potential changes (since Z increases every time). This can be computed by breadth-first search. We repeat these steps until M is a perfect matching. Increase y by on the vertices of and decrease y by on the vertices of . then let from RS to RT.During the algorithm we maintain a potential y and an orientation of Gy (denoted by ) which has the property that the edges oriented from T to S form a matching M. and an n×n matrix containing the cost of assigning each worker to a task. By the definition of the set Z of vertices reachable from RS increases (note that the number of tight edges does not necessarily increase). y is 0 everywhere. First the problem is written in the form of a matrix as given below . let and be the vertices not covered by M (so RS consists of the vertices in S with no incoming edge and RT consists of the vertices in T with no outgoing edge). and in a phase where M is unchanged. The time needed for a potential change is O(n2). The graph Gy changes. in which case it gives a minimum cost assignment. Initially. In each step. and all edges are oriented from S to T (so M is empty). The running time of this version of the method is O(n4): M is augmented n times. find the cost minimizing assignment. In a general step. Let Z be the set of vertices reachable in from RS by a directed path only following edges that are tight. We are done if M is a perfect matching. We maintain the invariant that all the edges of M are tight. is positive because there are no tight edges between and . If is empty. We orient the new edges from S to T. or modify the orientation to obtain a matching with more edges. If is nonempty.