Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/old files/ISOContainerMultiComponentVectorDecoder3D.cs @ 14815

Last change on this file since 14815 was 14042, checked in by gkronber, 8 years ago

#1966: moved obsolete files into a separate folder

File size: 5.2 KB
RevLine 
[9495]1#region License Information
2/* HeuristicLab
[13032]3 * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[9495]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
[13032]22
[9495]23using System;
24using System.Collections.Generic;
25using System.Linq;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Core;
28using HeuristicLab.Problems.BinPacking.Dimensions;
29using HeuristicLab.Problems.BinPacking.PackingBin;
30using HeuristicLab.Problems.BinPacking.PackingItem;
31using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
32using HeuristicLab.Common;
33using HeuristicLab.Collections;
34using HeuristicLab.Problems.BinPacking.Interfaces;
35using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
36
37namespace HeuristicLab.Problems.BinPacking.Decoders {
[9563]38  [Item("ISO container decoder for the MultiComponentVector encoding.", "<Description missing...>")]
[9495]39  [StorableClass]
[9563]40  public class ISOContainerMultiComponentVectorDecoder3D : PackingSolutionDecoder<
[9495]41      ThreeDimensionalPacking,
42      CuboidPackingBin,
[9563]43      CuboidPackingItem>, I3DMCVDecoder {
[9495]44
45    public ISOContainerMultiComponentVectorDecoder3D ()
46      : base() {
47    }
48    [StorableConstructor]
49    protected ISOContainerMultiComponentVectorDecoder3D (bool deserializing) : base(deserializing) { }
50    protected ISOContainerMultiComponentVectorDecoder3D(ISOContainerMultiComponentVectorDecoder3D original, Cloner cloner)
51      : base(original, cloner) {
52    }
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new ISOContainerMultiComponentVectorDecoder3D(this, cloner);
55    }
56
[9563]57    public static PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Decode(MultiComponentVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
[9596]58      PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> resultPlan = new PackingPlan3D(binMeasures);
59      ObservableList<BinPacking3D> result = new ObservableList<BinPacking3D>();
[9495]60
[9596]61      var sequenceMatrix = solution.GenerateSequenceMatrix();
62      Dictionary<int, bool> rotated = solution.GenerateRotationArray();
[9495]63
[9596]64      //Fill bins according to grouping vector
65      List<int> remainingIDs = new List<int>();
66      foreach (var sequence in sequenceMatrix) {
67        remainingIDs = remainingIDs.Concat(sequence).ToList();
68        var bp = new BinPacking3D(binMeasures);
69        bp.ExtremePointBasedPacking(ref remainingIDs, itemMeasures, true, rotated);
70        if (remainingIDs.Count > 0) {
71          bp.DoubleDepth();
72          bp.ExtremePointBasedPacking(ref remainingIDs, itemMeasures, true, rotated);
[9495]73        }
[9596]74        result.Add(bp);
[9495]75      }
[9596]76      result.RemoveAll(x => x.ItemPositions.Count == 0);
77      result = new ObservableList<BinPacking3D>(result.OrderByDescending(bp => bp.PackingDensity));
[9495]78
[9596]79      //Try to put remaining items in existing bins
80      var temp = new List<int>(remainingIDs);
81      foreach (int id in temp) {
82        foreach (var bp in result) {
83          var position = bp.FindExtremePointForItem(itemMeasures[id], rotated[id], true);
84          if (remainingIDs.Count > 0) {
85            bp.DoubleDepth();
86            position = bp.FindExtremePointForItem(itemMeasures[id], rotated[id], true);
[9495]87          }
[9596]88          if (position != null) {
89            bp.PackItem(id, itemMeasures[id], position);
90            remainingIDs.Remove(id);
91          }
[9495]92        }
93      }
94
[9596]95      //Put still remaining items in new bins
96      while (remainingIDs.Count > 0) {
97        var bp = new BinPacking3D(binMeasures);
98        bp.ExtremePointBasedPacking(ref remainingIDs, itemMeasures, true, rotated);
99        if (remainingIDs.Count > 0) {
100          bp.DoubleDepth();
101          bp.ExtremePointBasedPacking(ref remainingIDs, itemMeasures, true, rotated);
[9563]102        }
[9596]103        result.Add(bp);
[9563]104      }
[9596]105      result.RemoveAll(x => x.ItemPositions.Count == 0);
106      resultPlan.BinPackings = new ObservableList<BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>>(result.OrderByDescending(bp => bp.PackingDensity));
107      return resultPlan;
[9495]108    }
109
[9563]110    public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IItem encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
[9495]111      var solution = encodedSolution as MultiComponentVectorEncoding;
112      if (solution == null) throw new InvalidOperationException("Encoding is not of type MultiComponentVector");
[9563]113      return Decode(solution, binMeasures, itemMeasures);
[9495]114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.