匈牙利算法(C#)实现

本文介绍了匈牙利算法在求解二分图最大匹配问题中的应用,并提供了C#实现示例。通过创建`MaxMatch`类,实现算法的关键步骤,包括查找非饱和点、判断顶点饱和度等,最终返回最大匹配结果矩阵。
摘要由CSDN通过智能技术生成

    匈牙利算法是求二分图的最大匹配的一种算法,它的根据就是Hall定理中充分性证明中的思想。( 卢开澄,卢化明. 图论及其应用.清华大学出版社[M]1995.)

使用举例:要给定条件(二分图)和初始匹配.

int[,] TestMaxArray = new int[5, 5]{
                             {  1, 1,-1, -1, -1 },
                             { -1, 1, 1, -1, -1 },
                             { -1, 1,-1, -1,  1 },
                             { -1,-1, 1, -1, -1 },
                             { -1,-1, 1,  1,  1 }};
int[,] GivenArray = new int[5, 5]{
                             {  1, 0, 0,  0, 0 },
                             {  0, 0, 0,  0, 0 },
                             {  0, 0, 0,  0, 1 },
                             {  0, 0, 0,  0, 0 },
                             {  0, 0, 1,  0, 2 }};
MaxMatch testtest = new MaxMatch(TestMaxArray, GivenArray);//实例化
int [,] resultArray = testtest.resultArray();//结果  

下面是实现代码: MaxMatch.csusing System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace MaxMatch
{
    /// <summary>
    /// The values of Array must be -1 or 1 or 0
    /// </summary>
    public class MaxMatch
    {
        private int[,] OriginData;
        private int[,] GivenMatch;
        private int cn, rn;
        private ArrayList OldIndexOfV1, OldIndexOfV2;
        private int[] SequencedIndexOfV2, TV1;

        public MaxMatch(int[,]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值