Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Encoding/ExtremePointPermutationDecoder.cs @ 15838

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

#2817:

  • Fixed a bug at creating the extreme points with the point projection based method.
File size: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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 System;
26using System.Collections.Generic;
27using System.Linq;
28using System.Text;
29using System.Threading.Tasks;
30using HeuristicLab.Common;
31using HeuristicLab.Problems.BinPacking3D.Packer;
32using HeuristicLab.Parameters;
33using HeuristicLab.Data;
34
35namespace HeuristicLab.Problems.BinPacking3D.Encoding {
36
37  /// <summary>
38  /// This class creates a solution
39  /// </summary>
40  [Item("Extreme-point Permutation Decoder (3d) Base", "Base class for 3d decoders")]
41  [StorableClass]
42  public class ExtremePointPermutationDecoder : ParameterizedNamedItem, IDecoder<Permutation> {
43
44    [Storable]
45    private IValueParameter<EnumValue<FittingMethod>> fittingMethodParameter;
46    public IValueParameter<EnumValue<FittingMethod>> FittingMethodParameter {
47      get { return fittingMethodParameter; }
48    }
49
50    public FittingMethod FittingMethod {
51      get { return fittingMethodParameter.Value.Value; }
52      set { fittingMethodParameter.Value.Value = value; }
53    }
54
55    [Storable]
56    private readonly IValueParameter<EnumValue<ExtremePointCreationMethod>> extremePointCreationMethodParameter;
57    public IValueParameter<EnumValue<ExtremePointCreationMethod>> ExtremePointCreationMethodParameter {
58      get { return extremePointCreationMethodParameter; }
59    }
60
61    public ExtremePointCreationMethod ExtremePointCreationMethod {
62      get { return extremePointCreationMethodParameter.Value.Value; }
63      set { extremePointCreationMethodParameter.Value.Value = value; }
64    }
65
66    [StorableConstructor]
67    protected ExtremePointPermutationDecoder(bool deserializing) : base(deserializing) { }
68    protected ExtremePointPermutationDecoder(ExtremePointPermutationDecoder original, Cloner cloner)
69      : base(original, cloner) {
70      fittingMethodParameter = cloner.Clone(original.fittingMethodParameter);
71    }
72    public ExtremePointPermutationDecoder() {
73      Parameters.Add(fittingMethodParameter =
74            new ValueParameter<EnumValue<FittingMethod>>("Fitting Method",
75                                                         "The fitting method that the decoder uses.",
76                                                         new EnumValue<FittingMethod>(FittingMethod.FirstFit)));
77
78      Parameters.Add(extremePointCreationMethodParameter =
79            new ValueParameter<EnumValue<ExtremePointCreationMethod>>("Extreme Point Generation Method",
80                                                         "The Extreme point generation method that the decoder uses.",
81                                                         new EnumValue<ExtremePointCreationMethod>(ExtremePointCreationMethod.PointProjection)));
82    }
83
84    public override IDeepCloneable Clone(Cloner cloner) {
85      return new ExtremePointPermutationDecoder(this, cloner);
86    }
87   
88    /// <summary>
89    /// Creates a solution for displaying it on the HEAL gui
90    /// </summary>
91    /// <param name="permutation">Permutation of items sorted by a sorting method. The value of each permutation index references to the index of the items list</param>
92    /// <param name="binShape">Bin for storing the items</param>
93    /// <param name="items">A list of packing items which should be assigned to a bin</param>
94    /// <param name="useStackingConstraints"></param>
95    /// <returns></returns>
96    public Solution Decode(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) {
97      var binPacker = BinPackerFactory.CreateBinPacker(FittingMethod);
98      var pruningMethod = ExtremePointPruningMethod.None;
99      Solution solution = new Solution(binShape, useExtremePoints: true, stackingConstraints: useStackingConstraints);
100     
101      IList<BinPacking3D> packingList = binPacker.PackItems(permutation, binShape, items, ExtremePointCreationMethod, pruningMethod, useStackingConstraints);
102      foreach (var packedBin in packingList) {
103        solution.Bins.Add(packedBin);
104      }
105      return solution;
106    }   
107  }
108}
109
Note: See TracBrowser for help on using the repository browser.