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 {
|
---|
12 | internal class BinPackerFormClosure : BinPackerMinRSLeft {
|
---|
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 |
|
---|
27 |
|
---|
28 | protected override void PackRemainingItems(ref IList<int> remainingIds, ref BinPacking3D packingBin, IList<PackingItem> items, ExtremePointCreationMethod epCreationMethod, bool useStackingConstraints) {
|
---|
29 | IExtremePointCreator extremePointCreator = ExtremePointCreatorFactory.CreateExtremePointCreator(epCreationMethod, useStackingConstraints);
|
---|
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);
|
---|
40 | }
|
---|
41 | }
|
---|
42 | base.PackRemainingItems(ref remainingIds, ref packingBin, items, epCreationMethod, useStackingConstraints);
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | private bool ItemFitsBinShapeWidth(int itemId, PackingItem item, PackingShape binShape) {
|
---|
47 | item.Rotated = false;
|
---|
48 | item.Tilted = false;
|
---|
49 | if (binShape.Width % item.Width == 0) {
|
---|
50 | return true;
|
---|
51 | }
|
---|
52 |
|
---|
53 | if (item.RotateEnabled && !item.TiltEnabled) {
|
---|
54 | item.Rotated = true;
|
---|
55 | if (binShape.Width % item.Width == 0) {
|
---|
56 | return true;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | if (!item.RotateEnabled && item.TiltEnabled) {
|
---|
60 | item.Rotated = false;
|
---|
61 | item.Tilted = true;
|
---|
62 | if (binShape.Width % item.Width == 0) {
|
---|
63 | return true;
|
---|
64 | }
|
---|
65 | }
|
---|
66 | if (item.RotateEnabled && item.TiltEnabled) {
|
---|
67 | item.Rotated = true;
|
---|
68 | item.Tilted = true;
|
---|
69 | if (binShape.Width % item.Width == 0) {
|
---|
70 | return true;
|
---|
71 | }
|
---|
72 | }
|
---|
73 | item.Rotated = false;
|
---|
74 | item.Tilted = false;
|
---|
75 | return false;
|
---|
76 | }
|
---|
77 |
|
---|
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;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|