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/BinPackerResidualSpaceBestFit.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;
     
    1233  [StorableClass]
    1334  public class BinPackerResidualSpaceBestFit : BinPacker {
    14     public BinPackerResidualSpaceBestFit(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) {
    15       _permutation = permutation;
    16       _binShape = binShape;
    17       _items = items;
    18       _useStackingConstraints = useStackingConstraints;
    19     }
    2035
     36    public BinPackerResidualSpaceBestFit() : base() { }/*
     37    public BinPackerResidualSpaceBestFit(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints)
     38      : base(permutation, binShape, items, useStackingConstraints) { }
     39      */
    2140    /// <summary>
    2241    /// Packs the items into the bins by using a best fit residual space algorithm.
     
    2544    /// </summary>
    2645    /// <returns></returns>
    27     public override IList<BinPacking3D> PackItems() {
     46    public override IList<BinPacking3D> PackItems(Permutation sortedItems, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) {
    2847      IList<BinPacking3D> packingList = new List<BinPacking3D>();
    29       IList<int> remainingIds = new List<int>(_permutation);
     48      IList<int> remainingIds = new List<int>(sortedItems);
    3049      bool rotated = false;
    3150
    3251      foreach (var remainingId in remainingIds) {
    33         PackingItem item = _items[remainingId];
     52        PackingItem item = items[remainingId];
    3453        var residualSpacePoints = GetResidualSpaceForAllPoints(packingList, item);
    3554        var sortedPoints = residualSpacePoints.OrderBy(x => x.Item3);
     
    3756
    3857        foreach (var point in sortedPoints) {
    39           if (point.Item1.IsPositionFeasible(item, point.Item2, _useStackingConstraints)) {
     58          if (point.Item1.IsPositionFeasible(item, point.Item2, useStackingConstraints)) {
    4059            var binPacking = point.Item1;
    41             PackItem(ref binPacking, remainingId, item, point.Item2, _useStackingConstraints);
     60            PackItem(ref binPacking, remainingId, item, point.Item2, useStackingConstraints);
    4261            packed = true;
    4362            break;
     
    4665
    4766        if (!packed) {
    48           BinPacking3D binPacking = new BinPacking3D(_binShape);
    49           var position = FindPackingPositionForItem(binPacking, item, _useStackingConstraints, rotated);
     67          BinPacking3D binPacking = new BinPacking3D(binShape);
     68          var position = FindPackingPositionForItem(binPacking, item, useStackingConstraints, rotated);
    5069          if (position != null) {
    51             PackItem(ref binPacking, remainingId, item, position, _useStackingConstraints);
     70            PackItem(ref binPacking, remainingId, item, position, useStackingConstraints);
    5271          } else {
    5372            throw new InvalidOperationException("Item " + remainingId + " cannot be packed in an empty bin.");
Note: See TracChangeset for help on using the changeset viewer.