public SixDegreesOfSeparation(string toFind) { s = new SymbolGraph("C:/Users/Dhana/Desktop/Learning/C#/Algorithms/Algorithms/Data/movies.txt", '/'); int vertex = s.getSymbolKey(toFind); UndirectedGraph graph = s.getSymbolGraph(); UndirectedGraphBreadthFirst searchTool = new UndirectedGraphBreadthFirst(graph); int[] matrix = searchTool.getShortestPath(graph, vertex); int MAX_BACON = 100; int[] hist = new int[MAX_BACON + 1]; for (int i = 0; i < graph.getTotalVertices(); i++) { int bacon = 0; if (matrix[i] > 0) { bacon = Math.Min(MAX_BACON, matrix[i]); hist[bacon]++; } } for (int i = 0; i < hist.Length; i++) { Console.WriteLine(i + " " + hist[i]); } }
static void Main(string[] args) { UndirectedGraph g = new UndirectedGraph(6); g.AddEdge(0, 2); g.AddEdge(0, 1); g.AddEdge(0, 5); g.AddEdge(1, 0); g.AddEdge(1, 2); g.AddEdge(2, 0); g.AddEdge(2, 1); g.AddEdge(2, 3); g.AddEdge(2, 4); g.AddEdge(3, 5); g.AddEdge(3, 4); g.AddEdge(3, 2); g.AddEdge(4, 3); g.AddEdge(4, 2); g.AddEdge(5, 3); g.AddEdge(5, 0); UndirectedGraphBreadthFirst br = new UndirectedGraphBreadthFirst(g); int[] shortestPath = br.getShortestPath(g,5); //br.bfs(g, 5); }
public static void main() { UndirectedGraph g = new UndirectedGraph(6); g.AddEdge(0, 2); g.AddEdge(0, 1); g.AddEdge(0, 5); g.AddEdge(1, 0); g.AddEdge(1, 2); g.AddEdge(2, 0); g.AddEdge(2, 1); g.AddEdge(2, 3); g.AddEdge(2, 4); g.AddEdge(3, 5); g.AddEdge(3, 4); g.AddEdge(3, 2); g.AddEdge(4, 3); g.AddEdge(4, 2); g.AddEdge(5, 3); g.AddEdge(5, 0); UndirectedGraphBreadthFirst br = new UndirectedGraphBreadthFirst(g); //int[] shortestPath = br.getShortestPath(g, 0); br.bfs(g, 5); }