Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2817:
-Added unit tests
-Refactoring of bp 3D

File size: 3.9 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 a collection of bin packing 3d objects. Each object represents a bin and the packed items</returns>
47    public abstract IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints);
48   
49    /// <summary>
50    /// Pack a given item into a given bin and updates the residual space and the extreme points
51    /// </summary>
52    /// <param name="packingBin"></param>
53    /// <param name="itemId"></param>
54    /// <param name="packingItem"></param>
55    /// <param name="position"></param>
56    protected virtual void PackItem(BinPacking3D packingBin, int itemId, PackingItem packingItem, PackingPosition position, bool useStackingConstraints) {
57
58      packingBin.PackItem(itemId, packingItem, position);
59      packingBin.UpdateResidualSpace(packingItem, position);
60      packingBin.UpdateExtremePoints(packingItem, position, useStackingConstraints);
61    }
62
63    /// <summary>
64    /// This method tries to find a valid packing position for an given item in a given packing bin
65    /// </summary>
66    /// <param name="packingBin"></param>
67    /// <param name="packingItem"></param>
68    /// <param name="useStackingConstraints"></param>
69    /// <param name="rotated"></param>
70    /// <returns>Returns the packing position for an given item. If there could not be found a valid position it returns null</returns>
71    protected PackingPosition FindPackingPositionForItem(BinPacking3D packingBin, PackingItem packingItem, bool useStackingConstraints, bool rotated) {
72      PackingItem newItem = new PackingItem(
73        rotated ? packingItem.Depth : packingItem.Width,
74        packingItem.Height,
75        rotated ? packingItem.Width : packingItem.Depth,
76        packingItem.TargetBin, packingItem.Weight, packingItem.Material);
77
78      // The extremepoints are sortet by Y / Z / X
79      return packingBin.ExtremePoints.Where(x => packingBin.IsPositionFeasible(newItem, x, useStackingConstraints)).FirstOrDefault();
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.