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);
        }
Esempio n. 2
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 ResultDataAfterGrouping FullSearch(DataPerformAlgorithm data, int optCountFlat)
        {
            var        result = new ResultDataAfterGrouping();
            const bool isPermutationForOneFlat  = true;
            const bool isPermutationForTwoFlat  = true;
            var        permListOneFlat          = Resursion.Data(data.ListLenOneFlat.Count, optCountFlat, isPermutationForOneFlat); //gereration permutations
            var        permListTwoFlat          = Resursion.Data(data.ListLenTwoFlat.Count, optCountFlat, isPermutationForTwoFlat); //gereration permutations
            var        permutDataOneFlat        = VariantsFlats.VariantsFlat(permListOneFlat, data.ListLenOneFlat);
            var        permutDataTwoFlat        = VariantsFlats.VariantsFlat(permListTwoFlat, data.ListLenTwoFlat);
            var        totalOptimalExceedSquare = double.MaxValue;

            var countI = -1;

            foreach (var i in permutDataOneFlat.ListVariantsFlat)
            {
                var countJ = -1;
                countI++;
                foreach (var j in permutDataTwoFlat.ListVariantsFlat)
                {
                    countJ++;
                    var resultApartLen = CreatePlacementForCompSearch.CreatePlacement(i, j, Constraints.StepH);

                    if (!(resultApartLen.FineAfterGrouping < totalOptimalExceedSquare))
                    {
                        continue;
                    }
                    totalOptimalExceedSquare = Math.Round(resultApartLen.FineAfterGrouping, 1);
                    result.Fine = resultApartLen.FineAfterGrouping;
                    result.ListResultOneFlat = resultApartLen.ListLenOneFlat;
                    result.ListResultTwoFlat = resultApartLen.ListLenTwoFlat;
                    result.ListExcessOneFlat = permutDataOneFlat.ListExceedFlat[countI].ToList();
                    result.ListExcessTwoFlat = permutDataTwoFlat.ListExceedFlat[countJ].ToList();
                }
            }
            return(result);
        }
Esempio n. 4
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);
        }