Beispiel #1
0
        // NOTE: same implementation as for 2d problem
        public virtual void Analyze(TSol[] individuals, double[] qualities, ResultCollection results, IRandom random)
        {
            var bestSolutionResultName  = "Best Packing Solution";
            var numContainersResultName = "Nr of Containers";
            var binUtilResultName       = "Overall Bin Utilization";

            if (!results.ContainsKey(bestSolutionResultName))
            {
                results.Add(new Result(bestSolutionResultName, typeof(Solution)));
            }
            if (!results.ContainsKey(numContainersResultName))
            {
                results.Add(new Result(numContainersResultName, typeof(IntValue)));
            }
            if (!results.ContainsKey(binUtilResultName))
            {
                results.Add(new Result(binUtilResultName, typeof(DoubleValue)));
            }


            // find index of item with max quality
            int bestIdx = 0;

            for (int j = 1; j < qualities.Length; j++)
            {
                if (qualities[j] > qualities[bestIdx])
                {
                    bestIdx = j;
                }
            }


            // update best solution so far
            var bestSolution = results[bestSolutionResultName].Value as Solution;

            if (bestSolution == null ||
                bestSolution.Quality.Value < qualities[bestIdx])
            {
                var newBestSolution = Decoder.Decode(individuals[bestIdx], BinShape, Items, UseStackingConstraints);
                newBestSolution.Quality = new DoubleValue(qualities[bestIdx]);
                results[bestSolutionResultName].Value  = newBestSolution;
                results[numContainersResultName].Value = new IntValue(newBestSolution.NrOfBins);
                results[binUtilResultName].Value       = new DoubleValue(BinUtilizationEvaluator.CalculateBinUtilization(newBestSolution));

                // update best known solution
                var bestKnownQuality = BestKnownQualityParameter.Value;
                if (bestKnownQuality == null ||
                    bestKnownQuality.Value < qualities[bestIdx])
                {
                    BestKnownQualityParameter.ActualValue  = new DoubleValue(qualities[bestIdx]);
                    BestKnownSolutionParameter.ActualValue = newBestSolution;
                }
            }
        }
Beispiel #2
0
        protected override void Run(CancellationToken token)
        {
            var items   = Problem.Items;
            var bin     = Problem.BinShape;
            var sorting = new[] { SortingMethodParameter.Value.Value };

            if (sorting[0] == SortingMethod.All)
            {
                sorting = Enum.GetValues(typeof(SortingMethod)).Cast <SortingMethod>().Where(x => x != SortingMethod.All).ToArray();
            }
            var fitting = new[] { fittingMethodParameter.Value.Value };

            if (fitting[0] == FittingMethod.All)
            {
                fitting = Enum.GetValues(typeof(FittingMethod)).Cast <FittingMethod>().Where(x => x != FittingMethod.All).ToArray();
            }
            var result = GetBest(bin, items, sorting, fitting, token);

            if (result == null)
            {
                throw new InvalidOperationException("No result obtained!");
            }

            Results.Add(new Result("Best Solution",
                                   "The best found solution",
                                   result.Item1));
            Results.Add(new Result("Best Solution Quality",
                                   "The quality of the best found solution according to the evaluator",
                                   new DoubleValue(result.Item2)));

            var binUtil   = new BinUtilizationEvaluator();
            var packRatio = new PackingRatioEvaluator();

            Results.Add(new Result("Best Solution Bin Count",
                                   "The number of bins in the best found solution",
                                   new IntValue(result.Item1.NrOfBins)));
            Results.Add(new Result("Best Solution Bin Utilization",
                                   "The utilization given in percentage as calculated by the BinUtilizationEvaluator (total used space / total available space)",
                                   new PercentValue(Math.Round(binUtil.Evaluate(result.Item1), 3))));

            if (result.Item3.HasValue && sorting.Length > 1)
            {
                Results.Add(new Result("Best Sorting Method",
                                       "The sorting method that found the best solution",
                                       new EnumValue <SortingMethod>(result.Item3.Value)));
            }
            if (result.Item4.HasValue && fitting.Length > 1)
            {
                Results.Add(new Result("Best Fitting Method",
                                       "The fitting method that found the best solution",
                                       new EnumValue <FittingMethod>(result.Item4.Value)));
            }
        }
 protected BinUtilizationEvaluator(BinUtilizationEvaluator original, Cloner cloner)
     : base(original, cloner)
 {
 }
 protected BinUtilizationEvaluator(BinUtilizationEvaluator original, Cloner cloner)
   : base(original, cloner) {
 }