//конец добавлени-удаления

        /// <summary> Задание загружено </summary>
        /// <param name="e"></param>
        protected override void OnTaskLoadingComlete(VariantDownloadedEventArgs e)
        {
            // Мы вызваны из другого потока. Поэтому работаем с UI-элементами через Dispatcher.
            //Dispatcher.BeginInvoke(() => { GivenGraph = VariantSerializer.Deserialize(e.Data)[0]; });

            //var number = e.Number; -- м.б. тоже где-то показать надо
            //var version = e.Version;


            GivenGraph  = DirectedGraph.CreateEmpty(0);
            MatrixGraph = (DirectedGraph)VariantSerializer.Deserialize(e.Data)[0];

            Matrix = new ObservableCollection <MatrixRowViewModel <string> >();
            for (var i = 0; i < MatrixGraph.VerticesCount; ++i)
            {
                var row = new ObservableCollection <string> {
                    i.ToString()
                };
                for (var j = 0; j < MatrixGraph.VerticesCount; ++j)
                {
                    var testEdge = new DirectedEdge(MatrixGraph.Vertices[i], MatrixGraph.Vertices[j]);
                    row.Add(MatrixGraph.Edges.Any(testEdge.Equals)
                            //row.Add((MatrixGraph[MatrixGraph.Vertices[i],MatrixGraph.Vertices[j]] != null)
                        ? "1"
                        : "0");
                }
                row.CollectionChanged += RowChanged;
                Matrix.Add(new MatrixRowViewModel <string>(row));
            }
        }
Exemple #2
0
        public static byte[] GetSerializedVariant()
        {
            var graph1 = DirectedGraph.CreateEmpty(7);

            graph1.AddEdge(new DirectedEdge(graph1.Vertices[0], graph1.Vertices[5]));
            graph1.AddEdge(new DirectedEdge(graph1.Vertices[1], graph1.Vertices[0]));
            graph1.AddEdge(new DirectedEdge(graph1.Vertices[1], graph1.Vertices[5]));
            graph1.AddEdge(new DirectedEdge(graph1.Vertices[2], graph1.Vertices[1]));
            graph1.AddEdge(new DirectedEdge(graph1.Vertices[2], graph1.Vertices[5]));
            graph1.AddEdge(new DirectedEdge(graph1.Vertices[3], graph1.Vertices[4]));
            graph1.AddEdge(new DirectedEdge(graph1.Vertices[4], graph1.Vertices[2]));
            graph1.AddEdge(new DirectedEdge(graph1.Vertices[4], graph1.Vertices[3]));
            graph1.AddEdge(new DirectedEdge(graph1.Vertices[5], graph1.Vertices[6]));
            graph1.AddEdge(new DirectedEdge(graph1.Vertices[6], graph1.Vertices[4]));

            var graph2 = DirectedGraph.CreateEmpty(7);

            graph2.AddEdge(new DirectedEdge(graph2.Vertices[0], graph2.Vertices[5]));
            graph2.AddEdge(new DirectedEdge(graph2.Vertices[1], graph2.Vertices[0]));
            graph2.AddEdge(new DirectedEdge(graph2.Vertices[1], graph2.Vertices[5]));
            graph2.AddEdge(new DirectedEdge(graph2.Vertices[2], graph2.Vertices[1]));
            graph2.AddEdge(new DirectedEdge(graph2.Vertices[2], graph2.Vertices[5]));
            graph2.AddEdge(new DirectedEdge(graph2.Vertices[3], graph2.Vertices[4]));
            graph2.AddEdge(new DirectedEdge(graph2.Vertices[4], graph2.Vertices[2]));
            graph2.AddEdge(new DirectedEdge(graph2.Vertices[4], graph2.Vertices[3]));
            graph2.AddEdge(new DirectedEdge(graph2.Vertices[5], graph2.Vertices[6]));
            graph2.AddEdge(new DirectedEdge(graph2.Vertices[6], graph2.Vertices[4]));

            return(VariantSerializer.Serialize(new IGraph[]
            {
                graph1,
                graph2
            }));
        }
Exemple #3
0
        /// <summary> Сгенерировать отладочный вариант </summary>
        protected override TaskVariantDto GetDebugVariant()
        {
            var debugGraph1 = UndirectedGraph.CreateEmpty(7);

            debugGraph1.AddEdge(new UndirectedEdge(debugGraph1.Vertices[0], debugGraph1.Vertices[1]));
            debugGraph1.AddEdge(new UndirectedEdge(debugGraph1.Vertices[0], debugGraph1.Vertices[6]));
            debugGraph1.AddEdge(new UndirectedEdge(debugGraph1.Vertices[0], debugGraph1.Vertices[2]));
            var debugGraph2 = UndirectedGraph.CreateEmpty(7);

            debugGraph2.AddEdge(new UndirectedEdge(debugGraph2.Vertices[0], debugGraph2.Vertices[1]));
            debugGraph2.AddEdge(new UndirectedEdge(debugGraph2.Vertices[0], debugGraph2.Vertices[6]));
            debugGraph2.AddEdge(new UndirectedEdge(debugGraph2.Vertices[0], debugGraph2.Vertices[2]));
            var serializedVariant = VariantSerializer.Serialize(new IGraph[]
            {
                debugGraph1,
                debugGraph2
            });

            return(new TaskVariantDto
            {
                Data = serializedVariant,
                GeneratorVersion = "1.0",
                Number = "Debug",
                Version = 1
            });
        }
        /// <summary> Задание загружено </summary>
        /// <param name="e"></param>
        protected override void OnTaskLoadingComlete(VariantDownloadedEventArgs e)
        {
            // Мы вызваны из другого потока. Поэтому работаем с UI-элементами через Dispatcher.
            Dispatcher.BeginInvoke(() => { GivenGraph = VariantSerializer.Deserialize(e.Data)[0]; });

            //var number = e.Number; -- м.б. тоже где-то показать надо
            //var version = e.Version;
        }
Exemple #5
0
        public void TestSerializeVariantDto()
        {
            var graphs = CreateGraphs().ToArray();
            var dto    = VariantSerializer.Serialize(graphs);

            CollectionAssert.IsNotEmpty(dto);

            var deserializedGraphs = VariantSerializer.Deserialize(dto);

            Assert.That(deserializedGraphs.Count() == 2);
        }
        /// <summary> Задание загружено </summary>
        /// <param name="e"></param>
        protected override void OnTaskLoadingComlete(VariantDownloadedEventArgs e)
        {
            // Мы вызваны из другого потока. Поэтому работаем с UI-элементами через Dispatcher.
            Dispatcher.BeginInvoke(
                () =>
            {
                try
                {
                    GivenGraph = (UndirectedGraph)VariantSerializer.Deserialize(e.Data)[0];
                }
                catch (InvalidCastException ex)
                {
                    throw new InvalidCastException("Входной граф должен быть неориентированным.", ex);
                }

                MdsRows = new ObservableCollection <MdsRowViewModel>();
                DomSet  = new ObservableCollection <Vertex>();
                IsMouseVerticesMovingEnabled = true;
                var minDsCount = new MinDSEvaluator(GivenGraph);
                minDsCount.Evaluate(GivenGraph, true);
                RealMdsRows = new List <MdsRowViewModel>();
                foreach (var minDs in minDsCount.MinDs)
                {
                    var tempScc = new MdsRowViewModel(minDs);
                    RealMdsRows.Add(tempScc);
                }
                var minimalDsCount = new MinDSEvaluator(GivenGraph);
                minimalDsCount.Evaluate(GivenGraph, false);
                var tempCount = 0;
                foreach (var minDs in minimalDsCount.MinDs)
                {
                    tempCount++;
                }
                _task       = Task.TaskAdjacencyMatrix;
                _dsCount    = tempCount - 1;
                _countOfSes = _dsCount;

                var matrix = new ObservableCollection <CommonUI.Controls.ViewModels.MatrixRowViewModel <string> >();
                for (var i = 0; i < GivenGraph.VerticesCount; ++i)
                {
                    var row = new ObservableCollection <string> {
                        i.ToString()
                    };
                    for (var j = 0; j < GivenGraph.VerticesCount; ++j)
                    {
                        row.Add("0");
                    }

                    row.CollectionChanged += RowChanged;
                    matrix.Add(new CommonUI.Controls.ViewModels.MatrixRowViewModel <string>(row));
                }
                Matrix = matrix;
            });
        }
        /// <summary> Задание загружено </summary>
        /// <param name="e"></param>
        protected override void OnTaskLoadingComlete(VariantDownloadedEventArgs e)
        {
            // Мы вызваны из другого потока. Поэтому работаем с UI-элементами через Dispatcher.
            Dispatcher.BeginInvoke(() =>
            {
                var data     = VariantSerializer.Deserialize(e.Data);
                GivenGraph   = data[0];
                CurrentGraph = UndirectedGraph.CreateEmpty(GivenGraph.VerticesCount);
            });

            //var number = e.Number; -- м.б. тоже где-то показать надо
            //var version = e.Version;
        }
        /// <summary> Сгенерировать отладочный вариант </summary>
        protected override TaskVariantDto GetDebugVariant()
        {
            var debugGraph = DirectedGraph.CreateEmpty(7);

            debugGraph.AddEdge(new DirectedEdge(debugGraph.Vertices[0], debugGraph.Vertices[5]));
            debugGraph.AddEdge(new DirectedEdge(debugGraph.Vertices[1], debugGraph.Vertices[0]));
            debugGraph.AddEdge(new DirectedEdge(debugGraph.Vertices[1], debugGraph.Vertices[5]));
            debugGraph.AddEdge(new DirectedEdge(debugGraph.Vertices[2], debugGraph.Vertices[1]));
            debugGraph.AddEdge(new DirectedEdge(debugGraph.Vertices[2], debugGraph.Vertices[5]));
            debugGraph.AddEdge(new DirectedEdge(debugGraph.Vertices[3], debugGraph.Vertices[4]));
            debugGraph.AddEdge(new DirectedEdge(debugGraph.Vertices[4], debugGraph.Vertices[2]));
            debugGraph.AddEdge(new DirectedEdge(debugGraph.Vertices[4], debugGraph.Vertices[3]));
            debugGraph.AddEdge(new DirectedEdge(debugGraph.Vertices[5], debugGraph.Vertices[6]));
            debugGraph.AddEdge(new DirectedEdge(debugGraph.Vertices[6], debugGraph.Vertices[4]));
            var serializedGraph = VariantSerializer.Serialize(new IGraph[] { debugGraph });

            return(new TaskVariantDto
            {
                Data = serializedGraph,
                GeneratorVersion = "1.0",
                Number = "Debug",
                Version = 1
            });
        }