当前位置:主页 > 育儿 >

c#盖尔-沙普利算法的改进-echo三毛

作者:admin 发布时间:2019-07-06 阅读:

        

        

        
        

盖尔-沙普利算法

        “盖尔-沙普利算法”(the Gale-Shapley 算法),也称为推延同意算法 算法),约分GS算法。马上盖尔和沙普利设计了市场结构来找到一私人的稳固的M。。主题(医疗机构)在主题的一侧高处开价。,每个先生大城市思索他收到的招聘通知书。,继拿你爱人的(以为可以同意),回绝引出各种从句。算法的一私人的转折点点是THA,令人使满意的开价无能耐的立即地被同意。,公正的私有财产住了。 on 至),那是推延同意。在开价被回绝后,医疗机构可以向静止医先生开价新的服务器。整个过程一向持续到缺席安排希望的事发布的新闻,到引出各种从句时分,先生们终极同意了他们本身的被卡住建议。。

在该算法的按照,加强了静止必然的元历来调停。

        1. 加强私人的评分体系,估分体系。两个当事人在完成硕士学位时的分差距不应当太大。

        2. 判离婚拮据越来越大

        3. 把持栏风险。换句话说,节俭地运用但是碰必然的女人本能。。

        原始的盖尔-沙普利算法中,操纵使满意度亲10,女性使满意度亲50。算法整齐的后单方使满意度相对地亲(整齐的比限制因素后女性使满意度甚至会高于操纵)。

        
        using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Gale-Shapley合并稳固婚配算法
//有n只雄性,M女,每私人的都有现实的分(思索到散布健康状况,私人的估分,每私人的都有对引出各种从句的评价。
//每私人的都陈列本身的受优先偿还的权利,取得你本身的天井列表(经过加或减ce接收一私人的距离。
//一圈索取,女性理智本身的使成横排和操纵使成横排同意或回绝。
//直到每私人的的代表团完毕namespace GaleShapley
{
    class Program
    {
        staticvoid Main(string[] 限制因素)
        {
            Marry marry = new Marry(200, 200);
            int number = marry.MaleDic.Count;
            marry.Start();
            ("MaleSatisfaction : " + );
            ("FeMaleSatisfaction : " + );
            //(操纵IDT分使满意度女性IDT分使满意度)
            //foreach (男 male in marry.MaleDic.Values)
            //{
            //    if (!)
            //    {
            //        continue;
            //    }
            //    Female female = [];
            //    (male.ID + "	" + () + "	" + () + "	" + 
            //        female.ID + "	" + fe() + "	" + fe());
            //}
            //List maleList = ((p => !)).ToList();
            //List femaleList = (.Values.Where(p => !)).ToList();
            //for (利钱 i = 0; i < maleList.Count; i++)
            //{
            //    Male male = maleList[i];
            //    Female female = femaleList[i];
            //    (male.ID + "	" + () + "	" + () + "	" +
            //       female.ID + "	" + fe() + "	" + fe());
            //}            ();
        }
    }
    publicstaticclass DoubleExtendMethod
    {
        publicstaticstring ToMyString(thisdouble 数字)
        {
            return num.ToString("0.##");
        }
    }
    ////// 索取情人
    ///publicclass RequestObj
    {
        ////// 情人编号
        ///publicint ID { get; privateset; }
        ////// 对本身心目说话中肯事物的评价
        ///publicdouble EstimatePoint { get; privateset; }

        public RequestObj(int id, double estimatePoint)
        {
            this.ID = id;
            this.EstimatePoint = estimatePoint;
        }
    }
    publicclass People
    {
        privatestaticdouble MaxPoint = 1000;
        privatestaticdouble MinPoint = 200;
        ////// 私人的编号
        ///publicint ID { get; set; }
        ////// 匹偶号码
        ///publicint PartnerID { get; set; }
        publicbool Marryed
        {
            get
            {
                returnthis.PartnerID < 0 ? false : true;
            }
        }
        ////// 现实得分
        ///publicdouble Point { get; set; }
        ////// 私人的估分
        ///publicdouble MyEstimatePoint { get; set; }
        ////// 匹偶得分
        ///publicdouble PartnerEstimatePoint { get; set; }
        ////// 使满意度
        ///publicdouble Satisfaction
        {
            get
            {
                if (!this.Marryed)
                {
                    return0;
                }
                //很难找到右手的办法来计算使满意度double mul = (this.MyEstimatePoint - this.PartnerEstimatePoint) / People.MaxPoint;
                if (this.MyEstimatePoint > this.PartnerEstimatePoint)
                {
                    return50.0 * (1 - 多种用途的)
                }
                else
                {
                    return50.0 * (1 + 多种用途的)
                }
            }
        }
        public People(int ID)
        {
            this.PartnerID = -1;
            this.ID = id;
            this.Point = Double() * (People.MaxPoint - People.MinPoint) + People.MinPoint;   //私人的得分从0到100,平分散布this.MyEstimatePoint = (this.Point);
        }

        ////// 估分体系
        //////        现实得分///估分publicstaticdouble GetEstimatePoint(double 点)
        {
            //return point;double mul =  + Double() * 0.4;    //把持分为80% - 120% 经过return point * mul;
        }
    }
    publicclass Male : People
    {
        public List RequestList { get; set; }
        public Male(int ID)
            : base(ID)
        {

        }
        publicvoid InitRequestList(Dictionary<int, Female> femaleDic)
        {
            this.RequestList = new List();
            foreach (女) female in femaleDic.Values)
            {
                if ((10) != 1)//把持这私人的能区域的女性人数,眼前,所有权的排序都是类似于的,它可以被私人的的应酬能耐所移动。                {
                    continue;
                }
                double point = ();//共同的等级if (点 > this.MyEstimatePoint)
                {
                    double mul = (点 - this.MyEstimatePoint) / this.MyEstimatePoint;
                    if (多种用途的/逻辑学与素养) < )
                    {
                        this.RequestList.Add(new RequestObj(female.ID, 点));
                    }
                }
                else
                {
                    double mul = (this.MyEstimatePoint - 点) / this.MyEstimatePoint;
                    if (多种用途的/逻辑学与素养) < )
                    {
                        this.RequestList.Add(new RequestObj(female.ID, 点));
                    }
                }
            }
            this.RequestList = this.RequestList.OrderByDescending(a => ).ToList();//递减次序        }

        ////// 做出计划
        //////        ///        publicvoid 索取(字典<int, Male> maleDic, Dictionary<int, Female> femaleDic)
        {
            if (this.Marryed)
            {
                return;
            }
            if (this.RequestList.Count == 0)
            {
                return;
            }
            Female female = femaleDic[this.RequestList[0身份证]
            if ((this, maleDic))
            {
                this.PartnerID = female.ID;
                this.PartnerEstimatePoint = this.RequestList[0].EstimatePoint;
            }
            this.RequestList.RemoveAt(0);
        }

        ////// 判离婚
        ///publicvoid Divorce()
        {
            this.PartnerID = -1;
            this.PartnerEstimatePoint = 0;
        }
    }
    publicclass Female : People
    {
        public Female(int ID)
            : base(ID)
        {

        }

        publicbool BeRequest(男 male, Dictionary<int, Male> maleDic)
        {
            double estimatePoint = ();//得分候选人提拔会if (this.Marryed)//与匹偶比较地            {
                if (this.PartnerEstimatePoint < estimatePoint)
                {
                    double difference = estimatePoint / this.PartnerEstimatePoint;
                    if (差别 > )
                    {
                        maleDic[this.PartnerID].Divorce();
                        this.PartnerID = male.ID;
                        this.PartnerEstimatePoint = estimatePoint;
                        returntrue;
                    }
                }
                returnfalse;
            }
            else//未婚            {
                if (estimatePoint > (this.MyEstimatePoint * ))
                {
                    this.PartnerID = male.ID;
                    this.PartnerEstimatePoint = estimatePoint;
                    returntrue;
                }
                returnfalse;
            }
        }
    }
    publicclass Marry
    {
        ////// 运用的随机数字大局
        ///publicstatic Random Rnd = new Random();
        public Dictionary<int, Male> MaleDic { get; set; }
        public Dictionary<int, Female> FemaleDic { get; set; }
        ////// 已婚数
        ///publicint MarriageCount
        {
            get
            {
                int count = 0;
                foreach (男 male inthis.MaleDic.Values)
                {
                    if ()
                    {
                        count++;
                    }
                }
                return count;
            }
        }
        ////// 单曲数
        ///publicint SingleCount
        {
            get
            {
                returnthis.MaleDic.Count + this.FemaleDic.Count - this.MarriageCount * 2;
            }
        }
        publicdouble MaleSatisfaction
        {
            get
            {
                double satisfaction = 0;
                foreach (男 male inthis.MaleDic.Values)
                {
                    satisfaction += 
                }
                return satisfaction / this.MaleDic.Count;
            }
        }
        publicdouble FemaleSatisfaction
        {
            get
            {
                double satisfaction = 0;
                foreach (女) female inthis.FemaleDic.Values)
                {
                    satisfaction += fe
                }
                return satisfaction / this.FemaleDic.Count;
            }
        }
        ////// 需求持续婚配
        ///publicbool NeedMatch
        {
            get
            {
                foreach (男 male inthis.MaleDic.Values)
                {
                    if (List.Count > 0 && !)
                    {
                        returntrue;
                    }
                }
                returnfalse;
            }
        }
        public Marry(int maleNum, int femaleNum)
        {
            this.MaleDic = new Dictionary<int, Male>();
            this.FemaleDic = new Dictionary<int, Female>();
            for (int i = 0; i < maleNum; i++)
            {
                (i, new 男(一)
            }
            for (int i = 0; i < femaleNum; i++)
            {
                (i, new 女(一)
            }
            foreach (男 male inthis.MaleDic.Values)
            {
                (this.FemaleDic);
            }
        }
        publicvoid Start()
        {
            while (this.NeedMatch)
            {
                foreach (男 male inthis.MaleDic.Values)
                {
                    (this.MaleDic, this.FemaleDic);
                }
            }
        }
    }
}

关键词:

    推荐图文

    最新文章