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.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
26 | using HeuristicLab.Problems.BinPacking3D.ExtremePointCreation;
|
---|
27 | using HeuristicLab.Problems.BinPacking3D.ExtremePointPruning;
|
---|
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 {
|
---|
35 | internal class BinPackerFirstFit : BinPacker {
|
---|
36 | #region Constructors for HEAL
|
---|
37 | [StorableConstructor]
|
---|
38 | protected BinPackerFirstFit(bool deserializing) : base(deserializing) { }
|
---|
39 |
|
---|
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 |
|
---|
49 | public BinPackerFirstFit() : base() { }
|
---|
50 |
|
---|
51 | /// <summary>
|
---|
52 | /// Packs the items of the object by using a first fit algorithm into an amount of bins and returns them.
|
---|
53 | /// </summary>
|
---|
54 | /// <returns>Returns a collection of bin packing 3d objects. Each object represents a bin and the packed items</returns>
|
---|
55 | public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, ExtremePointPruningMethod epPruningMethod, bool useStackingConstraints) {
|
---|
56 | IList<BinPacking3D> packingList = new List<BinPacking3D>();
|
---|
57 | IList<int> remainingIds = new List<int>(sortedItems);
|
---|
58 |
|
---|
59 | while (remainingIds.Count > 0) {
|
---|
60 | BinPacking3D packingBin = new BinPacking3D(binShape);
|
---|
61 | PackRemainingItems(ref remainingIds, ref packingBin, items, epCreationMethod, useStackingConstraints);
|
---|
62 | packingList.Add(packingBin);
|
---|
63 | }
|
---|
64 |
|
---|
65 | ExtremePointPruningFactory.CreatePruning(epPruningMethod).PruneExtremePoints(packingList);
|
---|
66 | return packingList;
|
---|
67 | }
|
---|
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>
|
---|
73 | /// <param name="packingBin">This object will be filled with some of the given items</param>
|
---|
74 | /// <param name="items">List of packing items. Some of the items will be assigned to the BinPacking3D object</param>
|
---|
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) {
|
---|
78 | IExtremePointCreator extremePointCreator = ExtremePointCreatorFactory.CreateExtremePointCreator(epCreationMethod, useStackingConstraints);
|
---|
79 | foreach (var itemId in new List<int>(remainingIds)) {
|
---|
80 | PackingPosition position = FindPackingPositionForItem(packingBin, items[itemId], useStackingConstraints);
|
---|
81 | // if a valid packing position could be found, the current item can be added to the given bin
|
---|
82 | if (position != null) {
|
---|
83 | PackItem(packingBin, itemId, items[itemId], position, extremePointCreator, useStackingConstraints);
|
---|
84 | remainingIds.Remove(itemId);
|
---|
85 | }
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | public override void PackItemsToPackingList(IList<BinPacking3D> packingList, Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, ExtremePointPruningMethod epPruningMethod, bool useStackingConstraints) {
|
---|
90 | throw new NotImplementedException();
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|