Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13365 was 13032, checked in by gkronber, 9 years ago

#1966:

  • removed unused using
  • added/updated license headers
File size: 4.5 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.Problems.BinPacking.Interfaces;
26using HeuristicLab.Problems.BinPacking.Shapes;
27using HeuristicLab.Data;
28using HeuristicLab.Common;
29using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
30
31namespace HeuristicLab.Problems.BinPacking.Evaluators {
32  [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")]
33  [StorableClass]
34  public abstract class PackingRatioRegularIdenticalBinEvaluator<D, B, I> : RegularSimpleRotationIdenticalBinPackingPlanEvaluator<D, B, I>
35    where D : class, IPackingDimensions
36    where B : PackingShape<D>, IPackingBin, IRegularPackingShape
37    where I : PackingShape<D>, IPackingItem, IRegularPackingShape {
38
39    [StorableConstructor]
40    protected PackingRatioRegularIdenticalBinEvaluator(bool deserializing) : base(deserializing) { }
41    protected PackingRatioRegularIdenticalBinEvaluator(PackingRatioRegularIdenticalBinEvaluator<D, B, I> original, Cloner cloner)
42      : base(original, cloner) {
43    }
44    public PackingRatioRegularIdenticalBinEvaluator() : base() { }
45
46    protected override DoubleValue Evaluate() {
47      DoubleValue quality = new DoubleValue(0);
48
49      IPackingPlan plan = PackingPlanParameter.ActualValue;
50      B binMeasure = PackingBinMeasuresParameter.ActualValue;
51      ItemList<I> itemMeasures = PackingItemMeasuresParameter.ActualValue;
52
53
54      //Check if data is valid
55      //if (plan.PackingItemPositions.Count != itemMeasures.Count)
56      //  throw new Exception("ERROR: ItemMeasures.count does not match packingPosition.count");
57
58
59      ////Check if any items are overlapping or not contained in their bins
60      //bool itemPositionsAreValid = !HasOverlappingOrNotContainedItems(plan.PackingItemPositions, binMeasure, itemMeasures, nrOfBins);
61
62
63
64      //if (itemPositionsAreValid)
65      return CalculatePackingRatio(plan as PackingPlan<D, B, I>);
66
67      //return quality;
68    }
69
70    /*
71        Falkenauer:1996 - A Hybrid Grouping Genetic Algorithm for Bin Packing
72       
73        fBPP = (SUM[i=1..N](Fi / C)^k)/N
74        N.......the number of bins used in the solution,
75        Fi......the sum of sizes of the items in the bin i (the fill of the bin),
76        C.......the bin capacity and
77        k.......a constant, k>1.
78     */
79    public static DoubleValue CalculatePackingRatio(PackingPlan<D, B, I> plan) {
80      int nrOfBins = plan.NrOfBins;
81      double result = 0;
82
83      //C
84      //double usableSpace = binMeasure.MultipliedMeasures;
85      //nrOfBins = N
86      for (int i = 0; i < nrOfBins; i++) {
87        //C
88        //double usableSpace = plan.GetPackingBinMeasuresForBinNr(0).MultipliedMeasures;//plan.GetPackingBinMeasuresForBinNr(i).MultipliedMeasures;
89        //var indexes = plan.PackingItemPositions.Select((Value, Index) => new { Value, Index }).Where(s => s.Value.Value.AssignedBin == i).Select(s => s.Index);
90        //var packedItemsInThisBin = plan.PackingItemMeasures.Select((Value, Index) => new { Value, Index }).Where(s => indexes.Contains(s.Index));
91        //Fi
92        //double usedSpaceInThisBin = packedItemsInThisBin.Select(s => s.Value.MultipliedMeasures).Sum();
93        //k = 2 --> (Fi/C)*(Fi/C)
94        //result += (((usedSpaceInThisBin) / (usableSpace)) * ((usedSpaceInThisBin) / (usableSpace))) / (i*i + 1);
95        var PD = plan.BinPackings[i].PackingDensity;
96        result += (PD * PD) / (i + 1);
97      }
98
99      result = result / nrOfBins;
100      return new DoubleValue (result);
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.