Changeset 15462 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerResidualSpaceBestFit.cs
- Timestamp:
- 11/08/17 16:30:41 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerResidualSpaceBestFit.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; … … 12 33 [StorableClass] 13 34 public class BinPackerResidualSpaceBestFit : BinPacker { 14 public BinPackerResidualSpaceBestFit(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) {15 _permutation = permutation;16 _binShape = binShape;17 _items = items;18 _useStackingConstraints = useStackingConstraints;19 }20 35 36 public BinPackerResidualSpaceBestFit() : base() { }/* 37 public BinPackerResidualSpaceBestFit(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) 38 : base(permutation, binShape, items, useStackingConstraints) { } 39 */ 21 40 /// <summary> 22 41 /// Packs the items into the bins by using a best fit residual space algorithm. … … 25 44 /// </summary> 26 45 /// <returns></returns> 27 public override IList<BinPacking3D> PackItems( ) {46 public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) { 28 47 IList<BinPacking3D> packingList = new List<BinPacking3D>(); 29 IList<int> remainingIds = new List<int>( _permutation);48 IList<int> remainingIds = new List<int>(sortedItems); 30 49 bool rotated = false; 31 50 32 51 foreach (var remainingId in remainingIds) { 33 PackingItem item = _items[remainingId];52 PackingItem item = items[remainingId]; 34 53 var residualSpacePoints = GetResidualSpaceForAllPoints(packingList, item); 35 54 var sortedPoints = residualSpacePoints.OrderBy(x => x.Item3); … … 37 56 38 57 foreach (var point in sortedPoints) { 39 if (point.Item1.IsPositionFeasible(item, point.Item2, _useStackingConstraints)) {58 if (point.Item1.IsPositionFeasible(item, point.Item2, useStackingConstraints)) { 40 59 var binPacking = point.Item1; 41 PackItem(ref binPacking, remainingId, item, point.Item2, _useStackingConstraints);60 PackItem(ref binPacking, remainingId, item, point.Item2, useStackingConstraints); 42 61 packed = true; 43 62 break; … … 46 65 47 66 if (!packed) { 48 BinPacking3D binPacking = new BinPacking3D( _binShape);49 var position = FindPackingPositionForItem(binPacking, item, _useStackingConstraints, rotated);67 BinPacking3D binPacking = new BinPacking3D(binShape); 68 var position = FindPackingPositionForItem(binPacking, item, useStackingConstraints, rotated); 50 69 if (position != null) { 51 PackItem(ref binPacking, remainingId, item, position, _useStackingConstraints);70 PackItem(ref binPacking, remainingId, item, position, useStackingConstraints); 52 71 } else { 53 72 throw new InvalidOperationException("Item " + remainingId + " cannot be packed in an empty bin.");
Note: See TracChangeset
for help on using the changeset viewer.