Exemple #1
0
        private async void calculateMatrix(object sender, RoutedEventArgs e)
        {
            try
            {
                matrixToCalc = getMatrixFromGrid(gridTextBox);
                Matrix matrixCopy = getMatrixFromGrid(gridTextBox);
                matrixCopy = HungarianAlgorithm.subMinFromRow(matrixCopy);
                matrixCopy = HungarianAlgorithm.subMinFromCols(matrixCopy);
                matrixCopy = HungarianAlgorithm.markLines(matrixCopy);
                matrixCopy = HungarianAlgorithm.testResult(matrixCopy);

                for (int i = 0; i < matrixCopy.getMatrix().GetLength(0); ++i)
                {
                    for (int j = 0; j < matrixCopy.getMatrix().GetLength(1); ++j)
                    {
                        if (matrixCopy.getMatrix()[i, j] == 999)
                        {
                            matrixCopy.setCell(i, j, 1);
                            gridTextBox[i, j].Background = new SolidColorBrush((Color)Application.Current.Resources["SystemAccentColorLight2"]);
                        }
                        else
                        {
                            matrixCopy.setCell(i, j, 0);
                        }
                    }
                }

                int cost = 0;
                for (int i = 0; i < matrixToCalc.getMatrix().GetLength(0); ++i)
                {
                    for (int j = 0; j < matrixToCalc.getMatrix().GetLength(1); ++j)
                    {
                        cost += matrixToCalc.getMatrix()[i, j] * matrixCopy.getMatrix()[i, j];
                    }
                }
                resultGrid.Visibility        = Visibility.Visible;
                resultGrid.Opacity           = 0;
                resultGrid.OpacityTransition = new ScalarTransition()
                {
                    Duration = new TimeSpan(0, 0, 0, 0, 500)
                };
                resultGrid.Opacity   = 1;
                resultTextBlock.Text = "Wynik: " + cost.ToString();

                matrixGrid.Visibility        = Visibility.Visible;
                matrixGrid.Opacity           = 0;
                matrixGrid.OpacityTransition = new ScalarTransition()
                {
                    Duration = new TimeSpan(0, 0, 0, 0, 500)
                };
                matrixGrid.Opacity = 1;
            }
            catch (Exception exp)
            {
                ContentDialog dialog = new ContentDialog {
                    Title = "Error", Content = exp.Message, CloseButtonText = "ok"
                };
                ContentDialogResult result = await dialog.ShowAsync();
            }
        }