Ejemplo n.º 1
0
        public void ReLayoutGraph()
        {
            //dane potrzebne w metodach obsługujących macierz
            MatrixMethod.NumberOfVertices = _numberOfVertices;
            MatrixMethod.ProbabilityValue = _probabilityValue;

            Graph             = new Graph(true);              //nowy graf
            _matrix           = MatrixMethod.FillTheMatrix(); //macierz incydencji
            _existingVertices = new List <Vertex>();          //lista przechowująca wierzchołki

            //wygenerowanie odpowiedniej ilości wierzchołków
            for (int i = 0; i < _numberOfVertices; i++)
            {
                _existingVertices.Add(new Vertex((i + 1).ToString(), i));
                Graph.AddVertex(_existingVertices[i]);
            }

            //generowanie krawędzi na podstawie macierzy
            EdgeMethod.GenerateEdges(_matrix, _existingVertices, Graph);

            //suma jest zapisana w ostatniej kolumnie macierzy oraz we właściwości obiektu vertex(VertexDegree)<=potrzebne w naprawie
            VertexMethod.CalculateTheSum(_matrix, _existingVertices);

            //zapisanie wierzołków sąsiadujących ze sobą(potrzebne w naprawie)
            VertexMethod.SetVertexNeighbors(_matrix, _existingVertices);

            UndirectedGraph = new UndirectedBidirectionalGraph <Vertex, Edge>(Graph);//coś jak canvas


            RefreshMatrixUi();//odświeżenie UI
        }
        private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            //Example graph from AI
            GraphGenerationMethods graphGenerator = new GraphGenerationMethods(_parameters);

            graphGenerator.GenerateTriangulationOfGraph();

            //Refresh pareto front
            var cutsSum     = EdgeMethod.GetCutsWeightsSum(_parameters.GeneratedBasicGraph, _parameters.Population);
            var cutsCount   = EdgeMethod.GetCutsCount(_parameters.GeneratedBasicGraph, _parameters.Population);
            var paretoArray = cutsCount.
                              Zip(cutsSum, (first, second) => (first, second)).
                              Select(x => new double[] { x.first, x.second }).ToList();

            _parameters.RewriteThePoints(paretoArray);
            _parameters.MainWindow.ParetoChart.EditSeriesCollection(_parameters.ListOfPoints);

            //aktualizacja macierzy incydencji
            MatrixMethod matrixMethod = new MatrixMethod(_parameters);

            _parameters.incidenceMatrix = matrixMethod.FillTheSecondHalfOfTheMatrix(_parameters.incidenceMatrix);

            _parameters.GeneratedBasicGraph = EdgeMethod.GenerateEdges(_parameters.incidenceMatrix, _parameters.verticesBasicGeneratedGraph, _parameters.GeneratedBasicGraph);

            //aktualizacja wyświetlanej macierzy incydencji i wag (frontend)
            VertexMethod.CalculateTheSum(_parameters.incidenceMatrix, _parameters.verticesTriangulationOfGraph);
            VertexMethod.SetVertexNeighbors(_parameters.incidenceMatrix, _parameters.verticesTriangulationOfGraph);

            _parameters.MainWindow.OverallFluctuationChart.EditASeries(
                _parameters.FitnessArray.Average(),
                _parameters.IterationNumber);

            _parameters.MainWindow.SecondChart.EditBSeries(
                _parameters.FitnessArray.Min(),
                _parameters.IterationNumber);

            var minimumFitnessGraphIndex = _parameters.FitnessArray.ToList().IndexOf(_parameters.FitnessArray.Min());

            //var minimumFitnessGraphIndex = 0;
            _parameters.CountedExtremum = $"({cutsCount[minimumFitnessGraphIndex]}; {cutsSum[minimumFitnessGraphIndex]})";

            _parameters.MainWindow.ProgressBar.Value = _parameters.IterationNumber;

            _parameters.CurrentGroupsVertices = GraphGenerationMethods.GetGroupsVertices(
                _parameters.GeneratedBasicGraph,
                _parameters.Population,
                minimumFitnessGraphIndex);
            string groupsVerticesString = "";

            if (_parameters.CurrentGroupsVertices.ContainsValue(0))
            {
                groupsVerticesString += "Warning: group 0 detected. ";
            }
            _parameters.CurrentGroupsVertices.OrderBy(x => x.Key.Index).ToList().ForEach(x => groupsVerticesString += $"V: {x.Key.Index + 1}, G: {x.Value}; ");
            _parameters.MainWindow.GroupList.Content = groupsVerticesString;

            matrixMethod.RefreshMatrixUi(_parameters.TriangulationOfGraph);

            _parameters.MainWindow.ResetZoomControl(_parameters.MainWindow.TriangulationGraphZoomControl);
        }
Ejemplo n.º 3
0
        private void worker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
        {
            ////aktualizacja macierzy

            _matrix = MatrixMethod.FillTheSecondHalfOfTheMatrix(_matrix);
            //EdgeMethod.RemoveAllGraphEdges(Graph);

            Graph = EdgeMethod.GenerateEdges(_matrix, _existingVertices, Graph);

            // int edgeCounter = Graph.Edges.Count();
            ////aktualizacja tabeli
            VertexMethod.CalculateTheSum(_matrix, _existingVertices);
            VertexMethod.SetVertexNeighbors(_matrix, _existingVertices);

            RefreshMatrixUi();
        }
Ejemplo n.º 4
0
 //sprawdzanie czy eulerowski
 public bool CheckIfEuler()
 {
     VertexMethod.SetVertexNeighbors(_UIMatrix, _existingVertices);
     return(EulerChecker.CheckIfEuler(Graph, EdgesToColor, SleepTime, ref EulerPath));
 }
Ejemplo n.º 5
0
        //metoda naprawy grafów autorem jest Owner, zrobiłem delikatny tunining-> mniej się sypie xd
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            var workerGraph = Graph;
            var selector    = VertexMethod.GetVertexDegreeInfo(_matrix, _existingVertices);

            if (Graph.Edges.Count() >= 1)
            {
                while (selector[1].Count > 0)
                {
                    while (selector[0].Count > 0)
                    {
                        if (selector[1].Count >= 2)
                        {
                            var start = selector[0].Pop();
                            var end1  = selector[1].Pop();
                            var end2  = selector[1].Pop();

                            _matrix[start.Index][end1.Index] = 1;
                            _matrix[end1.Index][start.Index] = 1;
                            _matrix[start.Index][end2.Index] = 1;
                            _matrix[end2.Index][start.Index] = 1;
                            Report();
                        }

                        selector = VertexMethod.GetVertexDegreeInfo(_matrix, _existingVertices);
                        //(selector[1].Count == 0 && selector[0].Count > 0)

                        /*                             var start = selector[0].Pop();
                         *  var end = selector[2].Pop();
                         *  _matrix[start.Index][end.Index] = 1;
                         *  _matrix[end.Index][start.Index] = 1;
                         *  if (end.Neighbors.Count > 0)
                         *  {
                         *      _matrix[start.Index][end.Neighbors[0].Index] = 1;
                         *      _matrix[end.Neighbors[0].Index][start.Index] = 1;
                         *      _matrix[end.Index][end.Neighbors[0].Index] = 0;
                         *      _matrix[end.Neighbors[0].Index][end.Index] = 0;
                         *      Report();
                         *  }*/

                        if (selector[1].Count == 0 && selector[0].Count > 0)
                        {
                            var start = selector[0].Pop();
                            var end   = selector[2].Pop();
                            _matrix[start.Index][end.Index] = 1;
                            _matrix[end.Index][start.Index] = 1;
                            _matrix[start.Index][end.Neighbors[0].Index] = 1;
                            _matrix[end.Neighbors[0].Index][start.Index] = 1;
                            _matrix[end.Index][end.Neighbors[0].Index]   = 0;
                            _matrix[end.Neighbors[0].Index][end.Index]   = 0;
                            //EdgeMethod.RemoveTheEdge(Graph, end.Index, end.Neighbors[0].Index);


                            Report();
                        }
                        Report();
                    }

                    while (selector[1].Count > 0)
                    {
                        List <Vertex> connection = new List <Vertex>();
                        connection.Add(selector[1].Pop());
                        connection.Add(selector[1].Pop());
                        Report();
                        if (_matrix[connection[0].Index][connection[1].Index] == 1)
                        {
                            if (connection[0].Neighbors.Count == 1 && connection[1].Neighbors.Count == 1)
                            {
                                _matrix[connection[0].Index][connection[1].Index] = 0;
                                _matrix[connection[1].Index][connection[0].Index] = 0;
                                //EdgeMethod.RemoveTheEdge(Graph, connection[0].Index, connection[1].Index);
                                Report();
                            }
                            else
                            {
                                if (connection[0].Neighbors.Count > 1)
                                {
                                    var helpList = connection[0].Neighbors.Where(v => v.Index != connection[1].Index).ToList();

                                    _matrix[connection[0].Index][helpList[0].Index] = 0;
                                    _matrix[helpList[0].Index][connection[0].Index] = 0;
                                    //EdgeMethod.RemoveTheEdge(Graph, connection[0].Index, helpList[0].Index);
                                    Report();
                                }
                                else
                                {
                                    var helpList = connection[1].Neighbors.Where(v => v.Index != connection[0].Index).ToList();

                                    //if (helpList.Count > 0 && connection.Count > 0)
                                    //{
                                    _matrix[connection[1].Index][helpList[0].Index] = 0;
                                    _matrix[helpList[0].Index][connection[1].Index] = 0;
                                    //EdgeMethod.RemoveTheEdge(Graph, connection[1].Index, helpList[0].Index);

                                    Report();
                                    //}
                                }
                            }
                        }
                        else
                        {
                            _matrix[connection[0].Index][connection[1].Index] = 1;
                            _matrix[connection[1].Index][connection[0].Index] = 1;
                            Report();
                        }
                        Report();
                        selector = VertexMethod.GetVertexDegreeInfo(_matrix, _existingVertices);
                    }
                    selector = VertexMethod.GetVertexDegreeInfo(_matrix, _existingVertices);
                    //if (selector[1].Count == 2)
                    //{
                    //    Report();
                    //    break;
                    //}
                    Report();
                }
            }
            else
            {
                for (int i = 0; i < _existingVertices.Count; i++)
                {
                    if (i == 0)
                    {
                        _matrix[i][i + 1] = 1;
                        _matrix[i][_existingVertices.Count - 1] = 1;
                        Report();
                    }
                    else if (i == _existingVertices.Count - 1)
                    {
                        _matrix[i][0] = 1;
                        _matrix[i][_existingVertices.Count - 1] = 1;
                        Report();
                    }
                    else
                    {
                        _matrix[i][i + 1] = 1;
                        _matrix[i][i - 1] = 1;
                        Report();
                    }
                }
            }
            Report();
            RefreshMatrixUi();
            worker.CancelAsync();
        }