private void BFS(GraphAPI gapi, int s, long color) { Queue <int> queue = new Queue <int>(); queue.Enqueue(s); Marked[s] = true; while (queue.Count > 0) { int v = queue.Dequeue(); foreach (var w in gapi.Adjacent(v)) { if (!Marked[w]) { queue.Enqueue(w); Marked[w] = true; EdgeTo[w] = v; DistTo[w] = DistTo[v] + 1; if (gapi.Color[w] == color) { minDist = DistTo[w]; return; } } } } }
private void DFS(GraphAPI gapi, int v) { Marked[v] = true; //Id[v] = count; foreach (var item in gapi.Adjacent(v)) { if (!Marked[item]) { DFS(gapi, item); count++; } } }
private void DFS(GraphAPI gapi, int v) { Marked[v] = true; int count = 0; foreach (var item in gapi.Adjacent(v)) { if (!Marked[item - 1]) { count++; DFS(gapi, item - 1); EdgeTo[item - 1] = v; DistTo[item - 1] = count; } } }
//public DepthFirstSearch(GraphAPI gapi, int s, long color) //{ // Marked = new bool[gapi.S]; // EdgeTo = new int[gapi.S]; // this.S = s; // for (int i = 0; i < gapi.S; i++) // { // int count = 0; // long currentColor = gapi.Color[i]; // if (!Marked[i]) // { // DFS(gapi, i, color, countIds, count, currentColor); // } // } //} //public DepthFirstSearch(DiaGraphAPI gapi, int s) //{ // Marked = new bool[gapi.V]; // EdgeTo = new int[gapi.V]; // this.S = s; // DFS(gapi, s); //} private void DFS(GraphAPI gapi, int v, long color, List <int> countIds, int count, long currenColor) { Marked[v] = true; foreach (var item in gapi.Adjacent(v)) { if (!Marked[item - 1]) { count++; if (gapi.Color[item - 1] == color && currenColor == color) { countIds.Add(count); } DFS(gapi, item - 1, color, countIds, count, currenColor); EdgeTo[item - 1] = v; } } }
private void BFS(GraphAPI gapi, int s) { Queue <int> queue = new Queue <int>(); queue.Enqueue(s); Marked[s] = true; while (queue.Count > 0) { int v = queue.Dequeue(); foreach (var w in gapi.Adjacent(v)) { if (!Marked[w]) { string key = v < w ? v + "|" + w : w + "|" + v; var align = gapi.dict[key]; queue.Enqueue(w); Marked[w] = true; EdgeTo[w] = v; DistTo[w] = DistTo[v] + 1; } } } }