[9348] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[13032] | 3 | * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[9348] | 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 |
|
---|
[13032] | 22 |
|
---|
[9348] | 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 25 | using HeuristicLab.Problems.BinPacking.Interfaces;
|
---|
| 26 | using HeuristicLab.Problems.BinPacking.Shapes;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Common;
|
---|
[9440] | 29 | using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
|
---|
[9348] | 30 |
|
---|
| 31 | namespace 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
|
---|
[14045] | 36 | where B : PackingShape<D>
|
---|
[14043] | 37 | where I : PackingShape<D>, IPackingItem {
|
---|
[9348] | 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)
|
---|
[9563] | 65 | return CalculateBinUtilization(plan as PackingPlan<D, B, I>);
|
---|
[9348] | 66 |
|
---|
| 67 | //return quality;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[9563] | 70 | public static DoubleValue CalculateBinUtilization(PackingPlan<D, B, I> plan) {
|
---|
[9440] | 71 | int nrOfBins = plan.NrOfBins;
|
---|
[9348] | 72 | double result = 0;
|
---|
| 73 |
|
---|
[9563] | 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 |
|
---|
[9348] | 88 | for (int i = 0; i < nrOfBins; i++) {
|
---|
[13605] | 89 | double usableSpace = plan.BinPackings[i].BinMeasures.Volume;
|
---|
[9593] | 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();
|
---|
[9563] | 93 | //result += (usedSpaceInThisBin / usableSpace);
|
---|
| 94 | totalUsableSpace += usableSpace;
|
---|
[9593] | 95 | //totalUsedSpace += usedSpaceInThisBin;
|
---|
| 96 | totalUsedSpace += plan.BinPackings[i].PackingDensity * usableSpace;
|
---|
[9348] | 97 | }
|
---|
| 98 |
|
---|
[9563] | 99 | result = totalUsedSpace / totalUsableSpace;
|
---|
| 100 | return new DoubleValue(result);
|
---|
[9348] | 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|