Пример #1
0
        public void TestGroupingThreeExceed()
        {
            const int    countFloor = 4;
            const double optFine    = 3.0;
            var          list1      = new List <double> {
                6.6, 7.2, 3.3, 4.8, 3.9, 7.2, 6.6, 6.6, 6.6, 6.3, 6.0
            };
            var list2 = new List <double> {
                7.2, 7.5, 8.1, 7.5, 7.5, 7.5, 7.5, 8.1, 7.8, 8.4, 8.7
            };
            var optItem1 = new List <double> {
                6.6, 7.2
            };
            var optItem2 = new List <double> {
                7.5, 8.1
            };
            var optItem3 = new List <double> {
                3.3, 3.9, 4.8
            };
            var optItem4 = new List <double> {
                7.2, 8.4, 8.7
            };

            var result = GroupingOnTheFloors.GroupingFlat(new InputSectionDataAlg(list1, list2, countFloor));

            Assert.AreEqual(result.ListResultOneFlat.Except(optItem1).ToList().Count, 0);
            Assert.AreEqual(result.ListResultTwoFlat.Except(optItem2).ToList().Count, 0);
            Assert.AreEqual(result.Fine, optFine);
            Assert.AreEqual(result.ListExcessOneFlat.Except(optItem3).ToList().Count, 0);
            Assert.AreEqual(result.ListExcessTwoFlat.Except(optItem4).ToList().Count, 0);
        }
        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);
        }
Пример #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);
        }
Пример #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);
        }