public void AudreyDana()
        {
            var actor = new SearchPerson(firstName: "Audrey", lastName: "Dana", birthYear: 1977);

            var startNode = _graph.Nodes.First(n => n.Name == PersonNode.BuildNodeName(actor));

            var results = (new DeepFirstAlgorithm(_graph)).GetAllDistances(startNode);

            var distances = results.Values.Where(d => d > 2 && d < double.PositiveInfinity).ToList();

            var maxDistance = distances.Max();

            var maxDistances = results.Where(kvp => kvp.Value == maxDistance).ToList();
        }
        private static void AddPersonNodes(Graph graph, DistanceNode profileNode, IEnumerable <IPerson> people, HashSet <string> duplicateChecker)
        {
            foreach (var person in people)
            {
                if (!graph.TryGetDistanceNode(PersonNode.BuildNodeName(person), out var personNode))
                {
                    personNode = new PersonNode(person);

                    graph.AddNode(personNode);
                }

                if (duplicateChecker.Add(personNode.Name)) //a person can have multiple jobs in the same profiles
                {
                    graph.AddEdge(profileNode, personNode, 1, true);
                }

                ((PersonNode)personNode).AddJob((ProfileNode)profileNode, person);
            }
        }
        private static bool IsMatch(PersonKey searchFor, PersonNode searchIn)
        {
            var searchInPerson = searchIn.Person;

            if (!IsMatch(searchFor.FirstName, searchInPerson.FirstName))
            {
                return(false);
            }
            else if (!IsMatch(searchFor.MiddleName, searchInPerson.MiddleName))
            {
                return(false);
            }
            else if (!IsMatch(searchFor.LastName, searchInPerson.LastName))
            {
                return(false);
            }
            else
            {
                var isMatch = IsMatch(searchFor.BirthYear, searchInPerson.BirthYear);

                return(isMatch);
            }
        }
        public void Test3Deep()
        {
            var sourcePerson = new SearchPerson(firstName: "Hans", lastName: "Alfredson");
            var targetPerson = new SearchPerson(firstName: "John", lastName: "Wayne");

            var sourceNode = _graph.GetDistanceNode(PersonNode.BuildNodeName(sourcePerson));
            var targetNode = _graph.GetDistanceNode(PersonNode.BuildNodeName(targetPerson));

            var calculator = new DeepFirstAlgorithm(_graph);

            var shortestGraph = calculator.GetShortestGraph(sourceNode.Name, targetNode.Name);

            var shortestGraphTargetNode = shortestGraph.GetDistanceNode(PersonNode.BuildNodeName(targetPerson));

            var movieDistance = ForwardUnitTestSample.GetRealMovieDistance(shortestGraphTargetNode);

            Assert.AreEqual(2, movieDistance);

            var stepsList = GraphHelper.GetPaths(shortestGraphTargetNode).ToList();

            Assert.AreEqual(1, stepsList.Count);

            ForwardUnitTestSample.CheckSteps(sourceNode, targetNode, stepsList, movieDistance * 2);
        }
Example #5
0
        public void TomWellingToGeorgeLucasDegree2Deep()
        {
            var sourcePerson = new SearchPerson(firstName: "Tom", lastName: "Welling", birthYear: 1977);
            var targetPerson = new SearchPerson(firstName: "George", lastName: "Lucas", birthYear: 1944);

            var sourceNode = _graph.GetDistanceNode(PersonNode.BuildNodeName(sourcePerson));
            var targetNode = _graph.GetDistanceNode(PersonNode.BuildNodeName(targetPerson));

            var calculator = new DeepFirstAlgorithm(_graph);

            var shortestGraph = calculator.GetShortestGraph(sourceNode.Name, targetNode.Name);

            var shortestGraphTargetNode = shortestGraph.GetDistanceNode(PersonNode.BuildNodeName(targetPerson));

            var movieDistance = ForwardUnitTestSample.GetRealMovieDistance(shortestGraphTargetNode);

            Assert.AreEqual(2, movieDistance);

            var stepsList = GraphHelper.GetPaths(shortestGraphTargetNode).ToList();

            Assert.AreEqual(1, stepsList.Count);

            ForwardUnitTestSample.CheckSteps(sourceNode, targetNode, stepsList, movieDistance * 2);
        }
Example #6
0
        public void TomHollandToToshiroMifuneDegree4()
        {
            var sourcePerson = new SearchPerson(firstName: "Tom", lastName: "Holland", birthYear: 1996);
            var targetPerson = new SearchPerson(firstName: "ToshirĂ´", lastName: "Mifune", birthYear: 1920);

            var sourceNode = _graph.GetDistanceNode(PersonNode.BuildNodeName(sourcePerson));
            var targetNode = _graph.GetDistanceNode(PersonNode.BuildNodeName(targetPerson));

            var calculator = new DeepFirstAlgorithm(_graph);

            var shortestGraph = calculator.GetShortestGraph(sourceNode.Name, targetNode.Name);

            var shortestGraphTargetNode = shortestGraph.GetDistanceNode(PersonNode.BuildNodeName(targetPerson));

            var movieDistance = ForwardUnitTestSample.GetRealMovieDistance(shortestGraphTargetNode);

            Assert.AreEqual(4, movieDistance);

            var stepsList = GraphHelper.GetPaths(shortestGraphTargetNode).ToList();

            Assert.AreEqual(18, stepsList.Count);

            CheckSteps(sourceNode, targetNode, stepsList, movieDistance * 2);
        }