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 |
|
---|
22 | using HeuristicLab.Core;
|
---|
23 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
25 | using System;
|
---|
26 | using System.Collections.Generic;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Threading.Tasks;
|
---|
30 | using HeuristicLab.Common;
|
---|
31 | using HeuristicLab.Problems.BinPacking3D.Packer;
|
---|
32 | using HeuristicLab.Parameters;
|
---|
33 | using HeuristicLab.Data;
|
---|
34 |
|
---|
35 | namespace 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 | //_binPacker = cloner.Clone(original._binPacker);
|
---|
72 | }
|
---|
73 | public ExtremePointPermutationDecoder() {
|
---|
74 | Parameters.Add(fittingMethodParameter =
|
---|
75 | new ValueParameter<EnumValue<FittingMethod>>("Fitting Method",
|
---|
76 | "The fitting method that the decoder uses.",
|
---|
77 | new EnumValue<FittingMethod>(FittingMethod.FirstFit)));
|
---|
78 |
|
---|
79 | Parameters.Add(extremePointCreationMethodParameter =
|
---|
80 | new ValueParameter<EnumValue<ExtremePointCreationMethod>>("Extreme Point Generation Method",
|
---|
81 | "The Extreme point generation method that the decoder uses.",
|
---|
82 | new EnumValue<ExtremePointCreationMethod>(ExtremePointCreationMethod.PointProjection)));
|
---|
83 | }
|
---|
84 |
|
---|
85 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
86 | return new ExtremePointPermutationDecoder(this, cloner);
|
---|
87 | }
|
---|
88 |
|
---|
89 | /*[Storable]
|
---|
90 | BinPacker _binPacker;
|
---|
91 | */
|
---|
92 | /// <summary>
|
---|
93 | /// Creates a solution for displaying it on the HEAL gui
|
---|
94 | /// </summary>
|
---|
95 | /// <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>
|
---|
96 | /// <param name="binShape">Bin for storing the items</param>
|
---|
97 | /// <param name="items">A list of packing items which should be assigned to a bin</param>
|
---|
98 | /// <param name="useStackingConstraints"></param>
|
---|
99 | /// <returns></returns>
|
---|
100 | public Solution Decode(Permutation permutation, PackingShape binShape, IList<PackingItem> items,bool useStackingConstraints) {
|
---|
101 | var binPacker = BinPackerFactory.CreateBinPacker(FittingMethod);
|
---|
102 | Solution solution = new Solution(binShape, useExtremePoints: true, stackingConstraints: useStackingConstraints);
|
---|
103 | foreach (var packedBin in binPacker.PackItems(permutation, binShape, items, ExtremePointCreationMethod, useStackingConstraints)) {
|
---|
104 | solution.Bins.Add(packedBin);
|
---|
105 | }
|
---|
106 | return solution;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|