Free cookie consent management tool by TermsFeed Policy Generator

source: branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/3D/PermutationEncoding/ResidualSpaceBestFitExtremePointPermutationDecoder.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.1 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("Residual Space Best Fit Extreme-point Permutation Decoder (3d)", "Decodes the permutation and creates a packing solution candidate")]
32  [StorableClass]
33  public class ResidualSpaceBestFitExtremePointPermutationDecoder : ExtremePointPermutationDecoderBase {
34
35    [StorableConstructor]
36    protected ResidualSpaceBestFitExtremePointPermutationDecoder(bool deserializing) : base(deserializing) { }
37    protected ResidualSpaceBestFitExtremePointPermutationDecoder(ResidualSpaceBestFitExtremePointPermutationDecoder original, Cloner cloner)
38      : base(original, cloner) {
39    }
40    public ResidualSpaceBestFitExtremePointPermutationDecoder() : base() { }
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new ResidualSpaceBestFitExtremePointPermutationDecoder(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      Dictionary<Tuple<BinPacking3D,PackingPosition>, int> points = new Dictionary<Tuple<BinPacking3D,PackingPosition>,int>();
49      var bpg = new BinPacking3D(binShape);
50      bpg.ExtremePointBasedPacking(ref remainingIDs, items, stackingConstraints: useStackingConstraints);
51      result.Bins.Add(bpg);
52      foreach (int ID in remainingIDs) {
53        points = GetResidualSpaceAllPoints(result, items[ID]);
54        var sortedPoints = points.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
55        if (!ExtremePointBasedPacking(sortedPoints, ID, items, stackingConstraints: useStackingConstraints)) {
56          var bp = new BinPacking3D(binShape);
57          bp.ExtremePointBasedPacking(ID, items, stackingConstraints: useStackingConstraints);
58          result.Bins.Add(bp);
59        }
60      }
61      result.UpdateBinPackings();
62      return result;
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.