Changeset 15462 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerFirstFit.cs
- Timestamp:
- 11/08/17 16:30:41 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerFirstFit.cs
r15454 r15462 1 using HeuristicLab.Core; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2016 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 using HeuristicLab.Core; 2 23 using HeuristicLab.Encodings.PermutationEncoding; 3 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 14 35 public class BinPackerFirstFit : BinPacker { 15 36 16 public BinPackerFirstFit(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) { 17 _permutation = permutation; 18 _binShape = binShape; 19 _items = items; 20 _useStackingConstraints = useStackingConstraints; 21 } 22 37 public BinPackerFirstFit() : base() { } 23 38 24 39 /// <summary> … … 26 41 /// </summary> 27 42 /// <returns>Returns a collection of bin packing 3d objects. Each object represents a bin and the packed items</returns> 28 public override IList<BinPacking3D> PackItems( ) {43 public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) { 29 44 IList<BinPacking3D> packingList = new List<BinPacking3D>(); 30 IList<int> remainingIds = new List<int>( _permutation);45 IList<int> remainingIds = new List<int>(sortedItems); 31 46 32 47 while (remainingIds.Count > 0) { 33 BinPacking3D packingBin = new BinPacking3D( _binShape);34 PackRemainingItems(ref remainingIds, ref packingBin, _items, _useStackingConstraints, null);48 BinPacking3D packingBin = new BinPacking3D(binShape); 49 PackRemainingItems(ref remainingIds, ref packingBin, items, useStackingConstraints, null); 35 50 packingList.Add(packingBin); 36 51 } … … 38 53 return packingList; 39 54 } 55 56 /// <summary> 57 /// Tries to pack the remainig items into a given BinPacking3D object. Each item could be packed into the BinPacking3D object will be removed from the list of remaining ids 58 /// </summary> 59 /// <param name="remainingIds">List of remaining ids. After the method has been executed the list has to have less items</param> 60 /// <param name="items">List of packing items. Some of the items will be assigned to the BinPacking3D object</param> 61 /// <param name="packingBin">This object will be filled with some of the given items</param> 62 protected void PackRemainingItems(ref IList<int> remainingIds, ref BinPacking3D packingBin, IList<PackingItem> items, bool useStackingConstraints, Dictionary<int, bool> rotationArray) { 63 64 foreach (var itemId in new List<int>(remainingIds)) { 65 bool rotated = rotationArray == null ? false : rotationArray[itemId]; 66 PackingPosition position = FindPackingPositionForItem(packingBin, items[itemId], useStackingConstraints, rotated); 67 // if a valid packing position could be found, the current item can be added to the given bin 68 if (position != null) { 69 PackItem(ref packingBin, itemId, items[itemId], position, useStackingConstraints); 70 remainingIds.Remove(itemId); 71 } 72 } 73 } 40 74 } 41 75 }
Note: See TracChangeset
for help on using the changeset viewer.