source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/BinUtilizationRegularIdenticalBinEvaluator.cs @ 14048

Last change on this file since 14048 was 14048, checked in by gkronber, 5 years ago

#1966: renamed *PackingDimension -> PackingPosition

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("Bin-Utilization Regular Identical-Bin Evaluator", "<Description missing> Found in Lee:2010")]
31  [StorableClass]
32  public abstract class BinUtilizationRegularIdenticalBinEvaluator<D, B, I> : RegularSimpleRotationIdenticalBinPackingPlanEvaluator<D, B, I>
33    where D : class, IPackingPosition
34    where B : PackingShape<D>
35    where I : PackingShape<D>, IPackingItem {
36
37    [StorableConstructor]
38    protected BinUtilizationRegularIdenticalBinEvaluator(bool deserializing) : base(deserializing) { }
39    protected BinUtilizationRegularIdenticalBinEvaluator(BinUtilizationRegularIdenticalBinEvaluator<D, B, I> original, Cloner cloner)
40      : base(original, cloner) {
41    }
42    public BinUtilizationRegularIdenticalBinEvaluator() : 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 CalculateBinUtilization(plan as PackingPlan<D, B, I>);
64
65      //return quality;
66    }
67
68    public static DoubleValue CalculateBinUtilization(PackingPlan<D, B, I> plan) {
69      int nrOfBins = plan.NrOfBins;
70      double result = 0;
71
72      //for (int i = 0; i < nrOfBins; i++) {
73      //  double usableSpace = plan.GetPackingBinMeasuresForBinNr(i).MultipliedMeasures;
74      //  var indexes = plan.PackingItemPositions.Select((Value, Index) => new { Value, Index }).Where(s => s.Value.Value.AssignedBin == i).Select(s => s.Index);
75      //  var packedItemsInThisBin = plan.PackingItemMeasures.Select((Value, Index) => new { Value, Index }).Where(s => indexes.Contains(s.Index));
76      //  double usedSpaceInThisBin = packedItemsInThisBin.Select(s => s.Value.MultipliedMeasures).Sum();
77      //  result += (usedSpaceInThisBin / usableSpace);
78      //}
79
80      //result = result / nrOfBins;
81      //return new DoubleValue (result);
82
83      double totalUsedSpace = 0;
84      double totalUsableSpace = 0;
85
86      for (int i = 0; i < nrOfBins; i++) {
87        double usableSpace = plan.BinPackings[i].BinMeasures.Volume;
88        //var indexes = plan.PackingItemPositions.Select((Value, Index) => new { Value, Index }).Where(s => s.Value.Value.AssignedBin == i).Select(s => s.Index);
89        //var packedItemsInThisBin = plan.PackingItemMeasures.Select((Value, Index) => new { Value, Index }).Where(s => indexes.Contains(s.Index));
90        //double usedSpaceInThisBin = packedItemsInThisBin.Select(s => s.Value.MultipliedMeasures).Sum();
91        //result += (usedSpaceInThisBin / usableSpace);
92        totalUsableSpace += usableSpace;
93        //totalUsedSpace += usedSpaceInThisBin;
94        totalUsedSpace += plan.BinPackings[i].PackingDensity * usableSpace;
95      }
96
97      result = totalUsedSpace / totalUsableSpace;
98      return new DoubleValue(result);
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.