public ActionResult <string> Get() { var filePath = @"Data\SocialNetwork.txt"; string pointA = "STACEY_STRIMPLE"; string pointB = "RICH_OMLI"; var graphDictionary = new Dictionary <string, GraphNode <string> >(); var unique = new AssociationHashSet <string>(100 * 1000); var links = new AssociationHashSet <string[]>(1000 * 1000); IOServicecs.GetData(filePath, graphDictionary, unique, links); Dijkstra <string> dijkstra = new Dijkstra <string>(graphDictionary.Select(g => g.Value)); var path = dijkstra.FindPathBetween(graphDictionary[pointA], graphDictionary[pointB]); return($"Count of people: {unique.Count}. Path between {pointA} and {pointB} :[ {string.Join(" -> ", path.Select(p => p.Value).ToArray())} ]"); }
public static void GetData(string filePath, Dictionary <string, GraphNode <string> > graphDictionary, AssociationHashSet <string> unique, AssociationHashSet <string[]> links) { using (StreamReader file = new StreamReader(filePath)) { string line; while ((line = file.ReadLine()) != null) { string[] lineItems = line.Split(','); //Add link links.AddItem(lineItems); //add uniqe Value unique.AddItem(lineItems[0]); unique.AddItem(lineItems[1]); } } foreach (string uniqueItems in unique) { if (graphDictionary == null || !graphDictionary.ContainsKey(uniqueItems)) { graphDictionary.Add(uniqueItems, new GraphNode <string>(uniqueItems)); } } foreach (string[] linksItems in links) { GraphNode <string> mainNode = graphDictionary[linksItems[0]]; GraphNode <string> neighbourNode = graphDictionary[linksItems[1]]; mainNode.AddNeighbour(neighbourNode, 1); } }