Binary Chart Hungarian algorithm template

Source: Internet
Author: User

Maximum matches: the number of matching edges that match the maximum

Minimum point coverage: Select a minimum point so that at least one end of any edge is selected

Maximum independent number: Select the most points so that any selected two points are not connected

Minimum path coverage: For a DAG (directed acyclic graph), select the fewest paths so that each vertex belongs to and belongs to only one path. The path length can be 0 (that is, a single point).

Theorem 1: Maximum number of matches = minimum point coverage (this is the Konig theorem)

Theorem 2: Maximum number of matches = maximum Independent number

Theorem 3: Minimum path coverage = number of vertices-maximum number of matches


const int n=555;///The maximum number of bool Tu[n][n];int from[n];///records to the right of the point if it is paired well where it comes from bool use[n];///record to the right of the point whether it has completed pairing int n,m;///m, n represents the respective number of sides, N is the left, M is the right bool Dfs (int x) {    for (int i=1;i<=m;i++)///m is the right, so the upper bound is M    if (!use[i]&&tu[x] [i])    {        use[i]=1;        if (from[i]==-1| | DFS (From[i]))        {            from[i]=x;            return 1;        }    }    return 0;} int Hungary () {    int tot=0;    Memset (From,-1,sizeof (from));    for (int i=1;i<=n;i++)///n is left, so here the upper bound is n    {        memset (use,0,sizeof (use));        if (Dfs (i))            tot++;    }    return tot;}

can also be changed into vector version, the method is more flexible.



Binary Chart Hungarian algorithm template

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.