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); } }
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); }
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); }
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); }