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 |
|
---|
33 | namespace HeuristicLab.Problems.BinPacking3D.Decoder {
|
---|
34 |
|
---|
35 | /// <summary>
|
---|
36 | /// This class creates a solution
|
---|
37 | /// </summary>
|
---|
38 | [Item("Extreme-point Permutation Decoder (3d) Base", "Base class for 3d decoders")]
|
---|
39 | [StorableClass]
|
---|
40 | public class ExtremePointPermutationDecoder : Item, IDecoder<Permutation>
|
---|
41 | //where TBinPacker : BinPacker, new ()
|
---|
42 | {
|
---|
43 |
|
---|
44 | [StorableConstructor]
|
---|
45 | protected ExtremePointPermutationDecoder(bool deserializing) : base(deserializing) { }
|
---|
46 | protected ExtremePointPermutationDecoder(ExtremePointPermutationDecoder original, Cloner cloner)
|
---|
47 | : base(original, cloner) {
|
---|
48 | }
|
---|
49 |
|
---|
50 | /// <summary>
|
---|
51 | /// Creates an extrem point based permutation decoder
|
---|
52 | /// </summary>
|
---|
53 | /// <param name="binPacker">Contains the packing algorithm for packing the items</param>
|
---|
54 | public ExtremePointPermutationDecoder(BinPacker binPacker) : base() {
|
---|
55 | _binPacker = binPacker;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
59 | return new ExtremePointPermutationDecoder(this, cloner);
|
---|
60 | }
|
---|
61 |
|
---|
62 | BinPacker _binPacker;
|
---|
63 |
|
---|
64 | /// <summary>
|
---|
65 | /// Creates a solution for displaying it on the HEAL gui
|
---|
66 | /// </summary>
|
---|
67 | /// <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>
|
---|
68 | /// <param name="binShape">Bin for storing the items</param>
|
---|
69 | /// <param name="items">A list of packing items which should be assigned to a bin</param>
|
---|
70 | /// <param name="useStackingConstraints"></param>
|
---|
71 | /// <returns></returns>
|
---|
72 | public Solution Decode(Permutation permutation, PackingShape binShape, IList<PackingItem> items, bool useStackingConstraints) {
|
---|
73 | Solution solution = new Solution(binShape, useExtremePoints: true, stackingConstraints: useStackingConstraints);
|
---|
74 | foreach (var packedBin in _binPacker.PackItems(permutation, binShape, items, useStackingConstraints)) {
|
---|
75 | solution.Bins.Add(packedBin);
|
---|
76 | }
|
---|
77 | return solution;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|