public static ResultDataAfterGrouping GroupingFlat(InputSectionDataAlg sectionData)
        {
            sectionData.ListLenOneFlat.Sort();
            sectionData.ListLenTwoFlat.Sort();

            var resultCalculateOneFlat = CalculateGroupingFlat(sectionData.OptCountFlat, sectionData.CountFloor, sectionData.ListLenOneFlat, true);
            var resultCalculateTwoFlat = CalculateGroupingFlat(sectionData.OptCountFlat, sectionData.CountFloor, sectionData.ListLenTwoFlat, false);
            var totalFine = CalculateTotalFine(resultCalculateOneFlat, resultCalculateTwoFlat);

            return(new ResultDataAfterGrouping(resultCalculateOneFlat.ListResultFlat, resultCalculateTwoFlat.ListResultFlat,
                                               totalFine, resultCalculateOneFlat.ListExcessFlat, resultCalculateTwoFlat.ListExcessFlat));
        }
        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);
        }
Example #3
0
        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);
        }
        public static void Validate(InputSectionDataAlg sectionData, bool isHeuristicAlgoritm)
        {
            //Выберите этаж
            if (sectionData.CountFloor == 0)
            {
                MessageBox.Show(MessagesText.NotSelectedFloor);
            }

            //Отсечка, следующие проверки только для полного перебора
            if (isHeuristicAlgoritm)
            {
                return;
            }

            //Полный перебор невозможен для 6+ контейнеров
            if (sectionData.ListLenOneFlat.Count / sectionData.CountFloor >= 12 && sectionData.ListLenTwoFlat.Count / sectionData.CountFloor >= 12)
            {
                MessageBox.Show(MessagesText.NotSixContaiters);
            }
        }
Example #5
0
        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);
        }
Example #6
0
        private void fullSearch_btn_Click(object sender, EventArgs e)
        {
            var dataCAlg = new InputSectionDataAlg();

            PerformComprehensiveSearch(dataCAlg);
        }
Example #7
0
        private void greedy_btn_Click(object sender, EventArgs e)
        {
            var dataHAlg = new InputSectionDataAlg();

            PerformHAlg(dataHAlg);
        }
Example #8
0
        private void dynam_btn_Click(object sender, EventArgs e)
        {
            var dataDAlg = new InputSectionDataAlg();

            PerformDAlg(dataDAlg);
        }