Example #1
0
 /// <summary>
 /// Adds vertex to this digraph
 /// </summary>
 /// <param name="vertex">Vertex to add</param>
 public void AddVertex(DigraphVertex vertex)
 {
     if (vertices.Contains(vertex))
     {
         throw new Exception("Vertex already exists");
     }
     vertices.Add(vertex);
 }
Example #2
0
 /// <summary>
 /// Step for closed loops finding
 /// </summary>
 /// <returns>True if process is not finished and false otherwise</returns>
 private bool stepClosedLoop()
 {
     oldVertices.Clear();
     oldVertices.AddRange(newVertices);
     newVertices.Clear();
     foreach (DigraphVertex v in oldVertices)
     {
         foreach (DigraphEdge e in v.outcomingEdges)
         {
             DigraphVertex t = e.Target;
             if (t == this)
             {
                 List <DigraphEdge> l = new List <DigraphEdge>();
                 e.Source.backwardPath(e.Source.index - 1, l);
                 l.Add(e);
                 DigraphPath path = new DigraphPath(l, true);
                 AddPath(path);
                 continue;
             }
             if (t.index == -1)
             {
                 t.index = v.index + 1;
                 newVertices.Add(t);
                 continue;
             }
             List <DigraphEdge> list     = new List <DigraphEdge>();
             List <DigraphEdge> incoming = t.IncomingEdges;
             foreach (DigraphEdge et in incoming)
             {
                 if (et == e)
                 {
                     continue;
                 }
                 if (et.Source.index == t.index - 1)
                 {
                     list.Add(et);
                     et.Source.backwardPath(et.Source.index - 1, list);
                     break;
                 }
             }
             //DigraphPath path = new DigraphPath(list, true);
             //AddPath(path);
             //ArrayList newList = new ArrayList();
             //newList.Add(e);
             //v.backwardPath(v.index - 1, newList);
             //DigraphPath newPath = new DigraphPath(newList, true);
             //AddPath(newPath);
         }
     }
     return(newVertices.Count > 0);
 }
Example #3
0
 /// <summary>
 /// Calculates backward shortest path
 /// </summary>
 /// <param name="index">Path length</param>
 /// <param name="list">The path</param>
 private void backwardPath(int index, List <DigraphEdge> list)
 {
     foreach (DigraphEdge e in incomingEdges)
     {
         DigraphVertex v = e.Source;
         if (v.index == index)
         {
             list.Add(e);
             if (index == 0)
             {
                 return;
             }
             v.backwardPath(index - 1, list);
             return;
         }
     }
 }
Example #4
0
 /// <summary>
 /// Removes vertex from this digraph
 /// </summary>
 /// <param name="vertex">Vertex to remove</param>
 public void RemoveVertex(DigraphVertex vertex)
 {
     vertices.Remove(vertex);
     vertex.RemoveObject();
 }