public void VisualizeSolution(IMatrix <int> matrix, ISolution solution) { var max = CoreUtilities.Utilities.Max(matrix); var min = CoreUtilities.Utilities.Min(matrix); var criterion = MinMaxCriterium.Calculate(matrix, solution); var splitted = new SplittedMatrix(matrix, solution); var solutionVisualizer = new SolutionVisualizerForm(splitted, matrix, solution, min, max, criterion); solutionVisualizer.Draw(); solutionVisualizer.Show(); }
public Test_result(IMatrixReadStorage <int, EmptyData> storage, IMatrixReadStorage <int, SolutionData> datastorage, IAlgorithm <int> algorithm, PartitioningParameters parameters) { results = new AllResults(); InitializeComponent(); foreach (var matrixData in storage.ReadMatrixes()) { string name = matrixData.Name; IMatrix <int> matrix = matrixData.Matrix; int n = matrixData.Matrix.Size(0); int m = matrixData.Matrix.Size(1); int M1 = parameters[0]; int M2 = parameters[1]; Int64 start = Stopwatch.GetTimestamp(); ISolution solution = algorithm.Run(matrix); double time = (Stopwatch.GetTimestamp() - start) / (double)Stopwatch.Frequency; double crit = MinMaxCriterium.Calculate(matrix, solution); double w = Utilities.W(matrix, parameters); double diff = crit - w; results.AddElem(new Note(name, n, m, M1, M2, crit, diff, 0, time, false)); } foreach (var matrixData in datastorage.ReadMatrixes()) { string name = matrixData.Name; IMatrix <int> matrix = matrixData.Matrix; int n = matrixData.Matrix.Size(0); int m = matrixData.Matrix.Size(1); PartitioningParameters dataParameters = matrixData.Data.Item1; int M1 = dataParameters[0]; int M2 = dataParameters[1]; double goodCrit = matrixData.Data.Item3; Int64 start = Stopwatch.GetTimestamp(); ISolution solution = algorithm.Run(matrix); double time = (Stopwatch.GetTimestamp() - start) / (double)Stopwatch.Frequency; double crit = CoreUtilities.Utilities.Max(new SplittedMatrix(matrix, solution)); double w = Utilities.W(matrix, dataParameters); double diff = crit - w; double goodDiff = crit - goodCrit; results.AddElem(new Note(name, n, m, M1, M2, crit, diff, goodDiff, time, true)); } results.GetGroups(GroupedResults); }
public ISolution Run(IMatrix <int> matrix) { double best_f = double.MaxValue; int[] best_x = null; int[] best_y = null; bool best_x_changed = false; int m = matrix.Size(0); int n = matrix.Size(1); int[] x = new int[M - 1]; int[] y = new int[N - 1]; var solution = new ArraySolution(x, y); if (M == 1) { best_x = x; if (N == 1) { best_y = y; } else { int currentY = 0; y[0] = 1; while (true) { if (y[currentY] > n + currentY - N) { currentY--; if (currentY < 0) { break; } y[currentY]++; } else if (currentY < N - 2) { currentY++; y[currentY] = y[currentY - 1] + 1; } else { double f = MinMaxCriterium.Calculate(matrix, solution); if (f < best_f) { best_f = f; best_y = (int[])y.Clone(); } y[currentY]++; } } } } else { int currentX = 0; x[0] = 1; while (true) { if (x[currentX] > m + currentX - M) { currentX--; if (currentX < 0) { break; } x[currentX]++; } else if (currentX < M - 2) { currentX++; x[currentX] = x[currentX - 1] + 1; } else { int currentY = 0; y[0] = 1; while (true) { if (y[currentY] > n + currentY - N) { currentY--; if (currentY < 0) { break; } y[currentY]++; } else if (currentY < N - 2) { currentY++; y[currentY] = y[currentY - 1] + 1; } else { double f = MinMaxCriterium.Calculate(matrix, solution); if (f < best_f) { best_f = f; best_y = (int[])y.Clone(); best_x_changed = true; } y[currentY]++; } } if (best_x_changed) { best_x = (int[])x.Clone(); best_x_changed = false; } x[currentX]++; } } } return(new ArraySolution(best_x, best_y)); }