예제 #1
0
 private static void CullVisitedNodes <T>(RootFinder finder, List <T> adjacent) where T : GraphElement <T>
 {
     foreach (var node in finder.Visited)
     {
         node.RemoveFromGraph();
     }
 }
예제 #2
0
 private static void RemoveVisitedNodes <T>(RootFinder finder, List <T> adjacent) where T : GraphElement <T>
 {
     for (var index = adjacent.Count - 1; index >= 0; index--)
     {
         if (finder.Contains(adjacent[index]))
         {
             adjacent.RemoveAt(index);
         }
     }
 }
예제 #3
0
        public static void RemoveNodes <T>(List <T> nodes) where T : GraphElement <T>
        {
            var adjacent = GetAdjacentNodes(nodes);

            foreach (var node in nodes)
            {
                node.DisconnectAll();
            }

            var finder = new RootFinder();

            while (adjacent.Count > 0)
            {
                finder.Reset();
                var connected = finder.IsConnectedToRoot(adjacent[0]);
                RemoveVisitedNodes(finder, adjacent);

                if (!connected)
                {
                    CullVisitedNodes(finder, adjacent);
                }
            }
        }