[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 |
|
---|
[14045] | 22 |
|
---|
[9348] | 23 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 27 | using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
|
---|
| 28 | using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
|
---|
| 29 | using HeuristicLab.Problems.Instances;
|
---|
[9440] | 30 | using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
|
---|
[9563] | 31 | using HeuristicLab.PluginInfrastructure;
|
---|
[14039] | 32 | using HeuristicLab.Data;
|
---|
[14046] | 33 | using HeuristicLab.Problems.BinPacking;
|
---|
[9348] | 34 |
|
---|
[14046] | 35 | namespace HeuristicLab.Problems.BinPacking3D {
|
---|
[13460] | 36 | [Item("Bin Packing Problem (3D, identical cuboids) (BPP)", "Represents a three-dimensional bin-packing problem using only bins with identical measures and bins/items with cuboidic shapes.")]
|
---|
[9348] | 37 | [StorableClass]
|
---|
[13460] | 38 | [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 310)]
|
---|
[14040] | 39 | // TODO don't support generic BPPData but only 3d BPPData
|
---|
[14048] | 40 | public class CuboidIdenticalBinPackingProblem : BinPackingProblem<PackingPosition, CuboidPackingShape, CuboidPackingItem>, IProblemInstanceConsumer<BPPData>, IProblemInstanceExporter<BPPData> {
|
---|
[9348] | 41 |
|
---|
[14040] | 42 |
|
---|
[9348] | 43 | #region Default Instance
|
---|
[14039] | 44 | private static readonly BPPData DefaultInstance = new BPPData() {
|
---|
| 45 | Name = "3D BPP Default Instance",
|
---|
[9348] | 46 | Description = "The default instance for 3D Bin Packing.",
|
---|
[14039] | 47 | BinMeasures = new int[] { 25, 25, 35 },
|
---|
[9348] | 48 | ItemMeasures = new int[][] {
|
---|
| 49 | new int[] {12,5,10},
|
---|
| 50 | new int[] {10,18,20},
|
---|
| 51 | new int[] {9,7,7},
|
---|
| 52 | new int[] {21,12,4},
|
---|
| 53 | new int[] {8,8,12},
|
---|
| 54 | new int[] {3,6,14},
|
---|
| 55 | new int[] {20,4,9},
|
---|
| 56 | new int[] {5,9,8},
|
---|
| 57 | new int[] {7,17,3},
|
---|
| 58 | new int[] {13,20,15},
|
---|
| 59 | new int[] {9,11,9},
|
---|
| 60 | new int[] {10,18,20},
|
---|
| 61 | new int[] {9,7,7},
|
---|
| 62 | new int[] {21,12,4},
|
---|
| 63 | new int[] {8,8,12},
|
---|
| 64 | new int[] {3,6,14},
|
---|
| 65 | new int[] {20,4,9},
|
---|
| 66 | new int[] {5,9,8},
|
---|
| 67 | new int[] {7,17,3},
|
---|
| 68 | new int[] {13,20,15},
|
---|
| 69 | new int[] {9,11,9},
|
---|
| 70 | new int[] {10,18,20},
|
---|
| 71 | new int[] {9,7,7},
|
---|
| 72 | new int[] {21,12,4},
|
---|
| 73 | new int[] {8,8,12},
|
---|
| 74 | new int[] {3,6,14},
|
---|
| 75 | new int[] {20,4,9},
|
---|
| 76 | new int[] {5,9,8},
|
---|
| 77 | new int[] {7,17,3},
|
---|
| 78 | new int[] {13,20,15},
|
---|
| 79 | new int[] {9,11,9},
|
---|
| 80 | new int[] {10,18,20},
|
---|
| 81 | new int[] {9,7,7},
|
---|
| 82 | new int[] {21,12,4},
|
---|
| 83 | new int[] {8,8,12},
|
---|
| 84 | new int[] {3,6,14},
|
---|
| 85 | new int[] {20,4,9},
|
---|
| 86 | new int[] {5,9,8},
|
---|
| 87 | new int[] {7,17,3},
|
---|
| 88 | new int[] {13,20,15},
|
---|
| 89 | new int[] {9,11,9}
|
---|
| 90 | },
|
---|
| 91 | Items = 30
|
---|
| 92 | };
|
---|
| 93 | #endregion
|
---|
[14039] | 94 |
|
---|
[9348] | 95 | [StorableConstructor]
|
---|
| 96 | protected CuboidIdenticalBinPackingProblem(bool deserializing) : base(deserializing) { }
|
---|
| 97 | protected CuboidIdenticalBinPackingProblem(CuboidIdenticalBinPackingProblem original, Cloner cloner)
|
---|
| 98 | : base(original, cloner) {
|
---|
| 99 | }
|
---|
| 100 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 101 | return new CuboidIdenticalBinPackingProblem(this, cloner);
|
---|
| 102 | }
|
---|
| 103 | public CuboidIdenticalBinPackingProblem() : base(
|
---|
[14048] | 104 | new PackingPlanEvaluationAlgorithm<Permutation, PackingPosition, CuboidPackingShape, CuboidPackingItem>()) {
|
---|
[9348] | 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 |
|
---|
[14040] | 109 | public void Load(BPPData data) {
|
---|
[14039] | 110 | var realData = data as RealBPPData;
|
---|
[14045] | 111 | var binData = new CuboidPackingShape(data.BinMeasures[0], data.BinMeasures[1], data.BinMeasures[2]);
|
---|
[14039] | 112 |
|
---|
| 113 | var itemData = new ItemList<CuboidPackingItem>(data.Items);
|
---|
| 114 | for (int j = 0; j < data.Items; j++) {
|
---|
[14045] | 115 | var bin = new CuboidPackingShape(data.BinMeasures[0], data.BinMeasures[1], data.BinMeasures[2]);
|
---|
[14039] | 116 | var item = new CuboidPackingItem(data.ItemMeasures[j][0], data.ItemMeasures[j][1], data.ItemMeasures[j][2], bin);
|
---|
| 117 | if (realData != null) {
|
---|
| 118 | item.Weight = realData.ItemWeights[j];
|
---|
| 119 | item.Material = realData.ItemMaterials[j];
|
---|
| 120 | }
|
---|
| 121 | itemData.Add(item);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null;
|
---|
| 125 |
|
---|
| 126 | PackingBinMeasures = binData;
|
---|
| 127 | PackingItemMeasures = itemData;
|
---|
| 128 |
|
---|
| 129 | ApplyHorizontalOrientation();
|
---|
| 130 | SortItems();
|
---|
| 131 | PackingItemsParameter.Value.Value = PackingItemMeasures.Count;
|
---|
| 132 | LowerBoundParameter.Value.Value = CalculateLowerBound();
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[14040] | 135 | public BPPData Export() {
|
---|
[14039] | 136 | var result = new BPPData {
|
---|
| 137 | Name = Name,
|
---|
| 138 | Description = Description,
|
---|
| 139 | Items = PackingItemsParameter.Value.Value,
|
---|
| 140 | BinMeasures = new int[] { PackingBinMeasures.Width, PackingBinMeasures.Height, PackingBinMeasures.Depth }
|
---|
| 141 | };
|
---|
| 142 |
|
---|
| 143 | var itemMeasures = new int[result.Items][];
|
---|
| 144 | int i = 0;
|
---|
| 145 | foreach (var item in PackingItemMeasures) {
|
---|
| 146 | itemMeasures[i] = new int[] { item.Width, item.Height, item.Depth };
|
---|
| 147 | i++;
|
---|
| 148 | }
|
---|
| 149 | result.ItemMeasures = itemMeasures;
|
---|
| 150 | return result;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[9348] | 153 | #region Helpers
|
---|
| 154 | protected override void InitializeDecoder() {
|
---|
[13607] | 155 | // Operators.RemoveAll(op => op is I2DOperator); TODO
|
---|
[9495] | 156 |
|
---|
[9563] | 157 | PackingSolutionDecoderParameter.ValidValues.Clear();
|
---|
[14039] | 158 | if (SolutionCreator is PackingSequenceRandomCreator) {
|
---|
[9563] | 159 | PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DPSDecoder>());
|
---|
[14039] | 160 | } else if (SolutionCreator is GroupingVectorRandomCreator) {
|
---|
[9563] | 161 | PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DGVDecoder>());
|
---|
[14039] | 162 | } else if (SolutionCreator is MultiComponentVectorRandomCreator) {
|
---|
[9563] | 163 | PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DMCVDecoder>());
|
---|
[9348] | 164 | } else {
|
---|
| 165 | string error = "The given problem does not support the selected solution-creator.";
|
---|
[13460] | 166 | ErrorHandling.ShowErrorDialog(error, null);
|
---|
[9348] | 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | protected override IPackingPlanEvaluator CreateDefaultEvaluator() {
|
---|
| 171 | return new PackingRatioCuboidIdenticalBinEvaluator();
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | protected override void InitializeProblemData() {
|
---|
| 175 | Load(DefaultInstance);
|
---|
| 176 | }
|
---|
[9598] | 177 |
|
---|
| 178 | protected override void RemoveTooBigItems() {
|
---|
[14039] | 179 | PackingItemMeasures.RemoveAll(pi =>
|
---|
[14048] | 180 | !PackingBinMeasures.Encloses(new PackingPosition(0, 0, 0, 0, false), pi) &&
|
---|
| 181 | !PackingBinMeasures.Encloses(new PackingPosition(0, 0, 0, 0, true), pi));
|
---|
[9598] | 182 | }
|
---|
[9348] | 183 | #endregion
|
---|
| 184 | }
|
---|
| 185 | }
|
---|