Ejemplo n.º 1
0
        private static RelationshipDegree GetTrueRelationshipDegree(Relative zeroRelative, Relative firstRelative, List <RelationshipDegree> possibleRelationshipDegreesList)
        {
            RelationshipDegree trueRelationshipDegree = null;

            foreach (RelationshipDegree possibleRelationshipDegree in possibleRelationshipDegreesList)
            {
                if (possibleRelationshipDegree.RelationshipDegreeNumber == 0)
                {
                    trueRelationshipDegree = possibleRelationshipDegree;
                }
                else
                {
                    if (AncestorList.Contains(possibleRelationshipDegree.RelationshipDegreeNumber))
                    {
                        int             yDistanceToMRCA = possibleRelationshipDegree.Y;
                        List <Relative> parentsList     = GetParentsListInSelectedGeneration(zeroRelative, yDistanceToMRCA);

                        if (parentsList.Contains(firstRelative))
                        {
                            trueRelationshipDegree = possibleRelationshipDegree;
                            break;
                        }
                    }
                    else if (DescendantsList.Contains(possibleRelationshipDegree.RelationshipDegreeNumber))
                    {
                        int             yDistanceToMRCA = possibleRelationshipDegree.Y;
                        List <Relative> childsList      = GetChildsListInSelectedGeneration(zeroRelative, yDistanceToMRCA);

                        if (childsList.Contains(firstRelative))
                        {
                            trueRelationshipDegree = possibleRelationshipDegree;
                            break;
                        }
                    }
                    else
                    {
                        int             yDistanceToMRCAFromZeroPerson = possibleRelationshipDegree.X;
                        List <Relative> parentsListOfZeroPerson       = GetParentsListInSelectedGeneration(zeroRelative, yDistanceToMRCAFromZeroPerson);

                        int             yDistanceToMRCAFromFirstPerson = possibleRelationshipDegree.X - possibleRelationshipDegree.Y;
                        List <Relative> parentsListOfFirstPerson       = GetParentsListInSelectedGeneration(firstRelative, yDistanceToMRCAFromFirstPerson);

                        if (parentsListOfZeroPerson.Intersect(parentsListOfFirstPerson).ToList().Count > 0)
                        {
                            trueRelationshipDegree = possibleRelationshipDegree;
                            break;
                        }
                    }
                }
            }

            return(trueRelationshipDegree);
        }
Ejemplo n.º 2
0
        public static float[][] GetMatrix(int generatedMatrixSize, List <Relative> relativesList)
        {
            List <int> relativesNumbersRange = Enumerable.Range(0, relativesList.Count).ToList();

            List <int> randomNumbers = new List <int> {
                0
            };

            for (int i = 1; i < generatedMatrixSize; i++)
            {
                int randomValue = GetNextRandomValue(1, relativesNumbersRange.Count);
                randomNumbers.Add(relativesNumbersRange[randomValue]);
                relativesNumbersRange.RemoveAt(randomValue);
            }

            float[][] relativesMatrix = new float[generatedMatrixSize][];

            for (int i = 0; i < generatedMatrixSize; i++)
            {
                relativesMatrix[i] = new float[generatedMatrixSize];

                Relative zeroRelative = relativesList[randomNumbers[i]];

                for (int j = i + 1; j < generatedMatrixSize; j++)
                {
                    Relative firstRelative = relativesList[randomNumbers[j]];

                    if (i == 0)
                    {
                        relativesMatrix[i][j] = relativesList[randomNumbers[j]].RelationshipDegree.RelationshipDegreeNumber;
                    }
                    else
                    {
                        int yMrca = GetYOfMRCA(zeroRelative.RelationshipDegree.X, zeroRelative.RelationshipDegree.Y,
                                               firstRelative.RelationshipDegree.X, firstRelative.RelationshipDegree.Y);
                        int y0Result = yMrca - zeroRelative.RelationshipDegree.Y;
                        int y1Result = yMrca - firstRelative.RelationshipDegree.Y;

                        List <RelationshipDegree> possibleRelationshipDegreesList = GetPossibleRelationshipsList(yMrca,
                                                                                                                 y0Result, y1Result,
                                                                                                                 zeroRelative.RelationshipDegree, firstRelative.RelationshipDegree,
                                                                                                                 RelationshipDegreesDictionary.Values.ToList());
                        possibleRelationshipDegreesList = possibleRelationshipDegreesList.Where(x => x.RelationshipDegreeNumber != 1).ToList();
                        RelationshipDegree trueRelationshipDegree = GetTrueRelationshipDegree(zeroRelative, firstRelative, possibleRelationshipDegreesList);

                        relativesMatrix[i][j] = trueRelationshipDegree.RelationshipDegreeNumber;
                    }
                }
            }

            return(relativesMatrix);
        }
Ejemplo n.º 3
0
        private static List <Relative> GetParentsListInSelectedGeneration(Relative zeroRelative, int yDistanceToMRCA)
        {
            List <Relative> parentsList = new List <Relative> {
                zeroRelative
            };

            for (int g = 0; g < yDistanceToMRCA; g++)
            {
                List <Relative> newParentsList = new List <Relative> {
                };
                foreach (Relative parent in parentsList)
                {
                    newParentsList.AddRange(parent.ParentsList);
                }

                parentsList = newParentsList;
            }

            return(parentsList);
        }
Ejemplo n.º 4
0
        private static List <Relative> GetChildsListInSelectedGeneration(Relative zeroRelative, int yDistanceToMRCA)
        {
            List <Relative> childsList = new List <Relative> {
                zeroRelative
            };

            for (int g = 0; g > yDistanceToMRCA; g--)
            {
                List <Relative> newChildsList = new List <Relative> {
                };
                foreach (Relative child in childsList)
                {
                    newChildsList.AddRange(child.ChildsList);
                }

                childsList = newChildsList;
            }

            return(childsList);
        }