Exemplo n.º 1
0
        private static void topologicSorting(DirectedGraphMatrix originalGraph, List <int> retList, List <int> Done)
        {
            DirectedGraphMatrix graph = new DirectedGraphMatrix(1);

            graph.Set(originalGraph);

            while (retList.Count != originalGraph.NodesNr)
            {
                //find node with 0 dim
                for (int i = 0; i < graph.NodesNr; ++i)
                {
                    if (Done.Contains(i))
                    {
                        continue;
                    }

                    var neighbours = graph.GetNeighbours(i);

                    if (neighbours.Count == 0)
                    {
                        //remove this node
                        retList.Add(i);
                        Done.Add(i);
                        foreach (var node in graph.GetConnectedToNodes(i))
                        {
                            graph.RemoveConnection(node, i);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void ConnectTwoNodes(int node1, int node2)
 {
     if (Graph.GetConnection(node1, node2) == false)
     {
         Graph.MakeConnection(node1, node2);
         Graph.OnChange();
     }
     else
     {
         Graph.RemoveConnection(node1, node2);
         Graph.OnChange();
     }
 }