Пример #1
0
        public void TestGreedyMethodeI2()
        {
            //tests 12flat 2Iter
            const int    optCountFlat = 6;
            const double optFine      = 3.0;
            const double oneFirstFlat = 6.6;
            const double startFlat    = 6.6;
            var          list1        = new List <double> {
                3.9, 6.0, 6.6, 6.6, 6.6, 7.2
            };
            var list2 = new List <double> {
                7.5, 7.5, 7.5, 7.8, 8.1, 8.7
            };
            var optItem1 = new List <double> {
                3.9, 6.0, 6.6, 6.6, 6.6, 7.2
            };
            var optItem2 = new List <double> {
                8.1, 8.7, 8.1, 7.5, 8.1, 7.5
            };

            var result = GreedyMethodeSect.GreedyMethode(new DataMethode(list1, list2, optCountFlat), startFlat, "Middle");

            Assert.AreEqual(result.FinalPlaceOneFlat.Except(optItem1).ToList().Count, 0);
            Assert.AreEqual(result.FinalPlaceTwoFlat.Except(optItem2).ToList().Count, 0);
            Assert.AreEqual(result.Fine, optFine);
            Assert.AreEqual(result.NewFirstOneFlat, oneFirstFlat);
        }
Пример #2
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);
        }