Free cookie consent management tool by TermsFeed Policy Generator

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