Ungarische Methode Technische Universität München
Bipartiter Graph mit Kantengewichten

What's the optimal matching?

Matchings of optimal Weight

We extend the example of matching students to appropriate jobs by introducing preferences. Now, we aim to find a matching that will fulfill each students preference (to the maximum degree possible).

Finding matchings between elements of two distinct classes is a common problem in mathematics. In this case, we consider weighted matching problems, i.e. we look for matchings with optimal edge weights.

The Hungarian Method, which we present here, will find optimal matchings in bipartite graphs.

What do you want to do first?


SVG Download

Legend

Knoten Node
Knoten Edge

Legend

Which graph do you want to execute the algorithm on?

Start with an example graph:

Modify it to your desire:

  • Double click in the area of one of the partitions, in order to add a vertex to that partition. You can create up to 8 nodes in each partition.
  • In order to create an edge, first click on the origin node, then on the destination node.
  • You can only create edges between separate partitions. You can change the weight of an edge by double clicking the middle of the edge and entering the new weight.
  • Right-clicking will delete edges or nodes.

Download the modified graph:

Download

Upload an existing graph:

A

occured when reading from file:

the contents:

                    

What next?

SVG Download

Legend

MatchedNode Matched Node
Knoten Matching Edge

Legend

Current State of the Algorithm

BEGIN

initialize labels

WHILE matching is not complete DO

find a root of an alternating path

WHILE alternating path not found DO

try to find alternating path

in equality graph

IF alt. path not found

THEN update labels

END

increase matching

END

END

Current state of the variables:

Matching S T

If you switch tabs, the execution will be terminated.

You can open another browser window to read the description in parallel.

SVG Download

Legend

MatchedNode Matched Node
Knoten Matching Edge

Legend

Test your Knowledge: What would the algorithm do?


BEGIN

initialize labels

WHILE matching is not complete DO

find a root of an alternating path

WHILE alternating path not found DO

try to find alternating path

in equality graph

IF alt. path not found

THEN update labels

END

increase matching

END

END

State of the variables:

Matching S T

If you switch tabs, the execution will be terminated.

You can open another browser window to read the description in parallel.

SVG Download

Legend

MatchedNode Matched Node
Knoten Matching Edge

Legend

Test your Knowledge: What would the algorithm do?


BEGIN

initialize labels

WHILE matching is not complete DO

find a root of an alternating path

WHILE alternating path not found DO

try to find alternating path

in equality graph

IF alt. path not found

THEN update labels

END

increase matching

END

END

State of the variables:

Matching S T

Task is terminated if the tab is changed.

You can open another browser window for reading the description in parallel.