Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2817:

  • The items can be rotated and tilted now.
  • Added pruning of extreme points in packed bins.
  • Added new packer which packs items by positioning them on the point with the minimum of wasted space. He uses rotating and tilting of items.
  • Added classes for sorting given items.
File size: 4.4 KB
RevLine 
[15473]1#region License Information
2/* HeuristicLab
[15617]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[15473]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.Linq;
23using HeuristicLab.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Optimization;
28using HeuristicLab.Optimization.Operators;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Problems.BinPacking3D.Encoding;
31using HeuristicLab.Problems.BinPacking3D.Packer;
32using HeuristicLab.Problems.BinPacking3D.Evaluators;
33
34namespace HeuristicLab.Problems.BinPacking3D {
35  [Item("Bin Packing Problem (3D, permutation encoding) (BPP)", "Represents a three-dimensional bin-packing problem using only bins with identical measures and bins/items with rectangular shapes.")]
36  [StorableClass]
37  [Creatable(Category = CreatableAttribute.Categories.CombinatorialProblems, Priority = 320)]
38  public sealed class PermutationProblem : ProblemBase<Encodings.PermutationEncoding.PermutationEncoding, Permutation> {
39    [StorableConstructor]
40    private PermutationProblem(bool deserializing) : base(deserializing) { }
41
42    // cloning
43    private PermutationProblem(PermutationProblem original, Cloner cloner)
44      : base(original, cloner) {
45      RegisterEventHandlers();
46    }
47
48    public PermutationProblem()
49      : base() {
[15488]50      Decoder = new ExtremePointPermutationDecoder(); // default decoder
[15473]51
52      Encoding = new Encodings.PermutationEncoding.PermutationEncoding(EncodedSolutionName, Items.Count, PermutationTypes.Absolute);
53      AddOperators();
54      Parameterize();
55      RegisterEventHandlers();
56    }
57    public override IDeepCloneable Clone(Cloner cloner) {
58      return new PermutationProblem(this, cloner);
59    }
60
61    [StorableHook(HookType.AfterDeserialization)]
62    private void AfterDeserialization() {
63      RegisterEventHandlers();
64    }
65
66    protected override void OnEncodingChanged() {
67      base.OnEncodingChanged();
68      Parameterize();
69    }
70
71    private void AddOperators() {
72      Operators.Add(new TranslocationMoveEvaluator());
73      Operators.Add(new Swap2MoveEvaluator());
74
75      Operators.RemoveAll(x => x is SingleObjectiveMoveGenerator);
76      Operators.RemoveAll(x => x is SingleObjectiveMoveMaker);
77      Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator);
78      Operators.Add(new HammingSimilarityCalculator());
79      Operators.Add(new QualitySimilarityCalculator());
80      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
81
82      Encoding.ConfigureOperators(Operators.OfType<IOperator>());
83
84      foreach (var op in Operators.OfType<IOperator<Permutation>>()) {
85        op.BinShapeParameter.ActualName = BinShapeParameter.Name;
86        op.ItemsParameter.ActualName = ItemsParameter.Name;
87        op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name;
88        op.DecoderParameter.ActualName = DecoderParameter.Name;
89        op.UseStackingConstraintsParameter.ActualName = UseStackingConstraintsParameter.Name;
90      }
91    }
92
93    private void RegisterEventHandlers() {
94      // update encoding length when number of items were changed
95      ItemsParameter.ValueChanged += (sender, args) => Parameterize();
96    }
97
98    private void Parameterize() {
99      Encoding.Length = Items.Count;
100      foreach (var similarityCalculator in Operators.OfType<ISolutionSimilarityCalculator>()) {
101        similarityCalculator.SolutionVariableName = Encoding.SolutionCreator.PermutationParameter.ActualName;
102        similarityCalculator.QualityVariableName = Evaluator.QualityParameter.ActualName;
103      }
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.