Example #1
0
 private void StrongConnect(Vertex v)
 {
     v.LowIndex = v.Index = ++_currentIndex;
       v.InStack = true;
       _vertexStack.Push(v);
       foreach (var w in v.LinkedTo) {
     if (w.Index == 0) {
       StrongConnect(w);
       v.LowIndex = Math.Min(v.LowIndex, w.LowIndex);
     } else if (w.InStack)
       v.LowIndex = Math.Min(v.LowIndex, w.Index);
       }//foreach
       // If v is a root node, pop the stack and generate the SCC
       if (v.LowIndex == v.Index) {
     //Pop all vertexes until v - this is a new SCC group
     SccCount++;
     var nonTrivialGroup = _vertexStack.Peek() != v;
     while (true) {
       var w = _vertexStack.Pop();
       w.InStack = false;
       w.SccIndex = SccCount;
       w.NonTrivialGroup = nonTrivialGroup;
       if (w == v)  break; //from while
     }
       } //if v.LowIndex...
 }
Example #2
0
 public Vertex Add(object tag)
 {
     var v = new Vertex() { Tag = tag };
       Vertexes.Add(v);
       return v;
 }