private void MinSGraphDFS1(int i, int vnum, int[] templength, int[] tempfrom) { SpareGraph.adjIterator iter = new SpareGraph.adjIterator(this.sgraph, i); int u = i; for (int v = iter.begin(); !iter.isEnd(); v = iter.Next()) { if (!book [v]) { book [v] = true; templength [v] = templength [u] + 1; tempfrom [v] = u; MinSGraphDFS1(v, vnum + 1, templength, tempfrom); for (int k = 0; k != n; k++) { if (minLength [k] > templength [k] && book [k]) { minLength [k] = templength [k]; from [k] = tempfrom [k]; } } book [v] = false; } } }
private void SpareGraphDFS(int i) { int u = i; // Debug.Log ("正在访问的节点 :" + u); SpareGraph.adjIterator iter = new SpareGraph.adjIterator(this.sgraph, u); for (int v = iter.begin(); !iter.isEnd(); v = iter.Next()) { if (!book [v]) { book [v] = true; id [v] = count; from [v] = u; SpareGraphDFS(v); } } }
private void MinSGraphDFS1(int i) { SpareGraph.adjIterator iter = new SpareGraph.adjIterator(this.sgraph, i); int u = i; for (int v = iter.begin(); !iter.isEnd(); v = iter.Next()) { if (!book [v]) { book [v] = true; if (minLength [v] > minLength [u] + 1) { minLength [v] = minLength [u] + 1; from [v] = u; } MinSGraphDFS1(v); book [v] = false; } } }
private void SpareGraphBSF(int i) { int u = i; Queue q = new Queue(); q.Enqueue(u); while (q.Count != 0) { u = (int)q.Dequeue(); // Debug.Log ("正在访问的节点 :" + u); SpareGraph.adjIterator iter = new SpareGraph.adjIterator(this.sgraph, u); for (int v = iter.begin(); !iter.isEnd(); v = iter.Next()) { if (!book[v]) { book [v] = true; id[v] = count; from [v] = u; q.Enqueue(v); } } } }
public void testGraphBasicOperation() { //*********测试稠密图的基本功能********* print("*********测试稠密图的基本功能*********"); int n = 10; int m = 3; bool isDirected = false; //无向图 DenseGraph dGraph = new DenseGraph(n, isDirected); for (int i = 0; i != m; i++) { int p = Random.Range(0, n); int q = Random.Range(0, n); dGraph.AddEdge(p, q); } dGraph.print(); print("* *"); string rowsStr = ""; for (int i = 0; i != n; i++) { DenseGraph.adjIterator iter = new DenseGraph.adjIterator(dGraph, i); for (int hasEdge = iter.begin(); !iter.IsEnd(); hasEdge = iter.next()) { rowsStr += hasEdge + " "; } rowsStr += "\n"; } print(rowsStr); print("*************************************"); print("*********测试稀疏图图的基本功能*********"); n = 10; m = 3; isDirected = false; //无向图 SpareGraph sGraph = new SpareGraph(n, isDirected); dGraph = new DenseGraph(n, isDirected); for (int i = 0; i != m; i++) { int p = Random.Range(0, n); int q = Random.Range(0, n); sGraph.AddEdge(p, q); dGraph.AddEdge(p, q); } // dGraph.print (); print("* *"); rowsStr = ""; for (int i = 0; i != n; i++) { SpareGraph.adjIterator iter = new SpareGraph.adjIterator(sGraph, i); rowsStr += "第" + i + "结点 "; for (int hasEdge = iter.begin(); !iter.isEnd(); hasEdge = iter.Next()) { rowsStr += hasEdge + " "; } rowsStr += "\n"; } print(rowsStr); dGraph.print(); print("*************************************"); }