Exemplo n.º 1
0
        public void TestMethDynPr8()
        {
            const int    optCountFlat = 4;
            const double optFine      = 3.6;

            var list1 = new List <double> {
                3.9, 6.6, 6.6, 7.2
            };
            var list2 = new List <double> {
                7.5, 7.5, 7.8, 8.1
            };
            var optItem1 = new List <double> {
                3.9, 6.6, 6.6, 7.2
            };
            var optItem2 = new List <double> {
                8.1, 8.1, 8.7, 7.5
            };
            var listOneFlat = new List <double>();
            var listTwoFlat = new List <double>();

            var result         = DynamicMethodeSect.DynamicMethode(new DataMethode(list1, list2, optCountFlat));
            var listContainers = BackTrackForDynPr.BackTracking(result);

            Assert.AreEqual(Math.Round(listContainers.Last().FineChain, 1), optFine);
            foreach (var container in listContainers)
            {
                listOneFlat.Add(container.DataContainer.A1);
                listOneFlat.Add(container.DataContainer.A2);
                listTwoFlat.Add(container.DataContainer.B1);
                listTwoFlat.Add(container.DataContainer.B2);
            }
            Assert.AreEqual(listOneFlat.Except(optItem1).ToList().Count, 0);
            Assert.AreEqual(listTwoFlat.Except(optItem2).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);
        }