[15731] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Threading.Tasks;
|
---|
| 6 | using HeuristicLab.Common;
|
---|
| 7 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
| 8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 9 | using HeuristicLab.Problems.BinPacking3D.ExtremePointCreation;
|
---|
| 10 |
|
---|
| 11 | namespace HeuristicLab.Problems.BinPacking3D.Packer {
|
---|
[15801] | 12 | internal class BinPackerFormClosure : BinPackerMinRSLeft {
|
---|
[15731] | 13 |
|
---|
| 14 | #region Constructors for HEAL
|
---|
| 15 | [StorableConstructor]
|
---|
| 16 | protected BinPackerFormClosure(bool deserializing) : base(deserializing) { }
|
---|
| 17 |
|
---|
| 18 | public BinPackerFormClosure(BinPackerMinRSLeft original, Cloner cloner) : base(original, cloner) {
|
---|
| 19 | }
|
---|
| 20 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 21 | throw new NotImplementedException();
|
---|
| 22 | }
|
---|
| 23 | #endregion
|
---|
| 24 |
|
---|
| 25 | public BinPackerFormClosure() : base() { }
|
---|
| 26 |
|
---|
[15801] | 27 |
|
---|
| 28 | protected override void PackRemainingItems(ref IList<int> remainingIds, ref BinPacking3D packingBin, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, bool useStackingConstraints) {
|
---|
[15731] | 29 | IExtremePointCreator extremePointCreator = ExtremePointCreatorFactory.CreateExtremePointCreator(epCreationMethod, useStackingConstraints);
|
---|
[15801] | 30 | // If there are any items which width equals to the bin shape width or the result of a modulo division of the width is zero, these items will be packed first
|
---|
| 31 | //schauen, ob es einen gegenstand gibt, der die ganze breite ausfuellt oder bei einer division mit der breite ein rest von 0 rauskommt.
|
---|
| 32 | var binShape = packingBin.BinShape;
|
---|
| 33 | var placeable = remainingIds.ToList().Where(x => ItemFitsBinShapeWidth(x, items[x], binShape))
|
---|
| 34 | .OrderByDescending(x => items[x].Width)
|
---|
| 35 | .ThenByDescending(x => items[x].Height);
|
---|
| 36 | foreach (var itemId in placeable) {
|
---|
| 37 | var item = items[itemId];
|
---|
| 38 | if (TryToPack(packingBin, item, itemId, extremePointCreator, useStackingConstraints)) {
|
---|
| 39 | remainingIds.Remove(itemId);
|
---|
[15731] | 40 | }
|
---|
| 41 | }
|
---|
[15801] | 42 | base.PackRemainingItems(ref remainingIds, ref packingBin, items, epCreationMethod, useStackingConstraints);
|
---|
[15731] | 43 | }
|
---|
| 44 |
|
---|
| 45 |
|
---|
[15820] | 46 | private bool ItemFitsBinShapeWidth(int itemId, PackingItem item, PackingShape binShape) {
|
---|
[15801] | 47 | item.Rotated = false;
|
---|
| 48 | item.Tilted = false;
|
---|
| 49 | if (binShape.Width % item.Width == 0) {
|
---|
[15731] | 50 | return true;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[15801] | 53 | if (item.RotateEnabled && !item.TiltEnabled) {
|
---|
[15731] | 54 | item.Rotated = true;
|
---|
[15801] | 55 | if (binShape.Width % item.Width == 0) {
|
---|
| 56 | return true;
|
---|
| 57 | }
|
---|
[15731] | 58 | }
|
---|
[15801] | 59 | if (!item.RotateEnabled && item.TiltEnabled) {
|
---|
| 60 | item.Rotated = false;
|
---|
[15731] | 61 | item.Tilted = true;
|
---|
[15801] | 62 | if (binShape.Width % item.Width == 0) {
|
---|
| 63 | return true;
|
---|
| 64 | }
|
---|
[15731] | 65 | }
|
---|
[15801] | 66 | if (item.RotateEnabled && item.TiltEnabled) {
|
---|
[15731] | 67 | item.Rotated = true;
|
---|
| 68 | item.Tilted = true;
|
---|
[15801] | 69 | if (binShape.Width % item.Width == 0) {
|
---|
| 70 | return true;
|
---|
| 71 | }
|
---|
[15731] | 72 | }
|
---|
[15801] | 73 | item.Rotated = false;
|
---|
| 74 | item.Tilted = false;
|
---|
[15731] | 75 | return false;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[15801] | 78 | private bool TryToPack(BinPacking3D packingBin, PackingItem item, int itemId, IExtremePointCreator extremePointCreator, bool useStackingConstraints) {
|
---|
| 79 | var position = FindPackingPositionForItem(packingBin, item, useStackingConstraints);
|
---|
| 80 | if (position != null) {
|
---|
| 81 | PackItem(packingBin, itemId, item, position, extremePointCreator, useStackingConstraints);
|
---|
| 82 | packingBin.PackItem(itemId, item, position);
|
---|
| 83 | return true;
|
---|
| 84 | }
|
---|
| 85 | return false;
|
---|
[15731] | 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|