public static bool FindRoute(this DSGraph graph, string nodeA, string nodeB) { DSQueue <string> queue = new DSQueue <string>(); Dictionary <string, bool> visible = new Dictionary <string, bool>(); queue.Enqueue(nodeA); while (!queue.IsEmpty()) { var current = queue.Dequeue().Data; if (!visible.ContainsKey(current)) { visible.Add(current, true); if (current == nodeB) { return(true); } } foreach (var item in graph._node[current]) { if (!visible.ContainsKey(item)) { queue.Enqueue(item); } } } return(visible.ContainsKey(nodeB)); }
public void Test_Graph_DFS_SeperatedEdge() { DSGraph dSGraph = new DSGraph(); dSGraph.AddVertex("San Fransisco"); dSGraph.AddVertex("Las Vegas"); dSGraph.AddVertex("Seattle"); dSGraph.AddVertex("Atlanta"); dSGraph.AddVertex("Dallas"); dSGraph.AddVertex("Denver"); dSGraph.AddVertex("Delhi"); dSGraph.AddEdge("San Fransisco", "Seattle"); dSGraph.AddEdge("San Fransisco", "Dallas"); dSGraph.AddEdge("San Fransisco", "Denver"); dSGraph.AddEdge("Dallas", "Atlanta"); dSGraph.AddEdge("Dallas", "Denver"); dSGraph.AddEdge("Dallas", "Las Vegas"); var actual = dSGraph.DFS("Delhi"); var expected = new List <string>() { "Delhi" }; for (int i = 0; i < actual.Count; i++) { Assert.AreEqual(actual[i], expected[i]); } }
public void Test_Graph_BFS_Positive() { DSGraph dSGraph = new DSGraph(); dSGraph.AddVertex("San Fransisco"); dSGraph.AddVertex("Las Vegas"); dSGraph.AddVertex("Seattle"); dSGraph.AddVertex("Atlanta"); dSGraph.AddVertex("Dallas"); dSGraph.AddVertex("Denver"); dSGraph.AddVertex("Delhi"); dSGraph.AddEdge("San Fransisco", "Seattle"); dSGraph.AddEdge("San Fransisco", "Dallas"); dSGraph.AddEdge("San Fransisco", "Denver"); dSGraph.AddEdge("Dallas", "Atlanta"); dSGraph.AddEdge("Dallas", "Denver"); dSGraph.AddEdge("Dallas", "Las Vegas"); var actual = dSGraph.BFS("San Fransisco"); var expected = new List <string>() { "San Fransisco", "Seattle", "Dallas", "Denver", "Atlanta", "Las Vegas" }; Assert.IsNotNull(actual); Assert.AreEqual(expected.Count, actual.Count); for (int i = 0; i < actual.Count; i++) { Assert.AreEqual(actual[i], expected[i]); } }
public void FindRoute_Test_No_Route() { DSGraph obj = new DSGraph(); obj.AddVertex("San Fransisco"); obj.AddVertex("Las Vegas"); obj.AddVertex("Seattle"); obj.AddVertex("Atlanta"); obj.AddVertex("Dallas"); obj.AddVertex("Denver"); obj.AddVertex("Delhi"); obj.AddDirectedEdge("San Fransisco", "Seattle"); obj.AddDirectedEdge("San Fransisco", "Dallas"); obj.AddDirectedEdge("San Fransisco", "Denver"); obj.AddDirectedEdge("Dallas", "Atlanta"); obj.AddDirectedEdge("Dallas", "Denver"); obj.AddDirectedEdge("Dallas", "Las Vegas"); var actual = obj.FindRoute("Seattle", "Las Vegas"); Assert.IsFalse(actual); }
private bool ExportChartImage(string file) { DSGraph.SaveChartImage(file); return(true); }
private string GetTableFromView(string sep = ",") { return(Util.GetTableFromLogEntries(DSGraph.GetInViewEntries(), EnabledSeries, IdToPDPGroup, (DSGraph.UseMatchTime && DSGraph.CanUseMatchTime), DSGraph.MatchTime, sep)); }