Exemplo n.º 1
0
        public static void GetCouplesTest(int[] input, int sum, string dataName)
        {
            List <int[]> couples = CoupleFinder.GetCouples(input, sum);
            List <int>   rest    = input.ToList();

            Assert.IsNotNull(couples, dataName + " - couples null");

            foreach (int[] c in couples)
            {
                Assert.IsNotNull(couples, dataName + " - null couple");

                Assert.IsTrue(c.Length == 2, dataName + " - len 2");

                Assert.IsTrue(rest.Contains(c[0]), dataName + " - cont 0");
                rest.Remove(c[0]);

                Assert.IsTrue(rest.Contains(c[1]), dataName + " - cont 1");
                rest.Remove(c[1]);
            }

            for (int i = 0; i < rest.Count; ++i)
            {
                for (int j = 0; j < rest.Count; ++j)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    Assert.IsFalse(rest[i] + rest[j] == sum, dataName + " - missing sum");
                }
            }
        }
Exemplo n.º 2
0
        public Tuple <int, int> BringSpouseDuplexTogether(Dictionary <string, PersonWithMetadata> persons, CoupleFinder coupleFinder, Randomizer randy, Action <string> outputter)
        {
            var howmanyTotal = SpouseSearchDuplex.Sum(x => x.Value.Count);
            var successrate  = BringSpousesTogether(persons, SpouseSearchDuplex, true, coupleFinder, randy);
            var howmanySet   = (howmanyTotal * successrate) / 100;

            coupleFinder.RegisterNumberofChildrenToMarried(_numberOfChildren);
            outputter("BringSpouseDuplexTogether successrate=" + successrate);

            return(new Tuple <int, int>(howmanySet, howmanyTotal));
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public void BringChildrenAndParentsTogether(Dictionary <string, PersonWithMetadata> persons, CoupleFinder coupleFinder, Randomizer randy, Action <string> outputter)
        {
            var orgCount = ParentSearch.Count;

            while (ParentSearch.Count > 0)
            {
                var next = ParentSearch.Pop();

                if (!persons.ContainsKey(next.ChildNin))
                {
                    continue;
                }

                var child = persons[next.ChildNin];
                coupleFinder.SetParents(next, child, randy);

                if (randy.Hit(AdressModel.PSameAdressAsParents(child)))
                {
                    SetChildAdressToParents(persons, child, randy);
                }

                if (child.Person.FathersNIN != null && child.Person.MothersNIN != null && randy.Hit(AdressModel.PParentsSameAdress))
                {
                    SetParentsSameAdress(persons, child, randy);
                }
            }

            var marriedSuccessRate    = coupleFinder.MarriedSuccessRate;
            var nonmarriedSuccessRate = coupleFinder.NonMarriedSuccessRate;
            var parentsAreMarried     = (coupleFinder.MarriedSuccess.Count * 100) / orgCount;

            outputter("BringChildrenAndParentsTogether.marriedSuccessRate=" + marriedSuccessRate);
            outputter("BringChildrenAndParentsTogether.nonmarriedSuccessRate=" + nonmarriedSuccessRate);
        }