示例#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);
                        }
                    }
                }
            }
        }
示例#2
0
        private void GenerateGraph(object sender, RoutedEventArgs args)
        {
            if (sender == ErdosRenyiMenuItem)
            {
                var w = new ErdosGenerator();
                try
                {
                    w.ShowDialog();
                    Graph.Clear();
                    Graph.Set(GraphGenerator.CreateDirectional(w.DataContext as GraphMatrix));
                    Graph.OnChange();
                }
                catch (Exception e)
                {
                    MessageBoxResult result = MessageBox.Show("Coś poszło nie tak"
                                                              + System.Environment.NewLine
                                                              + e.Message
                                                              );
                }
            }
            else if (sender == SecondGeneratorMenuItem)
            {
                var w = new SecondGenerator();
                try
                {
                    w.ShowDialog();
                    Graph.Clear();
                    Graph.Set(GraphGenerator.CreateDirectional(w.DataContext as GraphMatrix));
                    Graph.OnChange();
                }
                catch (Exception e)
                {
                    MessageBoxResult result = MessageBox.Show("Coś poszło nie tak"
                                                              + System.Environment.NewLine
                                                              + e.Message
                                                              );
                }
            }

            Graph.Set(GraphGenerator.CreateRandomDirectedWeights(Graph));
            Graph.OnChange();
            Renderer.Displayer = new DirectedCircleDisplayer();
        }