Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/PackingRatioRegularIdenticalBinEvaluator.cs @ 14046

Last change on this file since 14046 was 14046, checked in by gkronber, 8 years ago

#1966: unified namespaces

File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22
23using HeuristicLab.Core;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25using HeuristicLab.Data;
26using HeuristicLab.Common;
27using HeuristicLab.Encodings.PackingEncoding;
28
29namespace HeuristicLab.Problems.BinPacking {
30  [Item("Packing-Ratio Regular Identical-Bin Evaluator", "Represents an evaluation-algorithm for regular-shaped bin-packing problems with identical bins which calculates the ratio between packed and unpacked space. Found in Falkenauer:1996")]
31  [StorableClass]
32  public abstract class PackingRatioRegularIdenticalBinEvaluator<D, B, I> : RegularSimpleRotationIdenticalBinPackingPlanEvaluator<D, B, I>
33    where D : class, IPackingDimensions
34    where B : PackingShape<D>
35    where I : PackingShape<D>, IPackingItem {
36
37    [StorableConstructor]
38    protected PackingRatioRegularIdenticalBinEvaluator(bool deserializing) : base(deserializing) { }
39    protected PackingRatioRegularIdenticalBinEvaluator(PackingRatioRegularIdenticalBinEvaluator<D, B, I> original, Cloner cloner)
40      : base(original, cloner) {
41    }
42    public PackingRatioRegularIdenticalBinEvaluator() : base() { }
43
44    protected override DoubleValue Evaluate() {
45      DoubleValue quality = new DoubleValue(0);
46
47      IPackingPlan plan = PackingPlanParameter.ActualValue;
48      B binMeasure = PackingBinMeasuresParameter.ActualValue;
49      ItemList<I> itemMeasures = PackingItemMeasuresParameter.ActualValue;
50
51
52      //Check if data is valid
53      //if (plan.PackingItemPositions.Count != itemMeasures.Count)
54      //  throw new Exception("ERROR: ItemMeasures.count does not match packingPosition.count");
55
56
57      ////Check if any items are overlapping or not contained in their bins
58      //bool itemPositionsAreValid = !HasOverlappingOrNotContainedItems(plan.PackingItemPositions, binMeasure, itemMeasures, nrOfBins);
59
60
61
62      //if (itemPositionsAreValid)
63      return CalculatePackingRatio(plan as PackingPlan<D, B, I>);
64
65      //return quality;
66    }
67
68    /*
69        Falkenauer:1996 - A Hybrid Grouping Genetic Algorithm for Bin Packing
70       
71        fBPP = (SUM[i=1..N](Fi / C)^k)/N
72        N.......the number of bins used in the solution,
73        Fi......the sum of sizes of the items in the bin i (the fill of the bin),
74        C.......the bin capacity and
75        k.......a constant, k>1.
76     */
77    public static DoubleValue CalculatePackingRatio(PackingPlan<D, B, I> plan) {
78      int nrOfBins = plan.NrOfBins;
79      double result = 0;
80
81      //C
82      //double usableSpace = binMeasure.MultipliedMeasures;
83      //nrOfBins = N
84      for (int i = 0; i < nrOfBins; i++) {
85        //C
86        //double usableSpace = plan.GetPackingBinMeasuresForBinNr(0).MultipliedMeasures;//plan.GetPackingBinMeasuresForBinNr(i).MultipliedMeasures;
87        //var indexes = plan.PackingItemPositions.Select((Value, Index) => new { Value, Index }).Where(s => s.Value.Value.AssignedBin == i).Select(s => s.Index);
88        //var packedItemsInThisBin = plan.PackingItemMeasures.Select((Value, Index) => new { Value, Index }).Where(s => indexes.Contains(s.Index));
89        //Fi
90        //double usedSpaceInThisBin = packedItemsInThisBin.Select(s => s.Value.MultipliedMeasures).Sum();
91        //k = 2 --> (Fi/C)*(Fi/C)
92        //result += (((usedSpaceInThisBin) / (usableSpace)) * ((usedSpaceInThisBin) / (usableSpace))) / (i*i + 1);
93        var PD = plan.BinPackings[i].PackingDensity;
94        result += (PD * PD) / (i + 1);
95      }
96
97      result = result / nrOfBins;
98      return new DoubleValue(result);
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.