- Timestamp:
- 01/16/18 15:40:43 (7 years ago)
- Location:
- branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPacker.cs
r15554 r15617 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6 Joseph Helm andHeuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 49 49 public BinPacker() { } 50 50 51 51 52 /// <summary> 52 53 /// Packs all items of the bin packer and returns a collection of BinPacking3D objects … … 57 58 /// <param name="useStackingConstraints">Flag for using stacking constraints</param> 58 59 /// <returns>Returns a collection of bin packing 3d objects. Each object represents a bin and the packed items</returns> 59 public abstract IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, bool useStackingConstraints);60 public abstract IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, ExtremePointPruningMethod epPruningMethod, bool useStackingConstraints); 60 61 61 62 /// <summary> … … 66 67 /// <param name="packingItem"></param> 67 68 /// <param name="position"></param> 68 protected virtual void PackItem(BinPacking3D packingBin, int itemId, PackingItem packingItem, PackingPosition position, IExtremePointCreator extremePointCreator, bool useStackingConstraints) { 69 if (!CheckItemDimensions(packingBin, packingItem, position)) { 70 throw new BinPacking3DException($"The dimensions of the given item exceeds the bin dimensions. " + 71 $"Bin: ({packingBin.BinShape.Width} {packingBin.BinShape.Depth} {packingBin.BinShape.Height})" + 72 $"Item: ({packingItem.Width} {packingItem.Depth} {packingItem.Height})"); 73 } 69 protected virtual void PackItem(BinPacking3D packingBin, int itemId, PackingItem packingItem, PackingPosition position, IExtremePointCreator extremePointCreator, bool useStackingConstraints) { 74 70 packingBin.PackItem(itemId, packingItem, position); 75 71 extremePointCreator.UpdateBinPacking(packingBin, packingItem, position); … … 82 78 /// <param name="packingItem"></param> 83 79 /// <param name="useStackingConstraints"></param> 84 /// <param name="rotated"></param>85 80 /// <returns>Returns the packing position for an given item. If there could not be found a valid position it returns null</returns> 86 protected PackingPosition FindPackingPositionForItem(BinPacking3D packingBin, PackingItem packingItem, bool useStackingConstraints, bool rotated) { 81 protected virtual PackingPosition FindPackingPositionForItem(BinPacking3D packingBin, PackingItem packingItem, bool useStackingConstraints) { 82 if (!CheckItemDimensions(packingBin, packingItem)) { 83 throw new BinPacking3DException($"The dimensions of the given item exceeds the bin dimensions. " + 84 $"Bin: ({packingBin.BinShape.Width} {packingBin.BinShape.Depth} {packingBin.BinShape.Height})" + 85 $"Item: ({packingItem.Width} {packingItem.Depth} {packingItem.Height})"); 86 } 87 87 88 PackingItem newItem = new PackingItem( 88 rotated ? packingItem.Depth :packingItem.Width,89 packingItem.Width, 89 90 packingItem.Height, 90 rotated ? packingItem.Width :packingItem.Depth,91 packingItem.Depth, 91 92 packingItem.TargetBin, packingItem.Weight, packingItem.Material); 92 93 … … 102 103 /// <param name="item"></param> 103 104 /// <returns>Returns true if the dimensions of an given item are less or equal to the bin.</returns> 104 pr ivate bool CheckItemDimensions(BinPacking3D packingBin, PackingItem item, PackingPosition itemPosition) {105 var width = item Position.Rotated ? item.Depth : item.Width;106 var depth = item Position.Rotated ? item.Width : item.Depth;105 protected virtual bool CheckItemDimensions(BinPacking3D packingBin, PackingItem item) { 106 var width = item.Width; 107 var depth = item.Depth; 107 108 return packingBin.BinShape.Width >= width && packingBin.BinShape.Height >= item.Height && packingBin.BinShape.Depth >= depth; 108 109 } 110 111 /// <summary> 112 /// Clones a given list of packing items. 113 /// </summary> 114 /// <param name="items"></param> 115 /// <returns></returns> 116 protected static IList<PackingItem> CloneItems(IList<PackingItem> items) { 117 var clonedItems = new List<PackingItem>(); 118 foreach (var item in items) { 119 clonedItems.Add(item.Clone() as PackingItem); 120 } 121 return clonedItems; 122 } 123 109 124 } 110 125 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerFactory.cs
r15554 r15617 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 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 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; … … 29 50 binPacker = new BinPackerResidualSpaceBestFit(); 30 51 break; 52 case FittingMethod.MinimumResidualSpaceLeft: 53 binPacker = new BinPackerMinRSLeft(); 54 break; 31 55 default: 32 56 throw new ArgumentException("Unknown fitting method: " + fittingMethod); -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerFirstFit.cs
r15554 r15617 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6 Joseph Helm andHeuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 using HeuristicLab.Problems.BinPacking3D.ExtremePointCreation; 27 using HeuristicLab.Problems.BinPacking3D.ExtremePointPruning; 27 28 using System; 28 29 using System.Collections.Generic; … … 52 53 /// </summary> 53 54 /// <returns>Returns a collection of bin packing 3d objects. Each object represents a bin and the packed items</returns> 54 public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod ep GenerationMethod, bool useStackingConstraints) {55 public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, ExtremePointPruningMethod epPruningMethod, bool useStackingConstraints) { 55 56 IList<BinPacking3D> packingList = new List<BinPacking3D>(); 56 57 IList<int> remainingIds = new List<int>(sortedItems); … … 58 59 while (remainingIds.Count > 0) { 59 60 BinPacking3D packingBin = new BinPacking3D(binShape); 60 PackRemainingItems(ref remainingIds, ref packingBin, items, ep GenerationMethod, useStackingConstraints, null);61 PackRemainingItems(ref remainingIds, ref packingBin, items, epCreationMethod, useStackingConstraints); 61 62 packingList.Add(packingBin); 62 63 } 63 64 65 ExtremePointPruningFactory.CreatePruning().PruneExtremePoints(epPruningMethod, packingList); 64 66 return packingList; 65 67 } … … 69 71 /// </summary> 70 72 /// <param name="remainingIds">List of remaining ids. After the method has been executed the list has to have less items</param> 73 /// <param name="packingBin">This object will be filled with some of the given items</param> 71 74 /// <param name="items">List of packing items. Some of the items will be assigned to the BinPacking3D object</param> 72 /// <param name="packingBin">This object will be filled with some of the given items</param> 73 protected void PackRemainingItems(ref IList<int> remainingIds, ref BinPacking3D packingBin, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, bool useStackingConstraints, Dictionary<int, bool> rotationArray) { 75 /// <param name="epCreationMethod"></param> 76 /// <param name="useStackingConstraints"></param> 77 protected void PackRemainingItems(ref IList<int> remainingIds, ref BinPacking3D packingBin, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, bool useStackingConstraints) { 74 78 IExtremePointCreator extremePointCreator = ExtremePointCreatorFactory.CreateExtremePointCreator(epCreationMethod, useStackingConstraints); 75 79 foreach (var itemId in new List<int>(remainingIds)) { 76 bool rotated = rotationArray == null ? false : rotationArray[itemId]; 77 PackingPosition position = FindPackingPositionForItem(packingBin, items[itemId], useStackingConstraints, rotated); 80 PackingPosition position = FindPackingPositionForItem(packingBin, items[itemId], useStackingConstraints); 78 81 // if a valid packing position could be found, the current item can be added to the given bin 79 82 if (position != null) { -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerFreeVolumeBestFit.cs
r15554 r15617 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6 Joseph Helm andHeuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 using HeuristicLab.Problems.BinPacking3D.ExtremePointCreation; 27 using HeuristicLab.Problems.BinPacking3D.ExtremePointPruning; 27 28 using System; 28 29 using System.Collections.Generic; … … 61 62 /// <param name="useStackingConstraints"></param> 62 63 /// <returns>Returns a collection of bin packing 3d objects. Each object represents a bin and the packed items</returns> 63 public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epGenerationMethod, bool useStackingConstraints) {64 public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epGenerationMethod, ExtremePointPruningMethod epPruningMethod, bool useStackingConstraints) { 64 65 IList<BinPacking3D> packingList = new List<BinPacking3D>(); 65 66 IList<int> remainingIds = new List<int>(sortedItems); … … 73 74 74 75 foreach (var packingBin in sortedBins) { 75 PackingPosition position = FindPackingPositionForItem(packingBin, item, useStackingConstraints , false);76 PackingPosition position = FindPackingPositionForItem(packingBin, item, useStackingConstraints); 76 77 positionFound = position != null; 77 78 var bin = packingBin; … … 84 85 if (!positionFound) { 85 86 BinPacking3D packingBin = new BinPacking3D(binShape); 86 PackingPosition position = FindPackingPositionForItem(packingBin, item, useStackingConstraints , false);87 PackingPosition position = FindPackingPositionForItem(packingBin, item, useStackingConstraints); 87 88 88 89 if (position == null) { … … 94 95 } 95 96 } 97 ExtremePointPruningFactory.CreatePruning().PruneExtremePoints(epPruningMethod, packingList); 96 98 return packingList.ToList(); 97 99 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerResidualSpaceBestFit.cs
r15554 r15617 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6 Joseph Helm andHeuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 using HeuristicLab.Problems.BinPacking3D.ExtremePointCreation; 27 using HeuristicLab.Problems.BinPacking3D.ExtremePointPruning; 27 28 using System; 28 29 using System.Collections.Generic; … … 55 56 /// </summary> 56 57 /// <returns>Returns a collection of bin packing 3d objects. Each object represents a bin and the packed items</returns> 57 public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, bool useStackingConstraints) {58 public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, ExtremePointPruningMethod epPruningMethod, bool useStackingConstraints) { 58 59 IList<BinPacking3D> packingList = new List<BinPacking3D>(); 59 60 IList<int> remainingIds = new List<int>(sortedItems); 60 61 IExtremePointCreator extremePointCreator = ExtremePointCreatorFactory.CreateExtremePointCreator(epCreationMethod, useStackingConstraints); 61 bool rotated = false;62 62 63 63 foreach (var remainingId in remainingIds) { … … 78 78 if (!packed) { 79 79 BinPacking3D binPacking = new BinPacking3D(binShape); 80 var position = FindPackingPositionForItem(binPacking, item, useStackingConstraints , rotated);80 var position = FindPackingPositionForItem(binPacking, item, useStackingConstraints); 81 81 if (position != null) { 82 82 PackItem(binPacking, remainingId, item, position, extremePointCreator, useStackingConstraints); … … 87 87 } 88 88 } 89 90 ExtremePointPruningFactory.CreatePruning().PruneExtremePoints(epPruningMethod, packingList); 89 91 return packingList; 90 92 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/IBinPacker.cs
r15554 r15617 1 using HeuristicLab.Encodings.PermutationEncoding; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 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 using HeuristicLab.Encodings.PermutationEncoding; 2 23 using System; 3 24 using System.Collections.Generic; … … 16 37 /// <param name="useStackingConstraints">Flag for using stacking constraints</param> 17 38 /// <returns>Returns a collection of bin packing 3d objects. Each object represents a bin and the packed items</returns> 18 IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, bool useStackingConstraints);39 IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, ExtremePointPruningMethod epPruningMethod, bool useStackingConstraints); 19 40 20 41 }
Note: See TracChangeset
for help on using the changeset viewer.