示例#1
0
        public void SomeNewAlgorithmsTest()
        {
            var graph      = new Graph(1);
            var algorithm  = GraphAlgorithmFactory.ResolveGraphAlgorithm(GraphAlgorithmsRegistry.ExampleAlgorithm);
            var parameters = new GraphAlgorithmParameters(graph, edges: new Edge[] { });

            algorithm.PerformAlgorithmAsync(parameters);
            algorithm.AlgorithmPerformed += OnAlgorithmPerformed;
        }
示例#2
0
        public void ConnectedComponentsCountTest()
        {
            var graph      = new Graph(3);
            var algorithm  = GraphAlgorithmFactory.ResolveGraphAlgorithm(GraphAlgorithmsRegistry.ConnectedComponentsCount);
            var parameters = new GraphAlgorithmParameters(graph);

            algorithm.PerformAlgorithmAsync(parameters);

            while (algorithm.IsPerforming)
            {
                Thread.Sleep(10);
            }

            algorithm.Result.Number.Should().Be(3);
        }
示例#3
0
        // TODO: алгоритм запускается в отдельном потоке, надо предусмотреть блокировку формы
        private void InitializeAlgorithmButtons()
        {
            var algorithms = GraphAlgorithmFactory.CreateAllGraphAlgorithms();
            var i          = 1;

            foreach (var algorithm in algorithms)
            {
                algorithm.Performed += result =>
                {
                    if (!string.IsNullOrWhiteSpace(result.StringResult))
                    {
                        MessageBox.Show(result.StringResult,
                                        GetStringResource("ResultMessageBoxTitle"));
                    }
                    else if (result.Number.HasValue)
                    {
                        MessageBox.Show(result.Number.ToString(),
                                        GetStringResource("ResultMessageBoxTitle"));
                    }

                    if (result.Edges != null)
                    {
                        if (result.IsSequential)
                        {
                            ColorizedEdgesAnimation(result.Edges, Brushes.Blue);
                        }
                        else
                        {
                            ColorizeEdges(result.Edges, Brushes.Blue);
                        }
                    }
                    if (result.Vertices != null)
                    {
                        ColorizeVertices(result.Vertices, Brushes.Red);
                    }
                    Dispatcher.Invoke(DispatcherPriority.Normal,
                                      (ThreadStart) delegate { ChangeAction(InterfaceAction.VertexEdit); });
                };
                var button = new Button
                {
                    Style   = FindResource("ToolbarButton") as Style,
                    Content = $"A{i++}",
                    ToolTip = algorithm.Name
                };
                button.Click += (sender, args) =>
                {
                    if (_currentAction == InterfaceAction.PerformAlgorithm && _algorithmVerticesCount == 0)
                    {
                        return;
                    }
                    ColorizeEdges(_graph.Edges, Brushes.Black);
                    ColorizeVertices(_graph.Vertices, Brushes.White);
                    ChangeAction(InterfaceAction.PerformAlgorithm);
                    _algorithmVertices = null;
                    foreach (var parametr in algorithm.RequiredParameters)
                    {
                        if (parametr.Item1 == typeof(Vertex))
                        {
                            _algorithmVerticesCount = parametr.Item2;
                            _algorithmVertices      = new List <Vertex>();
                        }
                    }

                    if (algorithm.RequiredParameters.Length == 1)
                    {
                        var parameters = new GraphAlgorithmParameters(_graph);
                        algorithm.PerformAlgorithmAsync(parameters);
                    }
                    _currentAlgorithm = algorithm;
                };
                Toolbar.Children.Add(button);
            }
        }