コード例 #1
0
        private void SetParentsSameAdress(Dictionary <string, PersonWithMetadata> persons, PersonWithMetadata child, Randomizer randy)
        {
            var ninMaster = randy.Hit(50) ? child.Person.FathersNIN : child.Person.MothersNIN;
            var ninSlave  = ninMaster == child.Person.MothersNIN ? child.Person.FathersNIN : child.Person.MothersNIN;

            if (!persons.ContainsKey(ninMaster) || !persons.ContainsKey(ninSlave) || persons[ninMaster].Person?.Addresses?.Any(x => x.CurrentAddress) == null)
            {
                return;
            }

            var adress = AdressModel.Clone(persons[ninMaster].Person.Addresses.First(x => x.CurrentAddress));

            adress.NIN = ninSlave;
            var indexOfCurrentAdress = AdressModel.IndexOfCurrentAdress(persons[ninSlave].Person.Addresses);

            if (indexOfCurrentAdress == null)
            {
                persons[ninSlave].Person.Addresses = new[] { adress }
            }
            ;
            else
            {
                persons[ninSlave].Person.Addresses[indexOfCurrentAdress.Value] = adress;
            }
        }
コード例 #2
0
        private void SetChildAdressToParents(Dictionary <string, PersonWithMetadata> persons, PersonWithMetadata child, Randomizer randy)
        {
            var takeFathers = child.Person.FathersNIN != null && randy.Hit(50);
            var ninToTake   = takeFathers ? child.Person.FathersNIN : child.Person.MothersNIN;

            if (ninToTake != null && persons.ContainsKey(ninToTake) && persons[ninToTake].Person?.Addresses?.Any(x => x.CurrentAddress) != null)
            {
                var adress = AdressModel.Clone(persons[ninToTake].Person.Addresses.First(x => x.CurrentAddress));
                adress.NIN = child.Person.NIN;

                var indexOfCurrentAdress = AdressModel.IndexOfCurrentAdress(child.Person.Addresses);
                if (indexOfCurrentAdress == null)
                {
                    child.Person.Addresses = new[] { adress }
                }
                ;
                else
                {
                    child.Person.Addresses[indexOfCurrentAdress.Value] = adress;
                }
            }
        }
コード例 #3
0
        private int BringSpousesTogether(Dictionary <string, PersonWithMetadata> persons, Dictionary <string, List <RelationshipSearch> > searchDic, bool duplex, CoupleFinder coupleFinder, Randomizer randy)
        {
            var success = new List <bool>();

            while (true)
            {
                if (!searchDic.Any())
                {
                    break;
                }

                var thisSearchGroup = searchDic.First();
                if (thisSearchGroup.Value == null || !thisSearchGroup.Value.Any())
                {
                    searchDic.Remove(thisSearchGroup.Key);
                    continue;
                }

                var thisSearch = thisSearchGroup.Value.FirstOrDefault(t => !t.Taken);

                if (thisSearch == null)
                {
                    searchDic.Remove(thisSearchGroup.Key);
                    continue;
                }

                thisSearch.Taken = true;
                var thisSearchNin = thisSearch.NinRef;
                if (persons.All(p => p.Key != thisSearchNin))
                {
                    continue;
                }

                int increment = 0;
                RelationshipSearch spouseSearch = null;
                while (true) //(thisSearch.IsLookingForAgeQuant - increment > 0) && (thisSearch.IsLookingForAgeQuant + increment < 30)
                {
                    bool conductedSearch = false;

                    if (thisSearch.IsLookingForAgeQuant + increment < 30)
                    {
                        var lookingForKey = thisSearch.KeyLookingFor(increment);

                        spouseSearch = searchDic.ContainsKey(lookingForKey) ?
                                       searchDic[lookingForKey].FirstOrDefault(y => y.Taken == false && persons.ContainsKey(y.NinRef) && y.NinRef != thisSearchNin && (!duplex || y.KeyLookingFor() == thisSearch.KeyMe())) :
                                       null;

                        if (spouseSearch != null)
                        {
                            break;
                        }

                        conductedSearch = true;
                    }

                    if (thisSearch.IsLookingForAgeQuant - increment > 0)
                    {
                        var lookingForKey = thisSearch.KeyLookingFor((-1) * increment);

                        spouseSearch = searchDic.ContainsKey(lookingForKey) ?
                                       searchDic[lookingForKey].FirstOrDefault(y => y.Taken == false && persons.ContainsKey(y.NinRef) && y.NinRef != thisSearchNin && (!duplex || y.KeyLookingFor() == thisSearch.KeyMe())) :
                                       null;

                        if (spouseSearch != null)
                        {
                            break;
                        }

                        conductedSearch = true;
                    }

                    increment++;

                    if (!conductedSearch)
                    {
                        break;
                    }
                }

                if (spouseSearch == null)
                {
                    success.Add(false);
                    continue;
                }

                success.Add(true);

                persons[thisSearchNin].Person.SpouseNIN = persons[spouseSearch.NinRef].Person.NIN;

                if (duplex)
                {
                    spouseSearch.Taken = true;
                    persons[spouseSearch.NinRef].Person.SpouseNIN = persons[thisSearchNin].Person.NIN;

                    if (persons[thisSearchNin].Person.Addresses != null && persons[thisSearchNin].Person.Addresses.Any(x => x.CurrentAddress) && randy.Hit(AdressModel.PSpousesSameAdress(persons[thisSearchNin])))
                    {
                        var adress = AdressModel.Clone(persons[thisSearchNin].Person.Addresses.First(x => x.CurrentAddress));
                        adress.NIN = spouseSearch.NinRef;
                        var spouseAdressIndexToReplace = AdressModel.IndexOfCurrentAdress(persons[spouseSearch.NinRef].Person.Addresses);

                        if (spouseAdressIndexToReplace == null)
                        {
                            persons[spouseSearch.NinRef].Person.Addresses = new[] { adress }
                        }
                        ;
                        else
                        {
                            persons[spouseSearch.NinRef].Person.Addresses[spouseAdressIndexToReplace.Value] = adress;
                        }
                    }

                    coupleFinder?.RegisterMarried(persons[thisSearchNin], persons[spouseSearch.NinRef]);
                }
            }

            return((100 * success.Count(t => t)) / success.Count);
        }