Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerFreeVolumeBestFit.cs @ 15454

Last change on this file since 15454 was 15454, checked in by rhanghof, 6 years ago

#2817

  • Extreme point bin packing does not need the occupation layer anymore
  • Changes at the fitting algorithm. Now they are packing the items as in the paper of S. Martello, D. Pisinger, D. Vigo described
File size: 2.2 KB
Line 
1using HeuristicLab.Core;
2using HeuristicLab.Encodings.PermutationEncoding;
3using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
4using System;
5using System.Collections.Generic;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9
10namespace HeuristicLab.Problems.BinPacking3D.Packer {
11  [Item("BinPackerFreeVolumeBestFit", "A class for packing bins for the 3D bin-packer problem. It uses a best fit algortihm depending on the free volume.")]
12  [StorableClass]
13  public class BinPackerFreeVolumeBestFit : BinPacker {
14    public BinPackerFreeVolumeBestFit(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) {
15      _permutation = permutation;
16      _binShape = binShape;
17      _items = items;
18      _useStackingConstraints = useStackingConstraints;
19    }
20
21    public override IList<BinPacking3D> PackItems() {
22      IList<BinPacking3D> packingList = new List<BinPacking3D>();
23      IList<int> remainingIds = new List<int>(_permutation);
24     
25
26      foreach (int remainingId in remainingIds) {
27        var sortedBins = packingList.OrderBy(x => x.FreeVolume);
28        PackingItem item = _items[remainingId];
29        bool positionFound = false;
30
31        foreach (var packingBin in sortedBins) {
32          PackingPosition position = FindPackingPositionForItem(packingBin, item, _useStackingConstraints, false);
33          positionFound = position != null;
34          var bin = packingBin;
35          if (positionFound) {
36            PackItem(ref bin, remainingId, item, position, _useStackingConstraints);
37            break;
38          }           
39        }
40
41        if (!positionFound) {
42          BinPacking3D packingBin = new BinPacking3D(_binShape);
43          PackingPosition position = FindPackingPositionForItem(packingBin, item, _useStackingConstraints, false);
44
45          if (position == null) {
46            throw new InvalidOperationException("Item " + remainingId + " cannot be packed in empty bin.");
47          }
48
49          PackItem(ref packingBin, remainingId, item, position, _useStackingConstraints);
50          packingList.Add(packingBin);
51        }
52      }
53      return packingList.ToList();
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.