Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/08/17 16:30:41 (6 years ago)
Author:
rhanghof
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPacker.cs

    r15454 r15462  
    1 using HeuristicLab.Core;
     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;
    223using HeuristicLab.Encodings.PermutationEncoding;
    324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    1334  [StorableClass]
    1435  public abstract class BinPacker {
    15     protected Permutation _permutation;
    16     protected PackingShape _binShape;
    17     protected IList<PackingItem> _items;
    18     protected bool _useStackingConstraints;
     36   
     37    public BinPacker() { }
    1938
    2039    /// <summary>
    2140    /// Packs all items of the bin packer and returns a collection of BinPacking3D objects
    2241    /// </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>
    2346    /// <returns></returns>
    24     public abstract IList<BinPacking3D> PackItems();
     47    public abstract IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints);
    2548
    26     /// <summary>
    27     /// Tries to pack the remainig items into a given BinPacking3D object. Each item could be packed into the BinPacking3D object will be removed from the list of remaining ids
    28     /// </summary>
    29     /// <param name="remainingIds">List of remaining ids. After the method has been executed the list has to have less items</param>
    30     /// <param name="items">List of packing items. Some of the items will be assigned to the BinPacking3D object</param>
    31     /// <param name="packingBin">This object will be filled with some of the given items</param>
    32     protected void PackRemainingItems(ref IList<int> remainingIds, ref BinPacking3D packingBin, IList<PackingItem> items, bool useStackingConstraints, Dictionary<int, bool> rotationArray) {
    33 
    34       foreach (var itemId in new List<int>(remainingIds)) {
    35         bool rotated = rotationArray == null ? false : rotationArray[itemId];
    36         PackingPosition position = FindPackingPositionForItem(packingBin, items[itemId], useStackingConstraints, rotated);
    37         // if a valid packing position could be found, the current item can be added to the given bin
    38         if (position != null) {
    39           PackItem(ref packingBin, itemId, items[itemId], position, useStackingConstraints);
    40           remainingIds.Remove(itemId);
    41         }
    42       }
    43     }
     49   
    4450
    4551    /// <summary>
     
    5258    protected void PackItem(ref BinPacking3D packingBin, int itemId, PackingItem packingItem, PackingPosition position, bool useStackingConstraints) {
    5359
    54       packingBin.AddItem(itemId, packingItem, position);
     60      packingBin.PackItem(itemId, packingItem, position);
    5561      packingBin.UpdateResidualSpace(packingItem, position);
    5662      packingBin.UpdateExtremePoints(packingItem, position, useStackingConstraints);
Note: See TracChangeset for help on using the changeset viewer.