Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2817
-Added unit tests for bin packing 3d.
-The items can now be sorted by the material.

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Joseph Helm and 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
22using HeuristicLab.Core;
23using HeuristicLab.Encodings.PermutationEncoding;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25using HeuristicLab.Problems.BinPacking3D;
26using System;
27using System.Collections.Generic;
28using System.Linq;
29using System.Text;
30using System.Threading.Tasks;
31
32namespace HeuristicLab.Problems.BinPacking3D.Packer {
33  [Item("BinPacker", "A class for packing bins for the 3D bin-packer problem.")]
34  [StorableClass]
35  public abstract class BinPacker {
36   
37    public BinPacker() { }
38
39    /// <summary>
40    /// Packs all items of the bin packer and returns a collection of BinPacking3D objects
41    /// </summary>
42    /// <param name="sortedItems">Permutation of items sorted by a sorting method. The value of each permutation index references to the index of the items list</param>
43    /// <param name="binShape">Bin for storing the items</param>
44    /// <param name="items">A list of packing items which should be assigned to a bin</param>
45    /// <param name="useStackingConstraints">Flag for using stacking constraints</param>
46    /// <returns></returns>
47    public abstract IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints);
48
49   
50
51    /// <summary>
52    /// Pack a given item into a given bin and updates the residual space and the extreme points
53    /// </summary>
54    /// <param name="packingBin"></param>
55    /// <param name="itemId"></param>
56    /// <param name="packingItem"></param>
57    /// <param name="position"></param>
58    protected void PackItem(ref BinPacking3D packingBin, int itemId, PackingItem packingItem, PackingPosition position, bool useStackingConstraints) {
59
60      packingBin.PackItem(itemId, packingItem, position);
61      packingBin.UpdateResidualSpace(packingItem, position);
62      packingBin.UpdateExtremePoints(packingItem, position, useStackingConstraints);
63    }
64
65    /// <summary>
66    /// This method tries to find a valid packing position for an given item in a given packing bin
67    /// </summary>
68    /// <param name="packingBin"></param>
69    /// <param name="packingItem"></param>
70    /// <param name="useStackingConstraints"></param>
71    /// <param name="rotated"></param>
72    /// <returns>Returns the packing position for an given item. If there could not be found a valid position it returns null</returns>
73    protected PackingPosition FindPackingPositionForItem(BinPacking3D packingBin, PackingItem packingItem, bool useStackingConstraints, bool rotated) {
74      PackingItem newItem = new PackingItem(
75        rotated ? packingItem.Depth : packingItem.Width,
76        packingItem.Height,
77        rotated ? packingItem.Width : packingItem.Depth,
78        packingItem.TargetBin, packingItem.Weight, packingItem.Material);
79
80      // The extremepoints are sortet by Z, X, Y
81
82      return packingBin.ExtremePoints.Where(x => packingBin.IsPositionFeasible(newItem, x, useStackingConstraints)).FirstOrDefault();
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.