public void RegisterMarried(PersonWithMetadata parent1, PersonWithMetadata parent2)
        {
            var father = parent1;
            var mother = parent2;

            if (parent1.IsFemale && !parent2.IsFemale)
            {
                father = parent2;
                mother = parent1;
            }

            var howManyOtherChildrenFather = _numberOfOtherChildrenForMarriedCouples(father);
            var howManyOtherChildrenMother = _numberOfOtherChildrenForMarriedCouples(mother);

            var couple = new Couple
            {
                FatherNin = father.Person.NIN,
                MotherNin = mother.Person.NIN,
                FatherSn  = father.Person.Sn,
                MotherSn  = mother.Person.Sn
            };

            AddToCoupleCache(couple, ParentRelationshipSearch.KeyMarriedParents(father, mother), false);

            if (howManyOtherChildrenFather > 0)
            {
                AddToParentCacheReturnKey(howManyOtherChildrenFather, father);
            }

            if (howManyOtherChildrenMother > 0)
            {
                AddToParentCacheReturnKey(howManyOtherChildrenMother, mother);
            }
        }
 public bool SetParents(ParentRelationshipSearch next, PersonWithMetadata child, Randomizer randy)
 {
     if (next.Married)
     {
         var success = SetCouple(next, child, GetNewMarriedCouple, randy);
         MarriedSuccess.Add(success);
         return(success);
     }
     else
     {
         var success = SetCouple(next, child, GetNewCouple, randy);
         NonMarriedSuccess.Add(success);
         return(success);
     }
 }
        public static string KeyMarriedParents(PersonWithMetadata father, PersonWithMetadata mother)
        {
            var pc = new ParentRelationshipSearch();

            pc.Mother = new RelationshipSearch
            {
                IsLookingForAgeQuant = mother.AgeQuants,
                IsLookingForFemale   = mother.IsFemale
            };
            pc.Father = new RelationshipSearch()
            {
                IsLookingForAgeQuant = father.AgeQuants,
                IsLookingForFemale   = father.IsFemale
            };
            pc.Married = true;

            return(pc.KeyParents());
        }
        private bool SetCouple(ParentRelationshipSearch next, PersonWithMetadata child, Func <ParentRelationshipSearch, PersonWithMetadata, Randomizer, Couple> getNewCouple, Randomizer randy)
        {
            var couple = GetFromCache(next.KeyParents()) ?? getNewCouple(next, child, randy);

            if (couple == null)
            {
                return(false);
            }

            SetNins(couple.FatherNin, couple.MotherNin, child);

            if (randy.Hit(NameModel.PHasSamesirnameAsParents(child)))
            {
                var takeFathers = couple.FatherSn != null && randy.Hit(50);
                child.Person.Sn = takeFathers ? couple.FatherSn : (couple.MotherSn ?? child.Person.Sn);
            }



            return(true);
        }
        private Couple GetNewCouple(ParentRelationshipSearch next, PersonWithMetadata child, Randomizer randy)
        {
            var mother = next.Mother == null ? null : (GetParentNinFromCache(next.Mother) ?? GetNewParent(next.Mother, married: false));
            var father = next.Father == null ? null : (GetParentNinFromCache(next.Father, mother) ?? GetNewParent(next.Father, married: false));

            if (mother == null && father == null)
            {
                return(null);
            }

            var howManyChildrenTogether = GetNumberOfChildsTogether(mother?.RemainingNumberOfChildren, father?.RemainingNumberOfChildren, randy);

            int?beforeFather = father?.RemainingNumberOfChildren;
            int?beforeMother = mother?.RemainingNumberOfChildren;

            //usikker på om dette er mulig ..
            if (mother != null)
            {
                mother.RemainingNumberOfChildren = mother.RemainingNumberOfChildren - howManyChildrenTogether;
            }
            if (father != null)
            {
                father.RemainingNumberOfChildren = father.RemainingNumberOfChildren - howManyChildrenTogether;
            }

            var couple = new Couple
            {
                FatherNin = father?.Nin,
                MotherNin = mother?.Nin,
                FatherSn  = father?.Sn,
                MotherSn  = mother?.Sn,
                RemainingNumberOfChildren = howManyChildrenTogether - 1
            };

            AddToCoupleCache(couple, next.KeyParents());

            return(couple);
        }
 private Couple GetNewMarriedCouple(ParentRelationshipSearch next, PersonWithMetadata child, Randomizer randu)
 {
     return(null); // all married couples are already in cache
 }