Free cookie consent management tool by TermsFeed Policy Generator

source: branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/FreeVolumeBestFitExtremePointPermutationDecoder.cs @ 14976

Last change on this file since 14976 was 14976, checked in by dsouravl, 7 years ago

#2762: worked on best fit heuristics

File size: 3.0 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 System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Encodings.PermutationEncoding;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.BinPacking3D {
31  [Item("Free Volume Best Fit Extreme-point Permutation Decoder (3d)", "Decodes the permutation and creates a packing solution candidate")]
32  [StorableClass]
33  public class FreeVolumeBestFitExtremePointPermutationDecoder : ExtremePointPermutationDecoderBase {
34
35    [StorableConstructor]
36    protected FreeVolumeBestFitExtremePointPermutationDecoder(bool deserializing) : base(deserializing) { }
37    protected FreeVolumeBestFitExtremePointPermutationDecoder(FreeVolumeBestFitExtremePointPermutationDecoder original, Cloner cloner)
38      : base(original, cloner) {
39    }
40    public FreeVolumeBestFitExtremePointPermutationDecoder() : base() { }
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new FreeVolumeBestFitExtremePointPermutationDecoder(this, cloner);
43    }
44
45    public override Solution Decode(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) {
46      Solution result = new Solution(binShape, useExtremePoints: true, stackingConstraints: useStackingConstraints);
47      IList<int> remainingIDs = new List<int>(permutation);
48      var bpg = new BinPacking3D(binShape);
49      bpg.ExtremePointBasedPacking(ref remainingIDs, items, stackingConstraints: useStackingConstraints);
50      result.Bins.Add(bpg);
51      foreach (int ID in remainingIDs) {
52        var sortedBins = result.Bins.OrderBy(x => x.FreeVolume);
53        var notPacked = 0;
54        foreach (BinPacking3D bp in sortedBins) {
55          if (!bp.ExtremePointBasedPacking(ID, items, stackingConstraints: useStackingConstraints)) { notPacked++; } else break;
56        }
57        if (notPacked == result.NrOfBins) {
58          var bp = new BinPacking3D(binShape);
59          bp.ExtremePointBasedPacking(ID, items, stackingConstraints: useStackingConstraints);
60          result.Bins.Add(bp);
61        }
62      }
63      result.UpdateBinPackings();
64      return result;
65    }
66  }
67}
Note: See TracBrowser for help on using the repository browser.