// Прием входных данных из формы или из .txt public InputSectionDataAlg() { CountFloor = Constraints.CountFloor; var listSquaresOneFlat = ReadFromFileAndRecordingInputDataInList.ReadFile(FilesDefault.DefaultListOneFlat); var listSquaresTwoFlat = ReadFromFileAndRecordingInputDataInList.ReadFile(FilesDefault.DefaultListTwoFlat); ListLenOneFlat = PreparationSquares.CalculateLengthOfFlat(listSquaresOneFlat, Constraints.WidthFlat[0]); ListLenTwoFlat = PreparationSquares.CalculateLengthOfFlat(listSquaresTwoFlat, Constraints.WidthFlat[0]); OptCountFlat = _calculateOptimalNumberFlat(ListLenOneFlat.Count, ListLenTwoFlat.Count, CountFloor); OptCountFlatOnFloor = OptCountFlat / CountFloor; }
private void PerformDAlg(InputSectionDataAlg inSectionData) { ValidateConditions.Validate(inSectionData, true); realizat_label.Text = "".ToString(CultureInfo.InvariantCulture); lossesOne_label.Text = "".ToString(CultureInfo.InvariantCulture); resultDynam_label.Text = "".ToString(CultureInfo.InvariantCulture); resultDynam_label.Text = string.Format(MessagesText.ResultDynamicProgram); var flatCount = inSectionData.ListLenOneFlat.Count + inSectionData.ListLenTwoFlat.Count; realizat_label.Text += string.Format(MessagesText.RealizationForRectangles, flatCount).ToString(CultureInfo.InvariantCulture); // lossesOne_label.Text += string.Format(MessagesText.SummarizeAdditionLengthForH, inData.SumDelta.ToString(CultureInfo.InvariantCulture)); var dataAlg = new DataPerformAlgorithm(); var resultDataAfterGrouping = GroupingOnTheFloors.GroupingFlat(inSectionData); dataAlg.ListLenOneFlat = PreparationSquares.FlatsWithTheAdditiveLength(resultDataAfterGrouping.ListResultOneFlat); dataAlg.ListLenTwoFlat = PreparationSquares.FlatsWithTheAdditiveLength(resultDataAfterGrouping.ListResultTwoFlat); var myStopWatchDynamic = new Stopwatch(); myStopWatchDynamic.Start(); // Create solution-tree var resultListDynM = DynamicMethodeSect.DynamicMethode(new DataMethode(dataAlg.ListLenOneFlat, dataAlg.ListLenTwoFlat, inSectionData.OptCountFlatOnFloor)); // Backtracking for optimal solution var backTrackingResult = BackTrackForDynPr.BackTracking(resultListDynM); // Print Result ( штраф по этажам и от группировки считаем внутри печати, а также приведение площадей) PrintResult.DynamicProgrammingPrintResult(backTrackingResult, inSectionData.CountFloor, resultDataAfterGrouping, resultDynam_label); myStopWatchDynamic.Stop(); resultDynam_label.Text += string.Format(MessagesText.WorkTimeDynamicProgram, myStopWatchDynamic.ElapsedMilliseconds / 1000.0).ToString(CultureInfo.InvariantCulture); }
private void PerformComprehensiveSearch(InputSectionDataAlg inSectionData) { ValidateConditions.Validate(inSectionData, false); realizat_label.Text = "".ToString(CultureInfo.InvariantCulture); lossesOne_label.Text = "".ToString(CultureInfo.InvariantCulture); resultFullSearch_label.Text = "".ToString(CultureInfo.InvariantCulture); var flatCount = inSectionData.ListLenOneFlat.Count + inSectionData.ListLenTwoFlat.Count; realizat_label.Text += string.Format(MessagesText.RealizationForRectangles, flatCount).ToString(CultureInfo.InvariantCulture); // lossesOne_label.Text += string.Format(MessagesText.SummarizeAdditionLengthForH, inData.SumDelta.ToString(CultureInfo.InvariantCulture)); var dataAlg = new DataPerformAlgorithm(); var resultDataAfterGrouping = GroupingOnTheFloors.GroupingFlat(inSectionData); dataAlg.ListLenOneFlat = PreparationSquares.FlatsWithTheAdditiveLength(resultDataAfterGrouping.ListResultOneFlat); dataAlg.ListLenTwoFlat = PreparationSquares.FlatsWithTheAdditiveLength(resultDataAfterGrouping.ListResultTwoFlat); dataAlg.FineAfterGrouping = resultDataAfterGrouping.Fine; var myStopWatch = new Stopwatch(); myStopWatch.Start(); var fullSearch = MethodeFullSearch.FullSearch(dataAlg, inSectionData.OptCountFlatOnFloor); fullSearch.Fine = Math.Round(fullSearch.Fine * inSectionData.CountFloor, 1); fullSearch.Fine = Math.Round(fullSearch.Fine + dataAlg.FineAfterGrouping, 1); fullSearch.ListExcessOneFlat = resultDataAfterGrouping.ListExcessOneFlat; fullSearch.ListExcessTwoFlat = resultDataAfterGrouping.ListExcessTwoFlat; PrintResult.FullSearchPrintResult(fullSearch, inSectionData.CountFloor, resultFullSearch_label); myStopWatch.Stop(); resultFullSearch_label.Text += MessagesText.NextLine; var timeFullSearch = string.Format(MessagesText.WorkTimeComprehensiveSearch, myStopWatch.ElapsedMilliseconds / 1000.0).ToString(CultureInfo.InvariantCulture); resultFullSearch_label.Text += timeFullSearch.ToString(CultureInfo.InvariantCulture); }
private void PerformHAlg(InputSectionDataAlg inSectionData) { ValidateConditions.Validate(inSectionData, true); realizat_label.Text = "".ToString(CultureInfo.InvariantCulture); lossesOne_label.Text = "".ToString(CultureInfo.InvariantCulture); resultGreedy_label.Text = "".ToString(CultureInfo.InvariantCulture); var flatCount = inSectionData.ListLenOneFlat.Count + inSectionData.ListLenTwoFlat.Count; realizat_label.Text += string.Format(MessagesText.RealizationForRectangles, flatCount).ToString(CultureInfo.InvariantCulture); // lossesOne_label.Text += string.Format(MessagesText.SummarizeAdditionLengthForH, inData.SumDelta.ToString(CultureInfo.InvariantCulture)); var dataAlg = new DataPerformAlgorithm(); var resultDataAfterGrouping = GroupingOnTheFloors.GroupingFlat(inSectionData); dataAlg.ListLenOneFlat = PreparationSquares.FlatsWithTheAdditiveLength(resultDataAfterGrouping.ListResultOneFlat); dataAlg.ListLenTwoFlat = PreparationSquares.FlatsWithTheAdditiveLength(resultDataAfterGrouping.ListResultTwoFlat); dataAlg.FineAfterGrouping = resultDataAfterGrouping.Fine; //for print in txt-file /* * var str1 = new StringBuilder(); * var str2 = new StringBuilder(); * foreach (var elem in dataAlg.ListLenOneFlat) * { * str1.Append(elem + " "); * } * * foreach (var elem in dataAlg.ListLenTwoFlat) * { * str2.Append(elem + " "); * } * * File.WriteAllText(@"C:\Users\marchenko.a\Downloads\Модифицированная Статья\ExampleTwoFirstList.txt", str1.ToString()); * File.WriteAllText(@"C:\Users\marchenko.a\Downloads\Модифицированная Статья\ExampleTwoSecondList.txt", str2.ToString()); */ var myStopWatchGreedy = new Stopwatch(); myStopWatchGreedy.Start(); var resultList = new ResultListGreedyMethode(); foreach (var flag in resultList.PositionStart) { var allIterationsResult = new ResultGreedyMethode[Constraints.NumberOfIteration]; var totalOptimalResult = new ResultGreedyMethode(double.MaxValue); var firstOneFlat = 0.0; // в RGreedyMethode var numberIteration = 1; while (numberIteration <= Constraints.NumberOfIteration) { var resultGreedyIter = GreedyMethodeSect.GreedyMethode( new DataMethode(dataAlg.ListLenOneFlat, dataAlg.ListLenTwoFlat, inSectionData.OptCountFlatOnFloor), firstOneFlat, flag); firstOneFlat = resultGreedyIter.NewFirstOneFlat; resultGreedyIter.NumIter = numberIteration; resultGreedyIter.Fine = Math.Round(resultGreedyIter.Fine * inSectionData.CountFloor, 1); resultGreedyIter.Fine = Math.Round(resultGreedyIter.Fine + dataAlg.FineAfterGrouping, 1); resultGreedyIter.ListLenExceedOneFlat = resultDataAfterGrouping.ListExcessOneFlat; resultGreedyIter.ListLenExceedTwoFlat = resultDataAfterGrouping.ListExcessTwoFlat; allIterationsResult[numberIteration - 1] = resultGreedyIter; if (resultGreedyIter.Fine < totalOptimalResult.Fine) { totalOptimalResult = resultGreedyIter; } //Вывод результата по итерациям //PrintResult.GreedyIterationPrintResult(resultGreedyIter, inData.CountFloor, true, resultGreedy_label); numberIteration++; if (numberIteration > Constraints.NumberOfIteration) { resultList.Results.Add(totalOptimalResult); } } } myStopWatchGreedy.Stop(); PrintResult.GreedyIterationPrintResult(resultList.Results.OrderBy(a => a.Fine).First(), inSectionData.CountFloor, false, resultGreedy_label); resultGreedy_label.Text += string.Format(MessagesText.WorkTimeHeuristicAlgoruthm, myStopWatchGreedy.ElapsedMilliseconds / 1000.0).ToString(CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); }