[15462] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15617] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[15462] | 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 |
|
---|
[15488] | 22 | using HeuristicLab.Common;
|
---|
[15462] | 23 | using HeuristicLab.Core;
|
---|
[15454] | 24 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[15488] | 26 | using HeuristicLab.Problems.BinPacking3D.ExtremePointCreation;
|
---|
[15617] | 27 | using HeuristicLab.Problems.BinPacking3D.ExtremePointPruning;
|
---|
[15454] | 28 | using System;
|
---|
| 29 | using System.Collections.Generic;
|
---|
| 30 | using System.Linq;
|
---|
| 31 | using System.Text;
|
---|
| 32 | using System.Threading.Tasks;
|
---|
| 33 |
|
---|
| 34 | namespace HeuristicLab.Problems.BinPacking3D.Packer {
|
---|
[15554] | 35 | internal class BinPackerFirstFit : BinPacker {
|
---|
[15488] | 36 | #region Constructors for HEAL
|
---|
| 37 | [StorableConstructor]
|
---|
| 38 | protected BinPackerFirstFit(bool deserializing) : base(deserializing) { }
|
---|
[15454] | 39 |
|
---|
[15488] | 40 | protected BinPackerFirstFit(BinPackerFirstFit original, Cloner cloner)
|
---|
| 41 | : base(original, cloner) {
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 45 | return new BinPackerFirstFit(this, cloner);
|
---|
| 46 | }
|
---|
| 47 | #endregion
|
---|
| 48 |
|
---|
[15462] | 49 | public BinPackerFirstFit() : base() { }
|
---|
[15454] | 50 |
|
---|
| 51 | /// <summary>
|
---|
[15471] | 52 | /// Packs the items of the object by using a first fit algorithm into an amount of bins and returns them.
|
---|
[15454] | 53 | /// </summary>
|
---|
| 54 | /// <returns>Returns a collection of bin packing 3d objects. Each object represents a bin and the packed items</returns>
|
---|
[15617] | 55 | public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, ExtremePointPruningMethod epPruningMethod, bool useStackingConstraints) {
|
---|
[15454] | 56 | IList<BinPacking3D> packingList = new List<BinPacking3D>();
|
---|
[15462] | 57 | IList<int> remainingIds = new List<int>(sortedItems);
|
---|
[15454] | 58 |
|
---|
| 59 | while (remainingIds.Count > 0) {
|
---|
[15462] | 60 | BinPacking3D packingBin = new BinPacking3D(binShape);
|
---|
[15617] | 61 | PackRemainingItems(ref remainingIds, ref packingBin, items, epCreationMethod, useStackingConstraints);
|
---|
[15454] | 62 | packingList.Add(packingBin);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[15617] | 65 | ExtremePointPruningFactory.CreatePruning().PruneExtremePoints(epPruningMethod, packingList);
|
---|
[15454] | 66 | return packingList;
|
---|
| 67 | }
|
---|
[15462] | 68 |
|
---|
| 69 | /// <summary>
|
---|
| 70 | /// 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
|
---|
| 71 | /// </summary>
|
---|
| 72 | /// <param name="remainingIds">List of remaining ids. After the method has been executed the list has to have less items</param>
|
---|
[15617] | 73 | /// <param name="packingBin">This object will be filled with some of the given items</param>
|
---|
[15462] | 74 | /// <param name="items">List of packing items. Some of the items will be assigned to the BinPacking3D object</param>
|
---|
[15617] | 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) {
|
---|
[15488] | 78 | IExtremePointCreator extremePointCreator = ExtremePointCreatorFactory.CreateExtremePointCreator(epCreationMethod, useStackingConstraints);
|
---|
[15462] | 79 | foreach (var itemId in new List<int>(remainingIds)) {
|
---|
[15617] | 80 | PackingPosition position = FindPackingPositionForItem(packingBin, items[itemId], useStackingConstraints);
|
---|
[15462] | 81 | // if a valid packing position could be found, the current item can be added to the given bin
|
---|
| 82 | if (position != null) {
|
---|
[15488] | 83 | PackItem(packingBin, itemId, items[itemId], position, extremePointCreator, useStackingConstraints);
|
---|
[15462] | 84 | remainingIds.Remove(itemId);
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
[15454] | 88 | }
|
---|
| 89 | }
|
---|