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); }
private void RefreshMatrixUi() { _UIMatrix = MatrixMethod.GenerateUIMatrix(_UIMatrix, Graph); DataTable = new DataTable(); MatrixMethod.SetMatrixColumns(DataTable); MatrixMethod.FillDataTable(_UIMatrix, DataTable); DataView = DataTable.DefaultView; NotifyPropertyChanged("Graph"); NotifyPropertyChanged("DataView"); NotifyPropertyChanged("UndirectedGraph"); }
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(); }
public static Vector Solve(this Matrix matrix, Vector vector, MatrixMethod method = MatrixMethod.LU) { switch (method) { case MatrixMethod.LU: return(LU.Solve(matrix, vector)); case MatrixMethod.Cholesky: return(Cholesky.Solve(matrix, vector)); case MatrixMethod.SVD: return(SVD.Solve(matrix, vector)); default: throw new IndexOutOfRangeException(nameof(method)); } }
public static Matrix Inverse(this Matrix matrix, MatrixMethod method = MatrixMethod.LU) { switch (method) { case MatrixMethod.LU: return(LU.Inverse(matrix)); case MatrixMethod.Cholesky: return(Cholesky.Inverse(matrix)); case MatrixMethod.SVD: return(SVD.Inverse(matrix)); default: throw new IndexOutOfRangeException(nameof(method)); } }
private void Button_Click_2(object sender, RoutedEventArgs e) { MatrixMethod mm1 = ((Grid)((TabItem)MainTabs.Items.Cast <TabItem>().Where(x => x.Header == ((ListBoxItem)MatrixOp1.SelectedItem).Content).First()).Content).Children .Cast <view.MatrixViewer>().First().getMatrixMethod(); MatrixMethod mm2 = ((Grid)((TabItem)MainTabs.Items.Cast <TabItem>().Where(x => x.Header == ((ListBoxItem)MatrixOp2.SelectedItem).Content).First()).Content).Children .Cast <view.MatrixViewer>().First().getMatrixMethod(); MatrixMethod result = null; switch (((ListBoxItem)MatrixAction.SelectedItem).Name) { case "Add": result = mm1.Add(mm2); break; case "Subtract": result = mm1.Subtract(mm2); break; case "Multiplication": result = mm1.MatrixMultiplication(mm2); break; } if (result != null) { MessageBox.Show("Операция заняла " + result.sw.Elapsed.ToString()); TabItem tabItem = new TabItem(); tabItem.Name = "matrix" + (MainTabs.Items.Count + 1); tabItem.Header = "Матрица " + (MainTabs.Items.Count + 1); Grid grid = new Grid(); view.MatrixViewer matrixViewer = new view.MatrixViewer(result); matrixViewer.Name = "Viewer" + (MainTabs.Items.Count + 1); matrixViewer.HorizontalAlignment = HorizontalAlignment.Left; matrixViewer.Height = 478; matrixViewer.Margin = new Thickness(10, 10, -868, -449); matrixViewer.VerticalAlignment = VerticalAlignment.Top; matrixViewer.Width = 948; grid.Children.Add(matrixViewer); tabItem.Content = grid; MainTabs.Items.Add(tabItem); } }